在Visual Studio 2015中进行跨平台构建时链接到第三方库 [英] Linking against third-party libraries when doing cross-platform build in Visual Studio 2015

查看:220
本文介绍了在Visual Studio 2015中进行跨平台构建时链接到第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Visual Studio 2015 RC编译共享对象(.so).

I am trying to compile a Shared Object (.so) with Visual Studio 2015 RC.

我要链接到stdafx.h中的Opus编解码器库:

I am linking against the Opus Codec libs in my stdafx.h:

#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")

我收到链接器错误:

链接器命令失败,退出代码为1(使用-v查看 调用)SharedObject1 C:\ Users \ MyUser \ Documents \ Visual Studio 2015 \ Projects \ SharedObject1 \ SharedObject1 \ clang.exe 1

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"?

Can anybody tell me how to investigate what might have gone wrong there? Where would I state this "-v"?

在跨平台项目中使用.libs是不行的吗?我想知道为什么每个人都谈论.a文件,.so,却从来没有谈论.libs.

And is it not ok to use .libs in a cross-platform project? I was wondering why everybody talks about .a files, .so, but never about .libs.

如果有人愿意拥有一个小型示例项目,请在此处上传.看.

I have uploaded my small example project here if somebody would be willing to have a look.

推荐答案

首先,Opus Codec发行版随附Visual Studio项目,这些项目被配置为仅构建非跨平台的Windows库.您需要将这些项目替换为跨平台库项目.或更好的选择:只需下载预构建的 libopus.a ,例如来自此处.

First, the Opus Codec distribution comes with Visual Studio projects that are configured to build only Windows libraries, which are not cross-platform. You need to replace these projects with Cross Platform Library projects. Or better alternative: just download prebuilt libopus.a, e.g. from here.

第二,您不能在跨平台项目中使用#pragma comment(lib, ...).而是将库依赖项添加到项目属性中:将opus添加到配置属性->链接器->输入->库依赖项;还将路径添加到包含 libopus.a 的文件夹中,到配置属性->链接器->常规->其他库目录.

Second, you cannot use #pragma comment(lib, ...) in cross-platform projects. Instead, add library dependencies to the project properties: add opus to Configuration Properties -> Linker -> Input -> Library Dependencies; also add path to the folder containing libopus.a to Configuration Properties -> Linker -> General -> Additional Library Directories.

第三,您似乎正在尝试通过将clang.exe放置在项目的根目录中来使用该版本(您的链接器错误显示了此信息).这一定是非常错误的.相反,您需要使用Android NDK随附的Clang. (确保NDKROOT环境变量指向Android NDK安装的根目录.)

Third, it looks like you are trying to use some version of clang.exe by placing it in the root of your project (your linker error shows this). It must be very wrong. Instead, you need to use Clang that comes with Android NDK. (Make sure the NDKROOT environment variable points the root of Android NDK installation.)

这篇关于在Visual Studio 2015中进行跨平台构建时链接到第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