Question

I am using Visual Studio 2010's toolchain to produce a DLL. Specifically, I want a Matlab module. I believe I am fairly close, but I am running into the following error:

LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
.libs/AverageFilter.mexw32 : fatal error LNK1120: 1 unresolved externals

There is no such symbol in my DLL because it does not make sense for there to be one in a shared library. However, 'libcmt.lib' includes both symbols for executables and DLLs. As such, I understand the error, but since I'm explicitly creating a DLL I was expecting Microsoft's linker to ignore this particular unresolved symbol.

As I understand it, when producing DLLs the expectation is that there be no undefined symbols, but since the only such symbol is irrelevant I decided to use the '/FORCE' option. I really dislike this solution, but first I would like to have a working Matlab module and then refine my solution.

Unfortunately, using the '/FORCE' option results in the following error:

cl : Command line error D8021 : invalid numeric argument '/FORCE'

How can I resolve these errors? Is there a way to have Microsoft's linker to ignore a specific unresolved symbol?

Was it helpful?

Solution

Exe's and Dll's in windows require an entry point if they contain executable code, see this MSDN page for DllMain:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx

For an exe it tends to be main() for a console app, or WinMain for a pure win32 API app.

Since your DLL wants a main() I assume you must have created an EXE console project and then changed it to a DLL later.

To resolve your issue you need to create the entry point function which is normally DllMain, but in your case is actually main. The entry point of your DLL can do nothing (i.e empty/stub function), which will allow it to link, and be loaded/unloaded by the OS, which then allows your client(s) to call your code :).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top