Static linking help please...!

Lokesh Setia lokeshs@sh.bel.alcatel.be
Tue Nov 9 09:26:00 GMT 1999


>>>>> "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.


More information about the Gcc-help mailing list