C++ 在 Visual Studio 2010 中链接库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5487056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linking Library In Visual Studio 2010
提问by Saint
I'm doing some research on the side when I'm bored and I found this glut32.dll, glut32.h and glut32.lib files that should hold the function definitions (If I'm not mistaken) of several different functions that this source code uses.
当我无聊时,我正在做一些研究,我发现这个 glut32.dll、glut32.h 和 glut32.lib 文件应该保存几个不同函数的函数定义(如果我没记错的话)源代码使用。
I'm using Visual Studio 2010 so I have to add .lib files manually using the project's properties. So...
我使用的是 Visual Studio 2010,所以我必须使用项目的属性手动添加 .lib 文件。所以...
I go to the Project/Properties/Config. Properties/VC++ Directories and add where my header files and .lib/.dll files are to the Include, Reference, Source and Library properties.
I then go into C/C++ in the Config. Prop. menu, into the General tab, and add the locations of my .h/.lib/.dll files to the Additonal Include Directories.
Go back into the C/C++ directory, to the Advanced tab and tell the code to compile as C code (changing this between C and C++ code does nothing in the end).
Then, out of the C/C++ tab, into the Config. Prop.s tab, I enter the Linker tab. Here, I go to the "Additional Library Directories" and add where my .lib and .dll files are.
Then into the Input tab where I write in the name of the .lib file in the Addition Dependencies tab. I've hit apply after every change and click apply/ok this time.
我转到项目/属性/配置。属性/VC++ 目录,并将我的头文件和 .lib/.dll 文件所在的位置添加到 Include、Reference、Source 和 Library 属性。
然后我在配置中进入 C/C++。Prop. 菜单,进入 General 选项卡,并将我的 .h/.lib/.dll 文件的位置添加到附加包含目录。
返回 C/C++ 目录,进入 Advanced 选项卡并告诉代码编译为 C 代码(在 C 和 C++ 代码之间更改此代码最终没有任何作用)。
然后,离开 C/C++ 选项卡,进入配置。Prop.s 选项卡,我进入 Linker 选项卡。在这里,我转到“其他库目录”并添加我的 .lib 和 .dll 文件所在的位置。
然后进入 Input 选项卡,我在 Addition Dependencies 选项卡中写入 .lib 文件的名称。每次更改后我都点击了应用,这次点击应用/确定。
I go to build by code and get this error:
我去通过代码构建并收到此错误:
1>------ Build started: Project: simplVRML, Configuration: Debug Win32 ------
1>Build started 3/30/2011 7:46:45 AM.
1>InitializeBuildStatus:
1> Touching "Debug\simplVRML.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>object.obj : error LNK2019: unresolved external symbol _arLoadPatt referenced in function _read_VRMLdata
1>object.obj : error LNK2019: unresolved external symbol _arVrmlLoadFile referenced in function _read_VRMLdata
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arVrmlDraw referenced in function _main
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arUtilTimerReset referenced in function _main
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arglSetupForCurrentContext referenced in function _main
1>simpleVRML.obj : error LNK2019: unresolved external symbol __imp__arVideoCapStart referenced in function _setupCamera
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arInitCparam referenced in function _setupCamera
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arParamDisp referenced in function _setupCamera
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arParamChangeSize referenced in function _setupCamera
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arParamLoad referenced in function _setupCamera
1>simpleVRML.obj : error LNK2019: unresolved external symbol __imp__arVideoInqSize referenced in function _setupCamera
1>simpleVRML.obj : error LNK2019: unresolved external symbol __imp__arVideoOpen referenced in function _setupCamera
1>simpleVRML.obj : error LNK2001: unresolved external symbol _arMatchingPCAMode
1>simpleVRML.obj : error LNK2001: unresolved external symbol _arTemplateMatchingMode
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arglTexmapModeGet referenced in function _debugReportMode
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arglDrawModeGet referenced in function _debugReportMode
1>simpleVRML.obj : error LNK2001: unresolved external symbol _arImageProcMode
1>simpleVRML.obj : error LNK2001: unresolved external symbol _arFittingMode
1>simpleVRML.obj : error LNK2019: unresolved external symbol __imp__arVideoClose referenced in function _Quit
1>simpleVRML.obj : error LNK2019: unresolved external symbol __imp__arVideoCapStop referenced in function _Quit
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arglCleanup referenced in function _Quit
1>simpleVRML.obj : error LNK2019: unresolved external symbol __imp__arVideoDispOption referenced in function _Keyboard
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arUtilTimer referenced in function _Keyboard
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arglTexmapModeSet referenced in function _Keyboard
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arglDrawModeSet referenced in function _Keyboard
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arGetTransMatCont referenced in function _Idle
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arGetTransMat referenced in function _Idle
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arDetectMarker referenced in function _Idle
1>simpleVRML.obj : error LNK2019: unresolved external symbol __imp__arVideoGetImage referenced in function _Idle
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arVrmlTimerUpdate referenced in function _Idle
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arglCameraViewRH referenced in function _Display
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arglCameraFrustumRH referenced in function _Display
1>simpleVRML.obj : error LNK2019: unresolved external symbol __imp__arVideoCapNext referenced in function _Display
1>simpleVRML.obj : error LNK2019: unresolved external symbol _arglDispImage referenced in function _Display
1>C:\Users\*\Desktop\AltReality\Pwork\simplVRML\Debug\simplVRML.exe : fatal error LNK1120: 34 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.81
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I can confirm the problem is how I'm linking the library, I'm definitely doing something wrong because when I try to link other libraries to other projects the result is the same. I've looked online and I've tried several tutorials, but to no avail- could somebody please tell me what I'm doing wrong?
我可以确认问题是我如何链接库,我肯定做错了什么,因为当我尝试将其他库链接到其他项目时,结果是一样的。我在网上查看并尝试了几个教程,但无济于事 - 有人可以告诉我我做错了什么吗?
回答by JCooper
None of the link errors are for GLUT functions. It looks like you're not linking against the ARToolkit library. That will be a different library that also needs to be included in your input line.
所有链接错误都不是针对 GLUT 函数的。看起来您没有链接 ARToolkit 库。那将是一个不同的库,也需要包含在您的输入行中。
回答by Tim Howe
As the previous post says, make sure your .dll/.lib file(s) are in the same directory as the .exe/.dll you are building and then go to your project's "Solution Explorer", right-click on the project name, choose "Add" -> "Existing Item...", then select the .dll/.lib file you want to include.
正如上一篇文章所说,确保您的 .dll/.lib 文件与您正在构建的 .exe/.dll 位于同一目录中,然后转到您项目的“解决方案资源管理器”,右键单击该项目名称,选择“添加”->“现有项目...”,然后选择要包含的 .dll/.lib 文件。
You should now see the .dll/.lib file listed below the "Source Files" section in the "Solution Explorer". I was seeing the same errors until I performed the steps I just described.
您现在应该会在“解决方案资源管理器”中的“源文件”部分下方看到列出的 .dll/.lib 文件。在执行我刚刚描述的步骤之前,我一直看到相同的错误。
Also, make sure that your header file(s) are included in the project and referenced in the source files appropriately.
此外,请确保您的头文件包含在项目中并在源文件中适当引用。
回答by Jason
Try to put .dll
and .lib
files needed into your project directory.
尝试把.dll
和.lib
文件需要到您的项目目录。
回答by yayay
I was having this problem when I was building a 32-bit application and trying to link to a 64-bit library. Maybe your are having the exact same problem or maybe the reverse. Maybe you are trying to link to a 32-bit library from a 64-bit executable.
我在构建 32 位应用程序并尝试链接到 64 位库时遇到了这个问题。也许您遇到了完全相同的问题,也可能相反。也许您正在尝试从 64 位可执行文件链接到 32 位库。
To fix this in Visual Studio, go to the Configuration Manager. Select the correct platform or create a new platform if needed.
要在 Visual Studio 中修复此问题,请转到配置管理器。如果需要,选择正确的平台或创建新平台。
回答by Eamonn McEvoy
A few things for you to try:
您可以尝试以下几件事:
- Do you have the Dll in the same directory as your exe?
- Is your .h added to your solution?
- Have you added the line #include "glut32.h"?
- Try adding the lib to your solution instead of the project properties.(not ideal but it should get it to compile for now)
- 你的dll和你的exe在同一个目录下吗?
- 您的 .h 是否已添加到您的解决方案中?
- 您是否添加了 #include "glut32.h" 行?
- 尝试将 lib 添加到您的解决方案而不是项目属性中。(不理想,但现在应该可以编译)
Hope this helps, Eamonn
希望这会有所帮助,埃蒙
回答by pradeep
try this
尝试这个
#pragma comment(lib, "dev\lib\avformat.lib")