简体   繁体   English

如何将Opus链接到您的Visual Studio项目?

[英]How to link opus to your visual studio project?

I wanted to play around with opus some so i downloaded opus 1.1 however it seems like i cant really link it to my visual studio 2010 express project. 我想和opus一起玩,所以我下载了opus 1.1,但似乎无法将其真正链接到我的visual studio 2010 express项目。 I tried adding the opus1.1/include path to properties/vc++Directoris/include Directories, but the linker still complains about some of the functions 我尝试将opus1.1 / include路径添加到properties / vc ++ Directoris / include目录,但是链接器仍然抱怨某些功能

error LNK2019: unresolved external symbol _opus_decoder_create referenced in function ...
error LNK2019: unresolved external symbol _opus_decoder_destroy referenced in function...
error LNK2019: unresolved external symbol _opus_encoder_destroy referenced in function...
error LNK2019: unresolved external symbol _opus_encoder_ctl referenced in function...
error LNK2019: unresolved external symbol _opus_encode referenced in function...
error LNK2019: unresolved external symbol _opus_decode referenced in function...

Any help would be appriciated! 任何帮助都将被申请!

opus1.1 / win32中有一个.sln文件,可在Visual Studio 2010中打开该文件并进行编译以进行调试和发布,然后创建.lib文件。

C++ libraries usually consist of header files (for the compiler) and library files (for the linker). C ++库通常由头文件 (用于编译器)和库文件 (用于链接器)组成。 You only provided header files but no library files, so the linker complains. 您仅提供了头文件,但没有提供库文件,因此链接器抱怨。 The include path is only for header files and has nothing to do with the linker [*]. 包含路径仅适用于头文件,与链接器[*]无关。

The library you downloaded probably contains some *.lib file. 您下载的库可能包含一些* .lib文件。 That's the file needed by the linker. 那是链接器所需的文件。 In Visual Studio, specify the directory of the file at "VC++ Directories > Library Directories" (preferably in the so-called "Property Manager" window), and in your project settings, specify the *.lib file at "Linker > Input > Additional Dependencies". 在Visual Studio中,在“ VC ++目录>库目录”(最好在所谓的“属性管理器”窗口中)指定文件目录,然后在项目设置中的“链接器>输入>”中指定* .lib文件。其他依赖项”。

Now here's the difficulty: you must make sure that your project is compiled with the same runtime-library setting the *.lib file was built with. 现在是困难所在:您必须确保使用与构建* .lib文件相同的运行时库设置来编译项目。 For example, if the *.lib file was built with /MD, then you must do the same. 例如,如果* .lib文件是使用/ MD构建的,则必须执行相同的操作。 If the *.lib file is not provided in the (for you) correct way, then you will eventually want to build the library yourself. 如果没有以正确的方式为您提供* .lib文件,那么您最终将要自己构建该库。

[*] Actually, in MSVC, you can have auto-linking via header files, a technique used by some Boost libraries, but let's ignore this for now. [*]实际上,在MSVC中,您可以通过头文件进行自动链接,这是某些Boost库使用的一种技术,但现在暂时忽略它。

The reason is that the "Windows" distribution of opusfile is compiled with mingw64, and generates .a link libraries, as well as traditional .dll files. 原因是opusfile的“ Windows”发行版使用mingw64进行编译,并生成.a链接库以及传统的.dll文件。 Thus, there is no straightforward way to link opusfile with Visual Studio. 因此,没有直接的方法将opusfile与Visual Studio链接。

This means that, as supplied, you can only use mingw64 to link against the "Windows" distribution, which, if you ask me, is not doing most Windows-based developers any favors. 这意味着,按照提供的方式,您只能使用mingw64链接到“ Windows”发行版,如果您问我,它对大多数基于Windows的开发人员没有任何帮助。

