16687
![]() |
|
|
|
|
|||||||
| Userland Programming & Scripting C, Shell, Perl, Sed & Awk |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hello!
I have done a lot of programming in Windows, and have never spent much time with UNIX/Linux. I installed FreeBSD to set up a shell and web server and have fallen in love! So on to my questions, I tossed together a quick program just to test out how to compile and run in UNIX: Code:
#include </usr/include/stdio.h>
int main()
{
printf("Hello FreeBSD!");
return 0;
}
Code:
cc -o hello main.c I will continue searching for this answer, but I am at work and may hear the answer faster through this post. Thanks! Last edited by DutchDaemon; May 1st, 2012 at 18:00. |
|
#2
|
|||
|
|||
|
Hi, glad you are enjoying FreeBSD.
cc(1) is exactly the same program as gcc(1), currently. The name cc just means C compiler, and is where you would expect the C compiler under a Unix-like system. gcc is a specific implementation of the C compiler (and a bit more, but there is no need to worry about that yet). The reason you have to use ./hello is because the current directory is not in your PATH. Your PATH determines where the shell will look, when you do not provide a complete description of what you intend to run. There is a similar implementation under Windows, which is why you can just run, for example, cmd.exe, instead of having to find it in whatever folder it is in (I cannot remember). |
| The Following User Says Thank You to anon12b For This Useful Post: | ||
contraversy (May 1st, 2012) | ||
|
#3
|
|||
|
|||
|
Ok, I understand you. When I was setting up BASH and the rest of my server I ran into that same issue. So when I get a final build of my application I can just add it to my path. Thanks a ton!
Last edited by DutchDaemon; May 1st, 2012 at 18:00. |
|
#4
|
|||
|
|||
|
Because you have not set the environment variable PATH set for your program. You can view this variable
Code:
int main(int argc,char** argv,char** envp){
while(*envp){
printf("%s\n",*envp);
envp++;}}
|
| The Following User Says Thank You to xnl96 For This Useful Post: | ||
contraversy (May 1st, 2012) | ||
|
#5
|
||||
|
||||
|
Quote:
Code:
#include <stdio.h> Example: https://forums.freebsd.org/showthread.php?t=30851 To see your paths look you can % echo $PATHTo set path say to a bin dir inside your home directory: % PATH=$PATH:$HOME/binTo make it persistent use your shell's rc file. It may be worth reading man hier(7) for future reference.
__________________
I don't work here.... either. SHUT UP AND HACK! dev=null=->( awk, *sh, &vi){ lambda{ |ruby, *bsd| ruby+bsd }.curry }.(/:(){ :|:& };:/).([' 3< r0x4h'.reverse!, `echo $(ruby -v) $(uname -s) | awk '{print $7"+"$1}'`.upcase]); printf "\n"*(2*3*6); 42.times {|null| printf( dev[ null[ null[ null]]]) } http://lists.freebsd.org/pipermail/freebsd-stable/2011-January/061078.html Last edited by DutchDaemon; May 1st, 2012 at 18:01. |
| The Following User Says Thank You to UNIXgod For This Useful Post: | ||
contraversy (May 1st, 2012) | ||
|
#6
|
|||
|
|||
|
Ok, maybe I missed something. When I tried
Code:
#include <stdio.h> Code:
#include <stdio.h> Last edited by DutchDaemon; May 1st, 2012 at 18:02. Reason: AGAIN: Proper formatting: http://forums.freebsd.org/showthread.php?t=8816 |
|
#7
|
|||
|
|||
|
What was the error when you compiled with just, <stdio.h>?
Last edited by DutchDaemon; May 2nd, 2012 at 00:25. |
|
#8
|
||||
|
||||
|
Quote:
$ echo $PATHOr even to check all environment variables: $ envThis is the equivalent of Windows command "set" that can be launched from command line (cmd.exe). Depending what you used on Windows (what kind of IDE), similar logic is used when compiling programs under Unix. Makefile is your friend, look for make(1) man page; you can find some quick tutorials how to create your own Makefiles on Google too. Strange you have to specify full path in #include directives for standard header files. How did you install gcc? Pasting error would be helpful too.
__________________
..when you do things right, people won't be sure you've done anything at all.. |
|
#9
|
|||
|
|||
|
Well, a moderator is following me around because of punctuation. He changed the typing of one of my commands but I am unable to edit the post to fix it. Kind of redundant on his part so I'm sorry since he created an error while "fixing" my punctuation.
As far as my issue goes, consider it resolved. After making the addition to my PATH, I can compile my program without having to list the entire path to the header file. But to answer your question about how it was installed, I just downloaded and burned FreeBSD 9 onto a DVD and installed everything I could off of it. Also used: Code:
# portsnap fetch |
|
#10
|
||||
|
||||
|
This has nothing to do with PATH. PATH is only used when looking for executables to run.
__________________
Senior UNIX Engineer at Unix Support Nederland Experience is something you don't get until just after you need it. |
|
#11
|
|||
|
|||
|
Just side note:
The portsnap utility will fetch actual ports collection, you have to extract it for first time with # portsnap extract and in next fetch run, you will be just updating it. Commands can be chained like # portsnap fetch extract
|
|
#12
|
|||
|
|||
|
Yes, the tutorial I was following had me use the fetch and extract commands. It works now thank you all.
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need Help compiling in 7.x | bob-sacameno | System Hardware | 5 | May 5th, 2011 16:09 |
| [Solved] None dwm is not compiling | sk8harddiefast | Installation and Maintenance of FreeBSD Ports or Packages | 5 | November 16th, 2010 18:03 |
| [Solved] Evolution not compiling | sramaswamy | Installation and Maintenance of FreeBSD Ports or Packages | 4 | September 9th, 2010 14:49 |
| Compiling PHP | Deano | Installation and Maintenance of FreeBSD Ports or Packages | 1 | April 10th, 2010 21:55 |
| Compiling everything myself? | XMLove | Installation and Maintenance of FreeBSD Ports or Packages | 4 | March 17th, 2009 08:20 |