-
Visual C++: LNK4086
I'm trying to create a DLL within Visual C++. The classes all used to be part of a "test program" with a main.cpp but now I am trying to move them to their own DLL and then have main.cpp reference them.
If it's relevant, here's an example of one of the classes:
Code:
#define dl0 __declspec(dllexport)
class c_Timer
{
private:
ALLEGRO_TIMER *timer;
public:
dl0 c_Timer();
dl0 void initTimer(); //Initializes the timer.
dl0 void startTimer(); //Starts the timer at a rate specified in game::state.fps.
dl0 void stopTimer(); //Stops the timer.
dl0 void destroyTimer(); //Frees up the timer's memory.
};
When I try to compile the entire project, I get no errors other than
Code:
warning LNK4086: entrypoint '_mainCRTStartup' is not __stdcall with 12 bytes of arguments; image may not run
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
Most of what I've found on Google says to change the Configuration Type from "Application" to "Dynamic Library", and I've done that to no avail.
Is there something I'm missing?
Also, should I be putting a dl0 before "ALLEGRO_TIMER *timer" as well?
Thanks!
-
Update:
I found a setting that marks /NOENTRY, selected it, and tried to recompile with no success. Same error.
-
The Config Type = "Dynamic Library" should work. Perhaps try jiggling the handle: "Clean Solution" and rebuild?
If you have multiple projects in the solution, make sure you're changing/building the right project/configuration (it is possible to have different Config Types for debug and release builds). Also, leave the /ENTRY and /NOENTRY options alone, you generally want Visual C++ to use its default entry point.
-
I moved all the source files out of the old solution/project and created a new empty DLL project, imported the sources, and linked the Allegro library again. Still got the same error.
Just tried clean solution too, still nothing.
Is it possible that linking the Allegro library is screwing something up?
Thanks for your help!
-
I figured it out.
Apparently Allegro likes to take over the main() function, so it got confused when it didn't see one. I added
Code:
#define ALLEGRO_NO_MAGIC_MAIN
to the top of the main header file, before any Allegro includes, and everything works now.