C++ 为什么当我确定将其放入时,“程序入口点无法在 dll 中定位”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1841721/
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
Why can't a "procedure entry point could not be located in dll" when I definitely put it in?
提问by Jordi
I have a really vague problem, but I hope someone can help with it. I was modifying a C++ project and yesterday it was still working, but today it's not. I'm pretty sure I didn't change anything, but to be completely sure I checked the project out from SVN again and I even reverted to a previous system restore point (because this is a work computer, it sometimes secretly installs updates etc.). After succesfully compiling it, the program can start up, but after I interact with it, I get this error: The procedure entry point ?methodName@className@@UAEXXZ could not be located in the dynamic link library libName.dll.
我有一个非常模糊的问题,但我希望有人可以提供帮助。我正在修改一个 C++ 项目,昨天它仍在工作,但今天它不是。我很确定我没有改变任何东西,但为了完全确定我再次从 SVN 检出项目,我什至恢复到以前的系统还原点(因为这是一台工作计算机,它有时会秘密安装更新等。 )。编译成功后,程序就可以启动了,但是和它交互后,出现这个错误: The procedure entry point ?methodName@className@@UAEXXZ could not belocated in the dynamic link library libName.dll。
I've searched the internet, but most people's problems seem to be caused by an older version of the DLL being used. I searched my computer and there is no older version. If I delete the correct version, the application doesn't start. If I then recompile the project, the DLL is created again, so I'm both pretty sure that the application is using the correct DLL and that the compilation is creating it. If I introduce syntax errors into the method that the error refers to, the project refuses to compile, so I guess this means that it is also compiling the files that contain the method.
我在互联网上搜索过,但大多数人的问题似乎是由使用旧版本的 DLL 引起的。我搜索了我的电脑,没有旧版本。如果我删除了正确的版本,应用程序就不会启动。如果我然后重新编译项目,DLL 会再次创建,所以我非常确定应用程序正在使用正确的 DLL,并且编译正在创建它。如果我在错误所指的方法中引入语法错误,项目将拒绝编译,所以我猜这意味着它也在编译包含该方法的文件。
Basically I don't know anything about DLL's, linking, etc. so I would greatly appreciate it if anybody has an idea as to why the functions that are very clearly defined in the project are all of a sudden not making it into the DLL anymore. I know this is vague and if any more information is required I will gladly provide it. Thanks!
基本上我对 DLL、链接等一无所知,所以如果有人知道为什么项目中非常明确定义的函数突然不再进入 DLL,我将不胜感激. 我知道这很模糊,如果需要更多信息,我很乐意提供。谢谢!
Update:I have tried the given suggestions, but I'm still stuck. __declspec(dllexport)
is apparently not used in the entire project. Opening the DLL with Dependency Walker shows me an empty top right section and the section below it lists the function from the error message. If I check Undecorate C++ Functionsit looks fine, but if I don't I get the weird question marks and @s from the error message and there appears to be a difference at the end:
更新:我已经尝试了给定的建议,但我仍然被卡住了。__declspec(dllexport)
显然没有在整个项目中使用。使用 Dependency Walker 打开 DLL 会显示一个空白的右上角部分,其下方的部分列出了错误消息中的函数。如果我检查Undecorate C++ 函数,它看起来不错,但如果我不这样做,我会从错误消息中得到奇怪的问号和 @s,最后似乎有所不同:
?methodName@className@@UAEXXZ
?methodName@className@@UAEXH@Z
Perhaps this is the problem, but I have no idea what it means, what may have caused this and what I can do about it.
也许这就是问题所在,但我不知道这意味着什么,可能是什么导致了这种情况以及我能做些什么。
采纳答案by Jordi
I feel a bit stupid, but I found the answer. The application (exe) I was using apparently loaded a second, different dll which had a dependency on the one mentioned in my original post. This second dll was still expecting the old functions and also needed to be recompiled against the updated dll.
我觉得有点傻,但我找到了答案。我正在使用的应用程序 (exe) 显然加载了第二个不同的 dll,它依赖于我原来的帖子中提到的那个。第二个 dll 仍然期待旧函数,并且还需要针对更新的 dll 重新编译。
Many thanks to the people who tried to help me here!
非常感谢在这里试图帮助我的人!
回答by Mark Rushakoff
Are you actually using __declspec(dllexport)
? My guess is no -- without that declaration, that function will not be exported by the DLL (or in other words, programs loading that DLL will not have access to functions without that declaration).
你真的在用__declspec(dllexport)
吗?我的猜测是否定的——没有那个声明,该函数将不会被 DLL 导出(或者换句话说,加载该 DLL 的程序将无法访问没有该声明的函数)。
Also, try using Dependency Walkerto see exactly which functions your DLL has made available.
此外,尝试使用Dependency Walker来准确查看您的 DLL 提供了哪些函数。
The fact that __declspec(dllexport)
isn't used in function declarations is okay -- most of the time, it will only be used once in a single header file, like
__declspec(dllexport)
不在函数声明中使用的事实是可以的——大多数情况下,它只会在单个头文件中使用一次,例如
#ifdef MAKING_DLL
#define FOO_API __declspec(dllexport)
#else
#define FOO_API
#endif
So that if you have #define MAKING_DLL
before that section, all functions that are declared like FOO_API int BakeACake()
will be exported based on whether MAKING_DLL
was defined. It's possible that the project was expecting MAKING_DLL
(or its equivalent) to be defined on the command line, depending on the project type built (something like /DMAKING_DLL
; or you might even need to define FOO_API yourself like /DFOO_API=__declspec(dllexport)
.
因此,如果您#define MAKING_DLL
在该部分之前拥有,则所有声明为 like 的函数都FOO_API int BakeACake()
将根据是否MAKING_DLL
已定义导出。这有可能是该项目期待MAKING_DLL
(或同等学历)在命令行上定义,这取决于建项目类型(类似/DMAKING_DLL
;或者,您可能需要自己定义FOO_API一样/DFOO_API=__declspec(dllexport)
。
The empty top right section in Dependency Walker just means your program isn't linking against the DLL's corresponding .lib file. That's okay, it just means you are using LoadLibrary
or LoadLibraryEx
to access functions in the DLL.
Dependency Walker 中右上角的空白部分仅表示您的程序未链接到 DLL 的相应 .lib 文件。没关系,这只是意味着您正在使用LoadLibrary
或LoadLibraryEx
访问 DLL 中的函数。
Another fairly likely scenario (based on the fact that the mangled names are different) is that the program was built using a different version of Visual Studio than 2008, which you used to build the DLL. Unlike plain C, there's no standard binary interface for C++, which means that you have to use the same compiler to build the program and the DLL when you are using C++ classes in the DLL. If you can, try rebuilding the program in VS2008, or try rebuilding the DLL in the same version of VS as the program was built.
另一个相当可能的情况(基于重整名称不同的事实)是该程序是使用不同于 2008 版本的 Visual Studio 构建的,而 2008 用于构建 DLL。与普通 C 不同,C++ 没有标准的二进制接口,这意味着当您在 DLL 中使用 C++ 类时,您必须使用相同的编译器来构建程序和 DLL。如果可以,请尝试在 VS2008 中重新构建程序,或者尝试在与构建程序相同的 VS 版本中重新构建 DLL。
回答by Ponting
Download dependency walkerand open your dll using this tool. It will show a list of exported functions from your dll. Check whether the above said method is part of the expected functions. If it's not, then it means you accidentally removed __declspec(dllexport)
for one of the classes in that dll.
下载依赖项walker并使用这个工具打开你的dll。它将显示从您的 dll 导出的函数列表。检查上述方法是否是预期功能的一部分。如果不是,则意味着您不小心删除__declspec(dllexport)
了该 dll 中的一个类。
回答by Povilas
Using information of the posts above I found simple general solution. All you need to do is open programs executable with dependency walker, look for the missing functions, look what dll's are using it, find the project which builds that dll and rebuild it.
使用上面帖子的信息,我找到了简单的通用解决方案。您需要做的就是打开具有依赖项walker 的可执行程序,查找缺少的函数,查看正在使用它的dll,找到构建该dll 的项目并重建它。