Linking fails with b.o:b.cpp:(.text$_ZN4TestC1Ev[Test::Test()]+0x8): undefined reference to `vtable for Test' if object file is stored in an archive but succeeds if not. Reproducible with this testcase: ### a.h ### class Test { public: virtual void do_something(); }; ### a.cpp ### #include "a.h" void Test::do_something() { } ### b.cpp ### #include "a.h" int main( int argc, char** argv ) { Test test; return 0; } ### build object files "a.o" "b.o" and put "a.o" in archive "a.a" g++ -c -o a.o a.cpp && g++.exe -c -o b.o b.cpp && ar -q a.a a.o ### linking with object files succeeds g++ -o c a.o b.o ### linking with archive file fails g++ -o c a.a b.o nm shows for the archive a.a and for the object a.o the same symbols. So it should succeed.
I get the same results with the latest mingw tools and on a debian box. Debian: GNU ld version 2.16.91 20060118 Debian GNU/Linux gcc version 4.0.3 20060212 (prerelease) (Debian 4.0.2-9) host, target, build: i486-linux-gnu
See ld info, node "Options" for info on when ld extracts objects from archives.
You are aware of the fact that I didn't use the -l option? From the documentation you pointed to I would expect that archives specified as input files without -l are either handled like objects or rejected as invalid input.
It doesn't make any difference whether an archive is specified as -lfoo or libfoo.a on the command line. You can force inclusion of the archive using --whole-archive.