C++ 中的链接错误和名称修改使用 Visual Studio 2008

发布于 2024-10-02 00:31:19 字数 1190 浏览 1 评论 0原文

我在 64 位版本的 Windows 上使用 64 位版本的 Visual Studio 2008。我有一个链接到库(OpenCV 2.1)的项目。我使用相同的编译器从源代码编译了 OpenCV。我的问题在发布和调试模式下都会出现。

在“属性”窗格或我的项目中,我在 C/C++ -> 下添加了包含头文件的目录。 “附加包含目录”。我已将包含 .lib 文件的目录添加到“附加库目录”中,并将库的名称添加到链接器 -> 下的“附加依赖项”条目中。输入。

当我编译和链接时,我收到以下样式的错误: 函数“int __cdecl Label(class cvImage &)”(?Label@@YAHAAV?$cvImage@M@@@Z)中引用了无法解析的外部符号_cvFloodFill

错误LNK2019:在链接器->命令行-> 其他选项,我添加了标签:/verbose:lib,我在编译器输出窗口中看到它正在搜索并查找应包含函数的库(cv210d.lib)。 (我查看了 OpenCV 的源代码,发现有问题的函数是在这个库中定义的)

1>链接...
1>搜索库
1>搜索 C:\Program Files\OpenCV2.1\lib\cv210d.lib:

在 OpenCV 源代码中,它具有外部“C”声明,包装了相关函数的声明。

我在库文件上运行 dumpbin /all ,我看到定义了以下符号。 (我安装了适用于Windows的gnu工具链,所以我可以使用grep)。

C:\Program Files\OpenCV2.1\lib>dumpbin /all cv210d.lib | C:\Program Files\OpenCV2.1\lib>dumpbin /all cv210d.lib | grep cvFloodFill
732B4 __imp_cvFloodFille
732B4 cvFloodFill
1CA __imp_cvFloodFill
1CA cvFloodFill

因此,正如您所看到的,链接器正在寻找符号 _cvFloodFill,但该符号尚未定义。仅定义了 cvFloodFill 和 __imp_cvFloodFill ,因此看起来发生了一些有趣的事情,这使得我编译库时与尝试链接库时的名称修改有所不同。

这就是我被困住的地方。我正确地解释了这些信息吗?我需要做些什么来影响名称修改吗?我是否需要使用某种不同的标志来编译库?

I am using the 64 bit version of Visual Studio 2008 on a 64 bit version of Windows. I have a project that links to a library (OpenCV 2.1). I have compiled OpenCV from source, using the same compiler. My problem occurs in both Release and Debug mode.

In the Properties pane or my project, I have added the directory containing the header files under C/C++ -> "Additional Include Directories". I have added the directory containing the .lib files to the "Additional Library Directories", and I have added the names of the libraries to the "Additional Dependencies" entry under Linker -> Input.

When I compile and link, I get errors in this style:
error LNK2019: unresolved external symbol _cvFloodFill referenced in function "int __cdecl Label(class cvImage &)" (?Label@@YAHAAV?$cvImage@M@@@Z)

Under Linker->Command Line -> Additional options, I added the tag: /verbose:lib and I see in the compiler output window that it is searching and finding the library that should contain the functions (cv210d.lib). (I looked in the source for OpenCV and found that the function in question is defined in this library)

1>Linking...
1>Searching libraries
1> Searching C:\Program Files\OpenCV2.1\lib\cv210d.lib:

In the OpenCV source, it has the extern "C" declaration wrapping the declaration of the functions in question.

I ran dumpbin /all on the library file, and I see the following symbols defined. (I have the gnu tool chain for windows installed, so I can use grep).

C:\Program Files\OpenCV2.1\lib>dumpbin /all cv210d.lib | grep cvFloodFill
732B4 __imp_cvFloodFille
732B4 cvFloodFill
1CA __imp_cvFloodFill
1CA cvFloodFill

So, as you can see, the linker is looking for the symbol _cvFloodFill, but that is not defined. only cvFloodFill and __imp_cvFloodFill are defined, so it looks like something funny is happening that is making the name-mangling different when I compile the library vs when I try to link against it.

So that is where I am stuck. Am I interpreting this information correctly? Is there something I need to do to affect the name-mangling? Do I need to compile the library with different flags of some sort?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月打碎记忆 2024-10-09 00:31:19

我找到了。 (我发布问题和答案是为了其他遇到此问题的人的利益,因为当我搜索网络时没有找到类似的内容)。

当我编译OpenCV时,在解决方案属性下,配置属性->配置中,所有项目的平台均设置为 x64。

当我编译项目时,平台设置为 Win32。答案是单击“配置管理器”,单击项目“平台”下的向下箭头,选择“新建”,然后选择 x64。

现在,该项目和 OpenCV 已针对同一平台进行编译,并且所有内容都可以正确链接和运行。

I found it. (I posted the question and answer for the benefit of anyone else who has this problem, because I didn't find anything like this when I searched the web).

When I compiled OpenCV, under the Solution Properties, Configuration Properties -> Configuration, the Platform for all of the projects was set to x64.

When I compiled my project, the platform was set to Win32. The answer was to click on Configuration Manager, Click on the Down arrow under "Platform" for the project, select "New", and then select x64.

So now, the project and OpenCV are compiled for the same platform and everything links and runs correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文