[英]Cannot import shared library with g++
i made a shared library, linked it to a main program, but this main program cannot see any of the shared library methods, nor import it's headers. 我制作了一个共享库,将其链接到主程序,但是该主程序无法看到任何共享库方法,也无法导入其标头。 This is what i did:
这就是我所做的:
g++ -c -fPIC -o objname.o objname.cpp -I"HeadersFolder"
g++ -shared -o libmylib.so obj1.o obj2.o etc.. etc..
g++ main.cpp -L. -lmylib
Now in this main i imported one of the lib headers, something like: 现在在这个主目录中,我导入了一个lib标头之一,如下所示:
#include <Header.hpp>
And g++ tells me no such file or directory. 而且g ++告诉我没有这样的文件或目录。
"Now in this main i imported one of the lib headers, something like: ..."
“现在在这个主目录中,我导入了一个lib头文件,类似于:...”
You also need to add the -I
option to compile main.cpp
in this case: 在这种情况下,还需要添加
-I
选项来编译main.cpp
:
g++ main.cpp -I"HeadersFolder" -L. -lmylib
Also you should use 你也应该用
#include "Header.hpp" // Note the quotes "
the angle brackets ( <>
) are for including system headers (that could possibly collide with your own when the preprocessor evaluates them). 尖括号(
<>
)用于包含系统标题(在预处理程序对其进行评估时,它们可能会与您自己的标题冲突)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.