找不到入口函数的问题,有人见过吗?

yangcock 2010-05-04 11:35:54
第一次编译后,输出 如下,

--------------------Configuration: Tesgine - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
LINK : fatal error LNK1561: entry point must be defined
Error executing cl.exe.

XXX.dll - 1 error(s), 0 warning(s)

===========================
再按f7编译,就能通过了。请问为什么会这样?怎么解决?
...全文
182 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2010-05-04
  • 打赏
  • 举报
回复
LINK : fatal error LNK1561: entry point must be defined??
Error Message
entry point must be defined


The linker did not find an entry point. You may have intended to link as a DLL, in which case you should link with the /DLL option. You may have also forgotten to specify the name of the entry point; link with the /ENTRY option.

Otherwise, you should include a main, wmain, WinMain, or wMain function in your code.

If you are using LIB and intend to build a .dll, one reason for this error is that you supplied a .def file. If so, remove the .def file from the build.
tanwei1002 2010-05-04
  • 打赏
  • 举报
回复
DLL不是有个DLLMain吗
lmxmx 2010-05-04
  • 打赏
  • 举报
回复
这个情况还真没见过……

标记,等高人……
lsupper 2010-05-04
  • 打赏
  • 举报
回复
没碰过这个错误,绑定
xiuxianshen 2010-05-04
  • 打赏
  • 举报
回复
你在写dll?
  • 打赏
  • 举报
回复
DEBUG方式编译时,.DEF 文件需要放在源文件的文件夹中,而不是DEBUG文件夹中。
RELEASE 方式编译时, .DEF 文件需要放在RELEASE文件夹中。
yangcock 2010-05-04
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 hb19820102 的回复:]
引用 10 楼 yangcock 的回复:
引用 7 楼 xuddk727 的回复:
If you are using LIB and intend to build a .dll, one reason for this error is that you supplied a .def file. If so, remove the .def file from the build.

……
[/Quote]

使用的LIB为静态库,不需要import
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 yangcock 的回复:]
引用 7 楼 xuddk727 的回复:
If you are using LIB and intend to build a .dll, one reason for this error is that you supplied a .def file. If so, remove the .def file from the build.


我确实使用了LIB,而且是在编译为DLL……
[/Quote]

在APP中声明DLL中的函数是否正确?
extern "C" _declspec(dllimport)
yangcock 2010-05-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 xuddk727 的回复:]
If you are using LIB and intend to build a .dll, one reason for this error is that you supplied a .def file. If so, remove the .def file from the build.
[/Quote]

我确实使用了LIB,而且是在编译为DLL,工程中存在DEF文件,但是我删除了DEF文件,仍然不行。

PS:VC6.0
  • 打赏
  • 举报
回复
dll文件:
#include <windows.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

extern "C" declspec(dllexport) void myfunc1(void){
MessageBox(NULL,TEXT("myfuc run..."),TEXT("note"),MB_OK);
return;
}

调用DLL的程序文件
#include <windows.h>
void(*pmyfunc)(void);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
LPSTR lpMod = TEXT("c:\\mydll.dll");//改成DLL路径
HMODULE hMod = (HMODULE)LoadLibrary(lpMod);
pmyfunc = (void(*)(void))GetProcAddress(hMod, TEXT("myfunc1"));
pmyfunc();

return 0;
}

你的源码没贴出来,不好判断。
我估计:
1,如果你是显示加载的DLL(调用LoadLibrary),那就是在GetProcAddress函数中写错了DLL中的函数名。
2,如果你是隐式加载的DLL,那么DLL中的函数声明应该在你的程序中声明为
extern "C" _declspec(dllimport) void myfunc1(void);

我写了个示例,但没有亲自验证,应该可以正确执行。你和你的程序对照一下,看哪里不正确。
yangcock 2010-05-04
  • 打赏
  • 举报
回复
是DLL,代码中有dllMain, 我也试过MSDN中的方法:/entry:"DllMain" 仍然不行

--------------
目前的问题就是RebuiltAll后找到入口函数,再按F7后可能找到,如果还找不到再找F7,试几就找到了。
许文君 2010-05-04
  • 打赏
  • 举报
回复
If you are using LIB and intend to build a .dll, one reason for this error is that you supplied a .def file. If so, remove the .def file from the build.
yangcock 2010-05-04
  • 打赏
  • 举报
回复
是DLL,代码中有dllMain, 我也试过MSDN中的方法:/entry:"DllMain"应该不行

--------------
目前的问题就是RebuiltAll后找到入口函数,再按F7后可能找到,如果还找不到再找F7,试几就找到了。

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