Clrdump (C++) 错误 LNK2019:未解析的外部符号 __imp__RegisterFilter@8 在函数 _main 中引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/334896/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:44:14  来源:igfitidea点击:

Clrdump (C++) error LNK2019: unresolved external symbol __imp__RegisterFilter@8 referenced in function _main

c++visual-studiomakefileclrdump

提问by JosephDoggie

I am using a makefile system with the pvcs compiler (using Microsoft Visual C++, 2008 compiler) and I am getting several link errors of the form:

我正在使用带有 pvcs 编译器(使用 Microsoft Visual C++,2008 编译器)的 makefile 系统,并且出现以下形式的几个链接错误:

error LNK2019: unresolved external symbol __imp__RegisterFilter@8 referenced in function _main

error LNK2019: unresolved external symbol __imp__RegisterFilter@8 referenced in function _main

This is happening DESPITE using the extern "C"declaration, viz.:

尽管使用extern "C"声明,即发生这种情况:

extern "C" int CLRDUMP_API RegisterFilter( LPCWSTR pDumpFileName, unsigned long DumpType );

Also, in the makeexe.mak, the library is being linked in as:

此外,在 makeexe.mak 中,库被链接为:

$(COMPILEBASE)\lib\clrdump.lib \

$(COMPILEBASE)\lib\clrdump.lib \

To be honest, I am not an expert at makefiles, and I am changing over a system from Microsoft Visual C++ 6.0 to 2008. This change-over may have something to do with the link errors, as the system used to work before.

老实说,我不是 makefile 方面的专家,我正在将系统从 Microsoft Visual C++ 6.0 转换到 2008。这种转换可能与链接错误有关,因为该系统以前可以正常工作。

Any help would really be appreciated.

任何帮助将不胜感激。

Thanks in Advance,

提前致谢,

Sincerely, Joseph

真诚的,约瑟夫

-- Edit 1 --

-- 编辑 1 --

Does anyone know how to turn verbose on in the makefile system of pvcs?

有谁知道如何在 pvcs 的 makefile 系统中打开详细信息?

Note that the above function is already a compiler-decorated version, having

请注意,上面的函数已经是编译器修饰的版本,具有

__imp__RegisterFilter@8

whereas the C++ function is just

而 C++ 函数只是

RegisterFilter

Thanks for the help, but if anyone can post a more complete solution, that would also be very appreciated.

感谢您的帮助,但如果有人可以发布更完整的解决方案,那也将不胜感激。

Sincerely, Joseph

真诚的,约瑟夫

-- Edit 2 --

-- 编辑 2 --

Some kind person posted this, but when I signed in it disappeared:

某个好心人发布了这个,但是当我登录时它消失了:

The imp prefix indicates that this function is imported from a DLL. Check the definition of CLRDUMP_API- is it __declspec(dllimport)? See this article for more information.

imp 前缀表示该函数是从 DLL 导入的。检查定义CLRDUMP_API- 是__declspec(dllimport)吗?有关更多信息,请参阅此文章。

There was a working link, but I've lost that, however I suppose one can always search the topic.

有一个工作链接,但我已经丢失了,但是我想人们总是可以搜索该主题。

Thanks, whoever you were!

谢谢,不管你是谁!

-- Edit 3 --

-- 编辑 3 --

