This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: g++ linking problem with multiple libraries on solaris 2.7
- To: qlong at mindspring dot com (Qiegang Long)
- Subject: Re: g++ linking problem with multiple libraries on solaris 2.7
- From: Joe Buck <jbuck at racerx dot synopsys dot com>
- Date: Sun, 16 Jul 2000 10:35:02 -0700 (PDT)
- Cc: gcc at gcc dot gnu dot org
> On Solaris 2.7 with gcc-2.9.5, I am having a strange problem with g++.
No, it is an issue with how linkers work on Unix and Unix-like systems.
> I have over 100 source files for a library. If I compiled all the
> sources file and generate one big static library with "ar" command,
> my test program can be successfully linked to the library. However, if
> I organize those files into two sets, then use "ar" to generate
> two static libraries, my test program cannot be linked successful with
> the two new libraries. The error is some symbols in one
> library cannot be resolved, although those symbols are defined in the
> other library.
That's because the linker does only one pass.
>
> For example, I generated libex1.a and libex2.a, to link test program
> mytest,
>
> $ g++ -o mytest.o libex1.a libex2.a -L/usr/local/lib -lstdc++
>
> the error is some symbols in libex2.a cannot be resolved, although those
> symbols are defined in libex1.a.
Don't organize your libraries that way. The linker will search libex1.a
only once, to resolve undefined symbols. The behavior you're seeing is
standard.
The command line
$ g++ -o mytest.o libex1.a libex2.a libex1.a -L/usr/local/lib -lstdc++
will work, but it's best to organize things so that the dependencies
don't require multiple searches.
> Is this a known problem?
Many beginners run into it, yes.
Also, please don't send HTML mail to the gcc list.