Thread: Visual C++ 2008 static linking help

  1. #1
    Registered User Chris87's Avatar
    Join Date
    Dec 2007
    Posts
    139

    Visual C++ 2008 static linking help

    I know this is about VC++ specifically, but I just don't trust Microsoft's boards that much. Plus I know the past several articles on the main page dealt with VC++.

    Anyway, VC++-compiled binaries seem to enforce that I use the MSVC 9.0 runtime DLLs and manifest file regardless if I specify multi-threaded (or debug) or multi-threaded DLL (or debug). I know this because the statically-linked runtime in my binary seemed to work on my computer, but when I transferred it to my parents' computer, the binary began whining about the absence of the runtime DLLs. It worked on my computer because VC++ installs the runtime DLLs of course.

    I just don't want to force people who use my software to install runtimes. Sure, for many, it's not that big a deal. But the general population would see this requirement and not bother. Also, if I were to distribute the runtime, that would make for a bigger download. Likely I want to make more than one project, and I don't want to distribute the runtime in every single download.

    Any help is appreciated!

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    147
    Well, you mentioned solution #1 in your title, link statically.

    That's makes your executable larger, but you have no dependencies at that point. The size increase to your executable is related to the functions the compiler pulls in from the library, but it is probably smaller than the redistributable package.

    Another solution is not to use MFC.

    Of course, that means either another framework, which isn't a bad idea, but also has the same issue of increasing the target size vs a DLL which you would package as part of your install, depending on the framework you choose.

    Did you have a question on how to statically link MFC?

  3. #3
    Registered User Chris87's Avatar
    Join Date
    Dec 2007
    Posts
    139
    Well, I use Express, which is MFC-less. I mean the C runtime itself being statically linkED.

    I'll give it another shot and post any errors I get on my other computer.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Commercial software packages install the runtimes themselves. You aren't the only one who is frustrated by this. With continuous changes in Visual Studio, you never know what your runtime link situation will be after the next release of the development environment. Some people go to such extremes as to completely eliminate any dependence on the C or C++ runtimes altogether by using NO standard functions.

    If you are using straight, standard C++, you might be able to use STLport, a free implementation of the C++ standard library and STL which you can link statically.

    If you are using some of Microsoft's more nonportable C++ elements like MFC, you'll just have to suck it up and create an installer which makes sure these components are present when installing your software. That's what everyone else does (how do people expect commercial software works?)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User Chris87's Avatar
    Join Date
    Dec 2007
    Posts
    139
    I guess I could use NSIS, make an installer that checks for the presence of it and if absent, downloads and decompresses the runtime into the system folder.

    Wait... STLport wouldn't work. VC++ projects force you to choose a runtime type linkage... Hmm.
    Last edited by Chris87; 05-09-2009 at 10:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking error with static template class members
    By cunnus88 in forum C++ Programming
    Replies: 6
    Last Post: 04-02-2009, 12:31 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 12:51 PM