我正在尝试使用 Visual Studio 2015 RC 编译共享对象 (.so)。
我正在链接我的 stdafx.h 中的 Opus 编解码器库:
#pragma comment(lib, "..\\..\\opus-1.1-beta\\win32\\VS2010\\Win32\\Debug\\celt.lib")
#pragma comment(lib, "..\\..\\opus-1.1-beta\\win32\\VS2010\\Win32\\Debug\\opus.lib")
#pragma comment(lib, "..\\..\\opus-1.1-beta\\win32\\VS2010\\Win32\\Debug\\silk_common.lib")
#pragma comment(lib, "..\\..\\opus-1.1-beta\\win32\\VS2010\\Win32\\Debug\\silk_fixed.lib")
#pragma comment(lib, "..\\..\\opus-1.1-beta\\win32\\VS2010\\Win32\\Debug\\silk_float.lib")
我收到链接器错误:
linker command failed with exit code 1 (use -v to see invocation) SharedObject1 C:\Users\MyUser\Documents\Visual Studio 2015\Projects\SharedObject1\SharedObject1\clang.exe 1
谁能告诉我如何调查那里可能出了什么问题? 我应该在哪里声明这个“-v”?
在跨平台项目中使用 .libs 不是可以的吗?我想知道为什么每个人都谈论 .a 文件、.so,但从来不谈论 .libs。
编辑:我已经上传了我的小示例项目 here如果有人愿意看一看。
最佳答案
首先,Opus Codec 发行版附带了 Visual Studio 项目,这些项目配置为仅构建非跨平台的 Windows 库。您需要将这些项目替换为 Cross Platform Library 项目。或者更好的选择:只需下载预构建的libopus.a,例如来自 here .
其次,您不能在跨平台项目中使用#pragma comment(lib, ...)
。相反,将库依赖项添加到项目属性:将 opus
添加到 Configuration Properties -> Linker -> Input -> Library Dependencies;还将包含 libopus.a 的文件夹的路径添加到配置属性 -> 链接器 -> 常规 -> 附加库目录。
第三,您似乎正试图通过将某些版本的 clang.exe 放在项目的根目录中来使用它(您的链接器错误显示了这一点)。一定是大错特错。相反,您需要使用 Android NDK 附带的 Clang。 (确保 NDKROOT 环境变量指向 Android NDK 安装的根目录。)
关于c++ - 在 Visual Studio 2015 中进行跨平台构建时链接第三方库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30568975/