ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ok, I'm starting to learn C, and I already know a bunch of java and php so its not the language that is confusing me as much as the compiling. I have GCC installed, but I have no idea how to use it. I am also unsure of how to save my files written in C. And no, I have not found any good tutorials written on this. So how would I write a simple hello world program? How do I save it (what extention do I use)? How do I compile it in GCC?
Well, assuming you're not using any libraries that need to be linked in, the tags
-o <outfile>
-Wall (all warnings)
-D_GNU_SOURCE (helpful for certain functions, but decreases portability)
are fairly standard. Syntax is the same as most unix programs:
Code:
gcc [FLAGS] infile
If you don't have the -o, it will make the file a.out, which is handy if you don't feel like typing a lot of stuff while you're in debugging phases.
When you get to libraries with special stuff, they'll tell you in the man pages. For example, ncurses requires the -lncurses flag, and GMP requires -lgmp.
Ok, thanks for the help, I got it working. However, I found out that the problem was actually with my Hello World file. For Java, I use the Green Tea Press tutorial to learn, and I found it extremely good. So for C, I decided to learn from the same tutorial converted to C ( http://www.ibiblio.org/obp/thinkCS/cpp/english/ , its C++, but I would expect the print statements to be the same). The hello world file they used was:
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
How can a language have two completely different print statements?
Not a single language, C and C++ are different languages with differing ways of printing things.
The first version is C++ only, and the second one is regular C.
You can compile almost every C-file with a C++ compiler. But not the other way around: compiling C++ code with a C compiler. This is what you have tried.
Pu simply, C++ is like C with extensions. A C-compiler does not recognise these extensions.
Originally posted by uphu
Ok, thanks, I was unaware of this. I thought GCC was a C++ compiler, but I guessed wrong.
could one of you point me in the direction of g++'s main page? Google ignores +'s... :\
To make things confusing () the software-package/product "GCC" contains compilers for C, C++ and other languages like fortran.
Both the C-compiler "gcc" and the C++-compiler "g++" are part of the "GCC" software package (GCC = GNU Compiler Collection). Its web-site is at http://gcc.gnu.org/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.