Main function in .lib as startup function?
I want to do something like this:
library.h
#define main ClientMain
libary.cpp
#define main ClientMain
extern "C" int main (int argc, char *arg开发者_JAVA百科v[], 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?
You're compiling your Windows program as a console program. In that case, the expected entry point really is main
, not WinMain
. The latter is for GUI programs. Your program has a function named WinMain
and a function named ClientMain
, but no main
.
It's fine if you want your library to provide the main
function, but you have to make sure it's really named main
, because that's what the linker will be looking for.
精彩评论