How to link in static objects from a static library?
- From: golfmat@xxxxxxxxx
- Date: 29 Dec 2006 16:31:27 -0800
Hi,
I am creating a static library (using "ar -cq ...") from a bunch of .o
files that all contain static "registrar" objects in certain classes.
In particular, I have a templated Registrar class, and each of the
classes being archived has a static member of type
Registrar<class_name> that is supposed to "register" a constructor
object for that class. When I explicitly list for the linker all of the
..o files that I am archiving, these Registrar objects are all
automatically linked into the executable such that they are all
constructed before main is called when I run the program. However, if I
instead try to link against an archive/static library of these very
same .o files, these Registrar objects are NOT being linked into the
executable.
I am wondering if there is a flag or something that I need to use in
order to force the linker to link in all static objects from the static
library in question? Or is this not possible to do? Any help would be
greatly appreciated. Thanks!
Matt
Here are trimmed down versions of the commands I am running (all of
these commands run w/o errors, save the static object issue mentioned
above):
Archive command:
ar -cq libs/libMyArchive.a
obj/rel/Uberserver/Credit/DO/TestFramework/DOThroughputTest.o
obj/rel/Uberserver/Credit/DO/TestFramework/DOCircularityTest.o
obj/rel/Uberserver/Credit/DO/TestFramework/DOLatencyTest.o
obj/rel/Uberserver/Credit/DO/TestFramework/DOIONodeFiller.o [more .o
files]
Link command that explicitly lists .o files (and WORKS):
g++ -g -L/creditdev/packages/pgsql/lib
-L/creditdev/packages/emgtools/lib-g++-3.4.3 -rdynamic
obj/rel/Base/StringUtilities.o obj/rel/Base/DebugUtils.o
obj/rel/Base/ConsoleUtilities.o obj/rel/Base/Time.o
obj/rel/Uberserver/Credit/DO/TestFramework/DOThroughputTest.o
obj/rel/Uberserver/Credit/DO/TestFramework/DOCircularityTest.o
obj/rel/Uberserver/Credit/DO/TestFramework/DOLatencyTest.o
obj/rel/Uberserver/Credit/DO/TestFramework/DOIONodeFiller.o [more .o
files] --start-group /creditdev/shared_libraries/libstdc++.so.6
/usr/local/ssl/lib/libcrypto.a -lEmgToolsSystemUtils -ltds -lpthread
-lncurses -ldl -lpq --end-group -o rel/slave
Link command that links against .a file (and does NOT work):
g++ -g -L/creditdev/packages/pgsql/lib
-L/creditdev/packages/emgtools/lib-g++-3.4.3 -rdynamic
obj/rel/Base/StringUtilities.o obj/rel/Base/DebugUtils.o
obj/rel/Base/ConsoleUtilities.o obj/rel/Base/Time.o [more .o files]
--start-group libs/libMyArchive.a
/creditdev/shared_libraries/libstdc++.so.6
/usr/local/ssl/lib/libcrypto.a -lEmgToolsSystemUtils -ltds -lpthread
-lncurses -ldl -lpq --end-group -o rel/slave
.
- Follow-Ups:
- Re: How to link in static objects from a static library?
- From: Paul Pluzhnikov
- Re: How to link in static objects from a static library?
- Prev by Date: Re: Dynamic library loader search path
- Next by Date: Re: How to link in static objects from a static library?
- Previous by thread: Dynamic library loader search path
- Next by thread: Re: How to link in static objects from a static library?
- Index(es):
Relevant Pages
|