简体   繁体   中英

DLL linker issue

I am compiling a DLL twice (once for x86, once for x64) and I have set /ENTRY to "DllMain". I am using the /MT runtime library option to statically link against the runtime library. This all work fine when doing the x86 build, but the x64 build fails with this:

error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup
{project directory}\LIBCMT.lib(crt0.obj)

Why does this work for the x86 build and not the x64 build? Is there something I am missing here?

Not a direct answer but it may be strictly related: as said in the comment, you should avoid changing the entrypoint in that way: normally the real entrypoint is taken by a "fake" DllMain provided by the CRT to initialize its internal data structures (as explained here ), so you're bypassing it. Probably the size reduction is due to CRT init code being removed.

Your dll is working with a non-initialized CRT, which is very bad. You should leave the default entrypoint, which, incidentally, should solve your problem.

By the way, notice that actually you could make a dll without the CRT (and it would become really small), but you shouldn't use the CRT at all , without even linking against it ( /NODEFAULTLIB switch). This means that you could just use libraries you explicitly link against (eg the Windows API), but I suspect you would lose several C++ features (I think at least exceptions and RTTI).

这可能是一个愚蠢的问题,但你确定你在x64情况下链接为DLL(即指定/DLL开关) - 因为抱怨是关于main ,我想知道它是否试图链接为可执行文件?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM