Thread: Visual C++: LNK4086

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    23

    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!

  2. #2
    Registered User
    Join Date
    May 2011
    Posts
    23
    Update:

    I found a setting that marks /NOENTRY, selected it, and tried to recompile with no success. Same error.

  3. #3
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    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.
    Consider this post signed

  4. #4
    Registered User
    Join Date
    May 2011
    Posts
    23
    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!

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    23
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual Studio DLL and Visual Basic
    By mathguy in forum C Programming
    Replies: 18
    Last Post: 12-08-2011, 03:55 PM
  2. Visual C++ and Visual Studio 2010
    By 03jh01 in forum C++ Programming
    Replies: 5
    Last Post: 10-03-2010, 04:03 AM
  3. Replies: 1
    Last Post: 04-20-2002, 06:49 AM
  4. Moving from Visual Basic to Visual C++
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-10-2002, 09:57 PM
  5. Visual Basic vs. Visual C++
    By Tesita in forum Windows Programming
    Replies: 7
    Last Post: 01-07-2002, 03:02 PM