0

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.

dened
  • 4,253
  • 18
  • 34
tmighty
  • 10,734
  • 21
  • 104
  • 218
  • Did you locate those files on your hard drive? The vs2010 bit seems strange. – Yakk - Adam Nevraumont Jun 01 '15 at 09:52
  • Yes, they are there. I have also compiled them using VS2015 (worked fine!), but that did not change anything. I am getting the same linker error. When I rename a lib so that the path is not correct anymore, I am getting a different error, so I am sure that VS2015 should find the lib. – tmighty Jun 01 '15 at 09:54
  • See http://stackoverflow.com/questions/1211841/how-can-i-make-visual-studios-build-be-very-verbose – kfsone Jun 04 '15 at 19:53
  • @kfsone It is not that easy because it is a chain of linking and compiling. – tmighty Jun 04 '15 at 21:22
  • Edit: I was able to activate it by choosing Linker->General->Extended Output -> Yes (-WI, --verbose), but I still don't have any clue why it might fail to build. – tmighty Jun 04 '15 at 22:07
  • 2
    @tmighty, are you trying to build an app for Android still? If yes, you need to build (or find) a `.a` library. A `.lib` is for windows only. Also, when downloading your project and running it, I got a different error, `clang.exe : error : no such file or directory: '..\..\..\voice\opuscodec.cpp'` It looks like your upload is incomplete. – Matthew Grivich Jun 05 '15 at 22:39
  • @MatthewGrivich Thank you for the info about the requirement of an .a library for Android, I didn't know that. Sorry about the wrong path. "opuscodec.cpp" can be found under MyApp->MySharedObject->MySharedObject- – tmighty Jun 06 '15 at 17:55

2 Answers2

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

dened
  • 4,253
  • 18
  • 34
  • 1) Are you sure that I can use libopus.a in my VS2015 Shared Object just like I would use a lib??? 2) Are you sure that I can not use #pragma comment(lib, ...)? In the clang docu it is said that it can be used: http://clang.llvm.org/docs/UsersManual.html (see "clang supports the Microsoft #pragma comment(lib, "foo.lib")..." 3) I did not put clang.exe anywhere. VS2015 does that. – tmighty Jun 06 '15 at 13:58
  • 1
    @tmighty, 1) Yes, when developing for Android, you should link against lib*.a instead of *.lib, and that library should be compiled specifically for Android. 2) You could read in the manual that Clang understands `#pragma comment(lib, ...)` only when Windows is the target, and the MS linker is used. Otherwise it is ignored (with warning). 3) It is very very strange... I wonder, what else VS2015 placed in the root of your project? – dened Jun 06 '15 at 15:50
  • 1) Thank you for the info. 2) I did not see this remark, thanks for the clarification. 3) There are too many files to mention. You can see them when you download my project. – tmighty Jun 06 '15 at 17:57
  • I add the opuslib.a as you suggested and switched my project to ARM. Then it would compile. – tmighty Jun 06 '15 at 19:00
0

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.

KompjoeFriek
  • 3,572
  • 1
  • 22
  • 35
  • If this would work, I would be the happiest man on earth. May I ask you if you have tried it yourself already? You do not have a version of Opus compiled with clang, do you? – tmighty Jun 05 '15 at 11:40
  • I am unable to select "Clang 3.4" under Configuration->General->Platformtoolset for Opus. – tmighty Jun 05 '15 at 12:06
  • Do you think I can compile a lib with Clang, or will it only create .so or .a files? I am asking because I don't know if I can use anything but a .lib in MyApp. Thanks a lot for all the help! – tmighty Jun 05 '15 at 12:33