Thanks ChrisN (I'm not yet allowed to vote). Despite using the refresh button, your answer disappeared, but then re-appeared after I posted a cut-n-paste.

谢谢 ChrisN(我还不能投票)。尽管使用了刷新按钮,但您的答案消失了,但在我发布了剪切粘贴后又重新出现了。

This is my definition of that:

这是我对此的定义:

define CLRDUMP_API __declspec(dllimport) __stdcall

I assume that the __stdcall is OK?

我假设 __stdcall 没问题?

-- Edit 4 --

-- 编辑 4 --

While I appreciate the efforts of those who answered, particularly ChrisN, at least on my particular system, the link error remains. So if anyone has any further insight, I'd appreciate it. Thanks again.

虽然我感谢回答者的努力,尤其是 ChrisN,但至少在我的特定系统上,链接错误仍然存​​在。因此,如果有人有任何进一步的见解,我将不胜感激。再次感谢。

采纳答案by antonymken

I was creating a simple Win32 c++ application in VS2005 and I was getting this error:

我在 VS2005 中创建了一个简单的 Win32 c++ 应用程序,我收到了这个错误:

LNK2019: unresolved external symbol __imp__somefunction

This application was using property sheets, hence it required this header (prsht.h).

此应用程序使用属性表,因此它需要此标题 (prsht.h)。

The solution to my problem was as follows: in program Properties→Configuration Properties→Linker→General, I set Additional Library Directoriesto "C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib".

我的问题的解决方案如下:在程序属性→配置属性→链接器→常规中,我将附加库目录设置为"C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib".

Also in program Properties→Configuration Properties→Linker→Command linefor the Additional Options, I added ComCtl32.Lib ComDlg32.Lib.

同样在程序Properties→Configuration Properties→Linker→Command linefor the Additional Options 中,我添加了ComCtl32.Lib ComDlg32.Lib.

My program is now compiling without any problems. My two cents: you need to identify all the libraries that your program requires. Hint: check all the headers you have included, you need to make sure that your linker can see them.

我的程序现在编译没有任何问题。我的两分钱:你需要确定你的程序需要的所有库。提示:检查您包含的所有标头,您需要确保您的链接器可以看到它们。

回答by ChrisN

The __imp_prefix indicates that the linker expects this function to be imported from a DLL.

__imp_前缀表示该连接器预计这一功能从DLL进口。

Is the clrdump library from this page? If so, note that extern "C"is not used in the header file supplied with the library. I confirmed this using the following command:

是来自这个页面的 clrdump 库吗?如果是这样,请注意extern "C"在随库提供的头文件中未使用。我使用以下命令确认了这一点:

dumpbin /exports clrdump.lib

which produces the following output for RegisterFilter- this is a mangled C++ function name:

它产生以下输出RegisterFilter- 这是一个损坏的 C++ 函数名称:

?RegisterFilter@@YGHPBGK@Z (int __stdcall RegisterFilter(unsigned short const *,unsigned long))

?RegisterFilter@@YGHPBGK@Z (int __stdcall RegisterFilter(unsigned short const *,unsigned long))

I tried creating a sample program using clrdump.lib using Visual Studio 2008. Here's my code:

我尝试使用 Visual Studio 2008 使用 clrdump.lib 创建示例程序。这是我的代码:

#include <windows.h>
#include "ClrDump.h"

int _tmain(int argc, _TCHAR* argv[])
{
    RegisterFilter(L"", 0);
    return 0;
}

Building this produced the following linker error:

构建它会产生以下链接器错误:

LNK2019: unresolved external symbol "__declspec(dllimport) int __stdcall RegisterFilter(wchar_t const *,unsigned long)" (__imp_?RegisterFilter@@YGHPB_WK@Z)

LNK2019: unresolved external symbol "__declspec(dllimport) int __stdcall RegisterFilter(wchar_t const *,unsigned long)" (__imp_?RegisterFilter@@YGHPB_WK@Z)

The code builds OK with Visual C++ 6.0.

代码在 Visual C++ 6.0 中构建正常。

Notice that the dumpbinoutput shows the first parameter to RegisterFilteras unsigned short const *but the linker error shows wchar_t const *. In Visual C++ 6.0, wchar_tis normally a typedef for unsigned short, whereas in later versions it is a distinct built-in type.

请注意,dumpbin输出显示第一个参数为RegisterFilterasunsigned short const *但链接器错误显示为wchar_t const *。在 Visual C++ 6.0 中,wchar_t通常是 的 typedef unsigned short,而在更高版本中,它是独特的内置类型。

To work around the problem in Visual Studio 2008, I set the "Treat wchar_t as Built-in Type" option to "No" (specify /Zc:wchar_t-on the compiler command line), and the code now builds OK.

为了解决 Visual Studio 2008 中的问题,我将“将 wchar_t 视为内置类型”选项设置为“否”(/Zc:wchar_t-在编译器命令行中指定),现在代码构建正常。

Sorry for the confusion with my previous answer. I hope this is more helpful!

很抱歉与我之前的答案混淆。我希望这更有帮助!

回答by barnaby-bitshifter

I recently had the same problem. I was excluding a library to avoid a collision, and all the bugs went away, except for LINK errors (just as you describe). When I swapped the library for the other one (I was excluding (ignoring) MSVCRT.lib, now I'm excluding (ignoring) LIBCMT.lib) the problem disappeared. Make sure you have not mixed libraries up somewhere. In my case, the linker was failing with "can't find imp_aligned_malloc". Of course there was no method in any of my code by that name. The compiler was prepending the imp. Exactly why I don't know, except that the problem went away when I swapped the exclude (ignore) as described above.

我最近遇到了同样的问题。我排除了一个库以避免冲突,所有的错误都消失了,除了 LINK 错误(正如你所描述的)。当我将库交换为另一个库时(我排除(忽略)MSVCRT.lib,现在我排除(忽略)LIBCMT.lib)问题消失了。确保您没有在某处混合使用库。就我而言,链接器因“找不到imp_aligned_malloc”而失败。当然,我的任何代码中都没有该名称的方法。编译器在前面加上了imp。究竟为什么我不知道,除了当我如上所述交换排除(忽略)时问题消失了。

Try starting with a fresh project, and re-add your source & header files, and keep track of the libraries you exclude (ignore). Try various combinations. Hope that helps.

尝试从一个新项目开始,重新添加您的源文件和头文件,并跟踪您排除(忽略)的库。尝试各种组合。希望有帮助。

回答by Brian

Try turning on verbose output for your linker (typically a command-line switch). That will show you exactly how the linker is trying to resolve the symbol, so you can see if:

尝试打开链接器的详细输出(通常是命令行开关)。这将准确显示链接器如何尝试解析符号,因此您可以查看是否:

  • the symbol's signature is what you expect
  • the linker is looking in the right location for your library
  • 符号的签名是您所期望的
  • 链接器正在为您的库寻找正确的位置

I hope this helps!

我希望这有帮助!

回答by Ago

Don't know if it is your case, but the impprefix may mean that you are compiling a x64 library in a Win32 project.

不知道是否是您的情况,但imp前缀可能意味着您正在 Win32 项目中编译 x64 库。

回答by Tanguy

Using a .DEF File

使用 .DEF 文件

If you choose to use __declspec(dllimport) along with a .DEF file, you should change the .DEF file to use DATA or CONSTANT to reduce the likelihood that incorrect coding will cause a problem:

如果您选择将 __declspec(dllimport) 与 .DEF 文件一起使用,您应该将 .DEF 文件更改为使用 DATA 或 CONSTANT 以减少错误编码导致问题的可能性:

// project.def
LIBRARY project
EXPORTS
   ulDataInDll   CONSTANT

The following table shows why:

下表显示了原因:

Keyword      Emits in the import library   Exports
CONSTANT     _imp_ulDataInDll              _ulDataInDll
             _ulDataInDll                  

DATA         _imp_ulDataInDll              _ulDataInDll

http://msdn.microsoft.com/en-us/library/aa271769(v=vs.60).aspx

http://msdn.microsoft.com/en-us/library/aa271769(v=vs.60).aspx