This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Static linking help please...!
- To: help-gcc at gnu dot org
- Subject: Re: Static linking help please...!
- From: Lokesh Setia <lokeshs at sh dot bel dot alcatel dot be>
- Date: 09 Nov 1999 18:08:10 +0100
- Newsgroups: gnu.gcc.help
- Organization: Alcatel
- References: <807nup$bgg$0@dosa.alt.net>
- Xref: wodc7nx0 gnu.gcc.help:1742
>>>>> "Tom" == Tom Gilbert <tom@alteredworlds.com> writes:
<snipped>
Tom> DYNAMIC LIBRARY (this works): Compiler options used to build
Tom> shared version - for object files: Compile: g++ -c -fPIC
Tom> -Iwhatever somthing.cpp -o something.obj
Tom> link: g++ -shared -fPIC list_of_.obj -o something.so
Tom> So this works without any problems.
Tom> STATIC LIBRARY: object files- g++ -c -Iwhatever somthing.cpp
Tom> -o something.obj
Tom> link: FIRST TRY- g++ list_of_.obj -o something.a this is
Tom> obviously trying to produce an executable, as I get the
Tom> following error message - /usr/lib/crt1.o (.text+0x18):
Tom> undefined reference to 'main'
Tom> SECOND TRY- g++ -static list_of_.obj -o something.a
Tom> this one fails as follows- /usr/i386-linux/bin/ld: cannot
Tom> open -lstdc++: No such file or directory
For creating libraries for static linking, you need to use "ar" to
archive the files in a ".a" file. An ar archived file is just a
simple collection of object files, there's no information needed to
resolve so you don't need gcc/ld to create the library. The syntax for
"ar" is somewhat similar to "tar". You need something like:
ar rc something.a list_of_.obj
then link your program with -lsomething
Regards,
Lokesh.