Page 1 of 1
Compiling normal C programs in Linux
Posted: Tue Oct 25, 2005 5:08 am
by OSMAN
Helloween!
What is the easiest way to compile a normal C-program linked with linux-libraries?
If I look at the gcc manual I see thousands of unnecessary options.
So, would you tell me a little about some necessary options like
-c, -o, -f and so on which do you think might help?
To this moment I've needed to specify the library paths in my makefile; wouldn't that have to be automatic feature of Gcc when I use #includes in C?
Btw, can gcc output ms-exe or com, and if can, how?
Re:Compiling normal C programs in Linux
Posted: Tue Oct 25, 2005 5:40 am
by AR
MinGW and Cygwin produce Windows executables.
Building standard apps in Linux is extremely simple (you should have easily been able to find a tutorial on this):
Standard libraries (libgcc, libc, libstdc++) should be automatically linked but you will need to specify others manually using the library option (ie. -l<Name>)
A more complex build involving multiple C files is:
Code: Select all
gcc -c mysrc1.c -o mysrc1.o
gcc -c mysrc2.c -o mysrc2.o
gcc mysrc1.o mysrc2.o -o myapp
Re:Compiling normal C programs in Linux
Posted: Tue Oct 25, 2005 5:52 am
by Candy
OSMAN wrote:
What is the easiest way to compile a normal C-program linked with linux-libraries?
If I look at the gcc manual I see thousands of unnecessary options.
There are no options that are unnecessary. You might not need them, but that doesn't mean that I don't need them, or that you won't need them in the future.
Btw, can gcc output ms-exe or com, and if can, how?
By enabling the linker to output that kind of file. You can enable that in its configuration. LD is contained in binutils.
Re:Compiling normal C programs in Linux
Posted: Thu Oct 27, 2005 1:36 pm
by AGI1122
If there is a makefile included then it's even easier. Usually just type "make" and it compiles for you.
There is also some programs that include a configuration generator that creates the stuff that the makefile uses.
For instance to compile sarien for linux I type this:
Then this:
Of course you have to have both gcc and make installed for this.
Cross platform takes a bit more work... I had to install some mingw32 stuff and I usually have to modify the makefile to make it use mingw32, but then I can compile windows executables from linux.
Re:Compiling normal C programs in Linux
Posted: Thu Oct 27, 2005 5:33 pm
by AR
"configure" is a shell script created by "autoconf" from a configuration file that you still have to write to begin with (using "m4").