.lib 中的 main 函数作为启动函数?
我想做这样的事情:
library.h
#define main ClientMain
libary.cpp
#define main ClientMain
extern "C" int main (int argc, char *argv[], char *envp[]);
#ifdef WINDOWS
int WINAPI WinMain()
{
// other code here
ClientMain(0, 0, 0);
}
#endif
client.cpp // platform dependent code
#include library.h
int main(int argc, char* argv[]){ // stuff}
但是,我不断收到错误: MSVCRTD.lib(crtexe.obj):错误 LNK2019:无法解析的外部符号 在函数 __tmainCRTStartup 中引用了 main
知道我做错了什么吗?
I want to do something like this:
library.h
#define main ClientMain
libary.cpp
#define main ClientMain
extern "C" int main (int argc, char *argv[], char *envp[]);
#ifdef WINDOWS
int WINAPI WinMain()
{
// other code here
ClientMain(0, 0, 0);
}
#endif
client.cpp // platform independent code
#include library.h
int main(int argc, char* argv[]){ // stuff}
However, I keep getting the error:
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup
Any idea what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在将 Windows 程序编译为控制台程序。在这种情况下,预期的入口点实际上是
main
,而不是WinMain
。后者用于 GUI 程序。您的程序有一个名为WinMain
的函数和一个名为ClientMain
的函数,但没有main
。如果您希望库提供
main
函数,那没问题,但您必须确保它确实名为main
,因为这就是链接器要查找的内容。You're compiling your Windows program as a console program. In that case, the expected entry point really is
main
, notWinMain
. The latter is for GUI programs. Your program has a function namedWinMain
and a function namedClientMain
, but nomain
.It's fine if you want your library to provide the
main
function, but you have to make sure it's really namedmain
, because that's what the linker will be looking for.