可以在Ubuntu中进行编译,但不能在Mac OS X中进行编译
Can compile in Ubuntu but not in Mac OS X
i在Ubuntu 12.04上构建了动态库(.so file
)。我们称之为test.so
。我有一个test.cpp
文件,该文件调用一些库功能。我首先将test.cpp
编译到test.o
中:
g++ test.cpp -o -c test.o
成功。然后,我将test.o
编译到test.so
中:
g++ -shared test.o -o test.so
也成功了。
我做了类似的事情,但是在Mac OS X上。
我首先获得了test.o
,
g++ test.cpp -o -c test.o
然后
g++ -dynamiclib test.o -o test.dylib
这失败了,因为我没有提供test.cpp
中使用的库。我修改了它:
g++ -dynamiclib test.o -o test.dylib -L/path/to/libraries -lLibraryName
然后起作用。
请注意,对于第一种情况,我没有为库和test.cpp
中使用的特定库提供这样的途径。有人知道为什么我在第一种情况下不需要,而在第二种情况下需要?
带有默认选项的链接器在Linux和OSX上的行为不相同。要获得OSX链接以更像您对Linux的期望,请使用以下链接标志。
-Wl,-undefined,dynamic_lookup
相关文章:
- 如何在 Mac 上正确编译C++,当它在 Linux 上编译没有问题时?
- 编译在我的 Mac 上工作,但在集群 (Linux) 上不起作用
- 在 Mac 上使用 VSCode 编译C++
- 使用 Mac 终端编译器编译 c++14 代码
- 如何编译:Mac上的Synergy(2017年的新工具链)
- 如何使用 clang 和 distcc 在不同架构(例如 Mac/Linux)的从属服务器上编译
- 针对 ubuntu 和 Mac 编译的差异
- 在 OpenGL 中在 Mac 上编译着色器时出现"version not supported"错误
- Cmake Mac OSX库链接问题:在Linux上进行编译,但在Mac上进行了编译
- 在 mac 上使用 MPFR 包编译错误
- 拥有LLVM IR库如何从Ubuntu将其交叉编译到iOS,Android,Windows和Mac?
- 在 Mac 上C++编译代码时处理“dyld:惰性符号绑定失败:找不到符号”错误
- 当Mac Mojave中的C 编译时,C编译器识别是未知的
- 从Mac上的终端编译时C 错误
- 在Mac OS X Mojave上使用AppleClang编译和链接OpenMP
- 在Mac OS上编译Dlib
- 使用 c++17 mac 编译
- 如何在Mac终端中编译C ++程序
- 为什么我可以编译为 C 而不是在 Mac OS X 上使用 Cython C++
- OpenCV3.2 编译错误 MAC OS X