c++ - How to make a static/dynamic library that uses a library -
i making c++ library. in library, using functions in static library (e.g. ref.a).
i want generate 1 library file, either mylib.a or mylib.so, programme using library not need link static library (ref.a). got ideas others how link static lib dynamic lib, "--whole-archive", not clear how it.
to mylib.a, ar -rc mylib.a mylib.o ref.a (may not standard way). shared lib, e.g. mylib.so?
to mylib.a, ar -rc mylib.a mylib.o ref.a
no, wouldn't work. have "expand" ref.a
before include mylib.a:
mkdir tmp.$$ && cd tmp.$$ && ar x ../ref.a && cd .. && ar rc mylib.a mylib.o tmp.$$/*.o && rm -rf tmp.$$
what shared lib
that's simpler:
gcc -shared -o mylib.so mylib.o -wl,--whole-archive ref.a -wl,--no-whole-archive
(it's very of import have trailing -wl,--no-whole-archive
, or may nasty link errors scheme libraries compiler driver adds end of link.)
c++ shared-libraries
No comments:
Post a Comment