如何在 C++ 的 .so 文件中包含库

How do I include a library in an .so file in C++

本文关键字:文件 包含库 so C++      更新时间:2023-10-16

我正在尝试编译一个依赖于FTDI库的.so文件。我不确定如何包含库以使其正确编译。(以下是我最好的猜测(。这是可能的还是有其他方法可以做到的?

shared: pldevice pldeviceenttecpro pluniverse
$(CC) -shared  -Wl,-soname,libplanklight.so -o libplanklight.so
-L/usr/local/lib -lftd2xx 
pldevice.o pldeviceenttecpro.o pluniverse.o

编辑:这是输出:

g++ -fPIC -c pldevice.cpp
g++ -fPIC -c pldeviceenttecpro.cpp
g++ -fPIC -c pluniverse.cpp
g++ -shared  -Wl,-soname,libplanklight.so -o libplanklight.so
-L/usr/local/lib -lftd2xx 
pldevice.o pldeviceenttecpro.o pluniverse.o
/usr/bin/x86_64-linux-gnu-ld: cannot open output file   libplanklight.so-L/usr/local/lib: No such file or directory
collect2: error: ld returned 1 exit status
Makefile:5: recipe for target 'shared' failed
make: *** [shared] Error 1

你缺少一个空格。

$(CC) -shared  -Wl,-soname,libplanklight.so -o libplanklight.so 
^^
Add a space here

\ 只是使命令在下一行继续,所以当你有

-o libplanklight.so
-L/usr/local/lib 

它将与-o libplanklight.so-L/usr/local/lib相同

但你想要-o libplanklight.so -L/usr/local/lib