使用gcc链接共享库

时间:2021-07-04 06:21:54

I have a shared library (*.so) created using Real View Compiler Tools (RVCT 3.2) on windows target. Then I try to link this *.so file with my application using gcc on linux system.

我在Windows目标上使用Real View编译器工具(RVCT 3.2)创建了一个共享库(* .so)。然后我尝试使用linux系统上的gcc将此* .so文件与我的应用程序链接。

What is the gcc option to link this shared library with my application linux?

将此共享库与我的应用程序li​​nux链接的gcc选项是什么?

My question is, is the -shared option, which is used as

我的问题是,-shared选项,用作

gcc -shared myfile.so

..., used to create the SO file or to link the SO file? I believe it creates something like:

...,用于创建SO文件或链接SO文件?我相信它创造了类似的东西:

gcc -lmyfile.so

Is this enough? Or is there any other switch to tell the linker that it's a dynamic library (shared object)?

这够了吗?或者是否有任何其他开关告诉链接器它是一个动态库(共享对象)?

2 个解决方案

#1


What worked for me was:

对我有用的是:

gcc -L. -l:myfile.so

#2


gcc -lmyfile should be enough (provided that your library is named libmyfile.so). The linker searches for shared objects when possible and AFAIK prefers them.

gcc -lmyfile应该足够了(假设您的库名为libmyfile.so)。链接器尽可能搜索共享对象,AFAIK更喜欢它们。

#1


What worked for me was:

对我有用的是:

gcc -L. -l:myfile.so

#2


gcc -lmyfile should be enough (provided that your library is named libmyfile.so). The linker searches for shared objects when possible and AFAIK prefers them.

gcc -lmyfile应该足够了(假设您的库名为libmyfile.so)。链接器尽可能搜索共享对象,AFAIK更喜欢它们。