Standalone VS 2010 C++ Program

后端 未结 5 599
迷失自我
迷失自我 2021-01-24 09:50

it\'s been a long while since I\'ve used VS 2010 and C++, and as I\'m getting back to using it, I\'m running into the same problems that plagued me last year: the exe\'s that I

5条回答
  •  被撕碎了的回忆
    2021-01-24 10:32

    Firstly, before I actually give you the detail:


    Warning

    If you do this, things will be bad for two reasons:

    1. If there are security or other bugs in the MSVC runtimes, and you take this approach, they're baked into your app which means you need to re-distribute. DLLs are preferred because theoretically people use system update which means any errors get fixed.
    2. Everything else you compile into your exe also needs to do this. If you don't, you end up with two versions of the code and whatever you're using won't link.

    One possible solution is to bake the MSVC runtime into your application, by using the cl.exe option (C/C++ compiler settings) /MT which means multi-threaded version of the C/C++ runtime linked statically. As I said, if you try to link against something that is linked itself dynamically to the runtime, you're going to end up in a mess. Also, as I said, this represents an additional security risk factor, so bear that in mind.

    The other options are to write an installer that can either download the appropriate runtime, or include the DLL needed.

    If you're using some feature of the runtime that exceeds a certain version of Windows (generic statement, but it does happen) then you should be able to use the Windows SDK to target various versions of Windows using appropriate C runtimes.

提交回复
热议问题