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?
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 namedWinMainand a function namedClientMain, but nomain.It’s fine if you want your library to provide the
mainfunction, but you have to make sure it’s really namedmain, because that’s what the linker will be looking for.