Linking against third-party libraries when doing cross-platform build in Visual Studio 2015

若如初见. 提交于 2020-01-17 01:26:08

问题


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

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

I am getting the linker error:

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

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

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.

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


回答1:


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.

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.

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.)




回答2:


Using clang for windows is fairly new, so most of the time when people are talking about clang, they use it on Unix, Linux or BSD type systems which uses .a and .so files instead of .lib and .dll files.

In the example you uploaded you use different toolsets for the library and your project:

  • The opus library was build using the vs2015 toolset (v140)
  • Your project MySharedObject was build using clang (Clang_3_4)

Clang is actually able to use vs2015 libs, when using the Visual C++ linker. However, your project MySharedObject seems to use the Android NDK r10d toolchain.

My best guess would be to change one of the projects to match the toolchain/toolset of the other.



来源:https://stackoverflow.com/questions/30568975/linking-against-third-party-libraries-when-doing-cross-platform-build-in-visual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!