c++ - 如何在 C++ 中的 .so 文件中包含一个库

标签 c++

我正在尝试编译一个依赖于 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

关于c++ - 如何在 C++ 中的 .so 文件中包含一个库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52550999/

相关文章:

c++ - 聚合类的删除顺序是什么?

c++ - 命令行有效,Makefile 中的相同命令无效

c++ - 不明白为什么这个 std::cout 打印这个

c# - 如何在C#和java中实现这种可插拔机制?

c++ - C++ 标准库函数和类是否包含在每个 C++ 实现中?

c++ - 使用 Boost.Python 设置包装类的元类

c++ - 用于稀疏数据查找的高效数据结构

c++ - 使用 PdhAddEnglishCounter 时出错

c++ - std::function 的仅 move 版本

c++ - 函数之间的数组指针丢失值(用 swig 编译以在 python3 中使用)