Linking a shared library using gcc

匆匆过客 提交于 2021-02-05 20:43:38

问题


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.

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

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

gcc -shared myfile.so

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

gcc -lmyfile.so

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


回答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.



来源:https://stackoverflow.com/questions/726014/linking-a-shared-library-using-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!