G*****9 发帖数: 3225 | 1 Beg for help.
I want to make some .so files written in C++ (with STL). How to build it and
link it correctly? Any quick solutions? Thank you. | r*******n 发帖数: 3020 | 2 3.4. Creating a Shared Library
Creating a shared library is easy. First, create the object files that will
go into the shared library using the gcc -fPIC or -fpic flag. The -fPIC and
-fpic options enable ``position independent code'' generation, a requirement
for shared libraries; see below for the differences. You pass the soname
using the -Wl gcc option. The -Wl option passes options along to the linker
(in this case the -soname linker option) - the commas after -Wl are not a
typo, and you must not include unescaped whitespace in the option. Then
create the shared library using this format:
gcc -shared -Wl,-soname,your_soname \
-o library_name file_list library_list
Here's an example, which creates two object files (a.o and b.o) and then
creates a shared library that contains both of them. Note that this
compilation includes debugging information (-g) and will generate warnings (
-Wall), which aren't required for shared libraries but are recommended. The
compilation generates object files (using -c), and includes the required -
fPIC option:
gcc -fPIC -g -c -Wall a.c
gcc -fPIC -g -c -Wall b.c
gcc -shared -Wl,-soname,libmystuff.so.1 \
-o libmystuff.so.1.0.1 a.o b.o -lc
and
【在 G*****9 的大作中提到】 : Beg for help. : I want to make some .so files written in C++ (with STL). How to build it and : link it correctly? Any quick solutions? Thank you.
| G*****9 发帖数: 3225 | 3 Thanks. But it does not work for me. For my case, since STL objects are used
in the library, gcc itself does not apply. I have to use g++.
will
and
requirement
linker
【在 r*******n 的大作中提到】 : 3.4. Creating a Shared Library : Creating a shared library is easy. First, create the object files that will : go into the shared library using the gcc -fPIC or -fpic flag. The -fPIC and : -fpic options enable ``position independent code'' generation, a requirement : for shared libraries; see below for the differences. You pass the soname : using the -Wl gcc option. The -Wl option passes options along to the linker : (in this case the -soname linker option) - the commas after -Wl are not a : typo, and you must not include unescaped whitespace in the option. Then : create the shared library using this format: : gcc -shared -Wl,-soname,your_soname \
| t****t 发帖数: 6806 | 4 just use g++ to link, it's the same.
used
【在 G*****9 的大作中提到】 : Thanks. But it does not work for me. For my case, since STL objects are used : in the library, gcc itself does not apply. I have to use g++. : : will : and : requirement : linker
|
|