由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Linux and Shared object
相关主题
AIX, C-shared library, and g++问一个windows下编译openGL code的问题
关于C++ STL编译的疑问有人用DEV-C++吗?
关于 gcc 和 g++ 的问题问一个简单C++问题
在 windows下的C++开发平台是不是 Dev-C++?请推荐复习C++STL的经典书。Thx.
关于Makefile的一个问题请推荐最好的C++/Java/Python开源代码
一个奇怪的library linking问题(c++, boost.python, shared li (转载)How to compile with ddd?
c的memory layout和c++的memory layout有什么不同?C++ question
Intel C++ compiler 求教C++ interdependence question
相关话题的讨论汇总
话题: shared话题: fpic话题: library话题: gcc话题: soname
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
C++ interdependence question关于Makefile的一个问题
ZZ: 初学者学习C++的50条忠告一个奇怪的library linking问题(c++, boost.python, shared li (转载)
C++ class libraryc的memory layout和c++的memory layout有什么不同?
const_reverse_iterator和reverse_iterator有什么区别? (转载)Intel C++ compiler 求教
AIX, C-shared library, and g++问一个windows下编译openGL code的问题
关于C++ STL编译的疑问有人用DEV-C++吗?
关于 gcc 和 g++ 的问题问一个简单C++问题
在 windows下的C++开发平台是不是 Dev-C++?请推荐复习C++STL的经典书。Thx.
相关话题的讨论汇总
话题: shared话题: fpic话题: library话题: gcc话题: soname