August 19th, 2003, 12:41 PM
Join Date: Aug 2003
Time spent in forums: 26 m 20 sec
Reputation Power: 11
the reason why compiler complains abt main() is because by default it compiles the source to an executable...
to prevent this, u need to include the "-c" option. This will create a non-executable binary object file.
Using conventional naming, the object file compiled is of file extension ".o"
$ gcc -c mylib.c
this will create by default mylib.o object file.
mylib.c is just a set of library codes and does not contain any main().
To use this object file:
$gcc -o myHelloWorld.exe mylib.o myHelloWorld.c
thils will compile my calling program with the object file...
You can tar multiple object files into a single archived file (usu file extension of ".a") and use that archived file as if its a single object file when compiling with other calling programs...:
$gcc -o myCallingProg.exe myBigLibCollection.a myCallingProg.c
After all this, i must add that my personal preferences after encountering many linkage problems in the past while attempting to compile STLs and porting, I prefer to avoid unnecessary libraries. I would put all my codes in the header files and have all my calling programs to #include them when needed. (its the way sgi stl do it and i like it, just my own preference... )
Hope it helps a little...
Sorrie if it doesnt...
Last edited by siddy : August 19th, 2003 at 12:45 PM.