"./configure && make" is how you built UNIX-style software, and requires a large set of text processing support tools (automake, autoconf, a Bourne-like shell, etc) as well as, usually, GCC, rather than the platform-native compiler on Windows. “ ./configure && make”是构建UNIX风格的软件的方式,它需要大量的文本处理支持工具(automake,autoconf,类似Bourne的shell等)以及通常的GCC,而不是Windows上的平台本地编译器。

The right answer is to generate .lib files, either by porting all the code in the distribution to Visual Studio on your own (lots of work) or by generating link libraries from the DLLs: http://support.microsoft.com/kb/131313/en-us 正确的答案是生成.lib文件,方法是将发行版中的所有代码自行移植到Visual Studio(很多工作),或者通过DLL生成链接库: http : //support.microsoft.com/kb / 131313 / EN-US

Note that, in general, this doesn't work -- it only works if the library API is C-based (not C++ based) and if there are no mis-matched allocations (where you do alloc, and library does free, or vice versa) and if the compiler that generated the .dll files is ABI compatible with Visual Studio. 请注意,通常这是行不通的-仅当库API基于C(而不是基于C ++)并且没有不匹配的分配(您在其中进行分配,而库在其中进行释放)时,它才有效反之亦然),并且生成.dll文件的编译器是否与Visual Studio ABI兼容。

You can also generate the linkable libs by generating a "stub" library with empty implementations, and use the .lib from that, or you can use dynamic loading using LoadLibrary() and GetProcAddress(). 您还可以通过生成带有空实现的“存根”库来生成可链接库,并从中使用.lib,也可以通过LoadLibrary()和GetProcAddress()使用动态加载。

So, yeah, the libopusfile developers weren't being particularly helpful to the vast majority of Windows-based developers when building the "windows" version of the library. 因此,是的,在构建库的“ Windows”版本时,libopusfile开发人员对绝大多数基于Windows的开发人员并没有特别帮助。

Btw: I had problems with this very unhelpful SDK myself, and I solved them, and re-packaged the solution for Visual Studio. 顺便说一句:我自己对这个非常无用的SDK遇到了问题,我解决了这些问题,并重新打包了Visual Studio的解决方案。 This includes additional header files that were necessary but not included, as well as generating a .lib linkable library from the functions found using dumpbin. 这包括必需但不包含的其他头文件,以及根据使用dumpbin找到的函数生成.lib可链接库。 Note that this has not been extensively tested, but I have a working opus file playback tool based on this: 请注意,这尚未经过广泛测试,但是我有一个基于此的工作文件播放工具:

http://www.enchantedage.com/opusfile-0.6-for-visual-studio http://www.enchantedage.com/opusfile-0.6-for-visual-studio

This includes the headers and .lib file needed for Visual Studio. 这包括Visual Studio所需的头文件和.lib文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将库链接到visual studio上的项目? - How to link libraries to a project on visual studio? 如何将Qt与visual studio c ++应用程序项目联系起来? - how to link Qt with a visual studio c++ application project? 我该怎么说Visual Studio将图书馆与我的项目链接起来? - How can i say visual studio to link a library with my project? 如何将扩展链接到Project(Visual Studio C ++) - How do I link Extensions to Project (Visual Studio C++ ) 将库(.lib)链接到Visual Studio 2013项目中 - Link library (.lib) into Visual Studio 2013 project 如何从Visual Studio 2010中的Visual C ++项目链接到其他版本的MFC? - How can you link to a different version of MFC from a Visual C++ project in Visual Studio 2010? 如何在Visual Studio中链接DLL? - How to link dll in visual studio? 如何在 Visual Studio 的同一个 C++ 解决方案中将 dll 项目正确链接到另一个项目? - How to correctly link a dll project to another project in the same C++ solution in Visual Studio? 我如何找出一个项目被告知要链接Visual Studio中的特定库? - How can I figure out where a project is told to link a particular library in Visual Studio? 如何解决由于.lib文件添加到Visual Studio中的C ++项目而导致的LINK错误? - How to resolve LINK errors due to addition of .lib files to a C++ project in Visual Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM