Re: How to link in static objects from a static library?
- From: Paul Pluzhnikov <ppluzhnikov-nsp@xxxxxxxxxxx>
- Date: Fri, 29 Dec 2006 20:21:43 -0800
golfmat@xxxxxxxxx writes:
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.
That is *exactly* how it's supposed to work. More here:
http://webpages.charter.net/ppluzhnikov/linker.html
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?
Sure:
g++ ... -Wl,--whole-archive -lMyArchive -Wl,--no-whole-archive ...
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
Your link line is all screwed up:
- you should never explicitly link libstdc++ -- g++ will add it
for you (and in correct place).
- the '--start-group' and '--end-group' should be prefixed with
'-Wl,' so they are correctly passed to the linker.
- you should never link with '-lpthread' either; use '-pthread'
at compile *and* link time instead.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
.
- References:
- How to link in static objects from a static library?
- From: golfmat
- How to link in static objects from a static library?
- Prev by Date: How to link in static objects from a static library?
- Next by Date: Re: Dynamic library loader search path
- Previous by thread: How to link in static objects from a static library?
- Index(es):