Visuals studio 2005 project properties configuration essentials


    To program the development of products, in addition to the use of the programming language, you also need a programming environment to assist you. Modern development tools extremely powerful, easy to refactoring, code completion, commissioning a variety of artifacts, so you get things done more efficiently. I am using Visual studio 2005 to do development, suddenly found today, the original of this environment, there are many things worth to explore.


The difference between Debug and Release

    Debug name suggests is a debug version, the program does not generate optimized and contains debug information tracking needs, the program is running, you can set breakpoints, view when the breakpoint occurs, the values ​​of all variables. Plus Visual stdio IDE supporting the various debugging artifact, Call Stacks, Memory, Watch, etc., adding a breakpoint to set policies (data breakpoints, function breakpoint), the program provides a powerful check BUG support.

    Release version release is not normally a member of any debug information, the executable file is much smaller than the debug version, and optimized for the fastest.

    Right Project Properties, -> Configuration Properties-> C / C ++ -> Under General, there is a Debug Information Format option. Generally choose Debug version of the Program Database (/ Zi), generated .pdb file record debug information, generally choose Release version for Disabled.

    Right Project Properties -> Configuration Properties -> C / C ++ -> Under Optimization, there Optimization option, Debug version of the general select Disabled, generally choose Release version of the Maximize Speed ​​(/ O2) optimization for the fastest speed.

    Right Project Properties -> Configuration Properties -> Linker -> Under Debugging, Generate Debug Info option, Debug version of the general select Yes (/ DEBUG), generally choose Release version No.

 

Difference MDd, MD, MTd, MT's

    In Visual studio development environment, right-Project Properties -> Configuration Properties -> C / C ++ -> under Code Generation, there is a Runtime Library option.

They are

Multi-threaded Debug DLL (/MDd)

 

Multi-threaded DLL (/MD)

 

Multi-threaded Debug (/MTd)

 

Multi-threaded (/MT)

 

MD refers to the Multi-threaded DLL, use multi-threaded DLL version of the runtime.

MT refers to the Multi-threaded, non-dynamic library version (version statically linked) runtime uses multiple threads.

After the MD or MT plus a d, represents the debugging version (Debug), whether you use the dynamic link library version or static version of the runtime, if you say, you have the choice of d band in the debugger. Because only with d debugging information when debugging to track inside.

 

In a project there, the runtime can only choose one, if both choose the DLL version (link MSVCRT.lib., Need MSVCRT.dll runtime), and choose a static library version (link LIBCMT.lib), then, runtime will be duplicate definitions, compile time error occurs. So a project, including it depends on a static library project, had unified version of the runtime. Either use the MT, or use MD.

因为MFC也会用到运行库,所以如果使用了MFC的类的话,MFC的运行库也是要和工程的统一起来,在右键项目Properties ->Configuration Properties -> General下的Use of MFC选项,如果使用动态库版本的运行库,那就得选择Use MFC in a Shared DLL,如果使用静态链接的的运行库,那就选择UseMFC in a Static Library。如果没有用到MFC的话,那么选择Use Standard Windows Libraries就可以了。

 

一个工程使用MT或者MTd静态链接的运行库时也会有可能出现编译错误,说某些函数重复定义。如下:

uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecloperator new(unsigned int)" (??2@YAPAXI@Z) already defined inLIBCMTD.lib(new.obj)

 

如果遇到uafxcwd.lib(调试版的带d)或者msvcrtd.lib(调试版的带d)的某某函数已经在libcmtd.lib(调试版的带d)里定义的编译错误,那是因为CRT 库对 new、delete 和 DllMain 函数使用弱外部链接。MFC 库也包含 new、delete 和DllMain 函数。这些函数要求先链接 MFC 库,然后再链接 CRT 库。

    只要右键项目Properties -> Configuration Properties -> Linker -> Input下的 Ignore Specified Library选项填上 uafxcwd.liblibcmtd.lib , 把这两个库都忽略,然后在Linker->Input 下的Additional Dependencies加上 uafxcwd.liblibcmtd.lib(先链接MFC的,再链接CRT),即可解决。

 

 

解决方案的配置

在Visual studio 2005在工具栏中有一个设置Solution Configuration的下拉框,设置当前的解决方案的配置,默认有Debug,和Release两种选择。上面提到有MT,MD两大类别,所以我们可以在里面添加MD_Debug,MD_Release,MT_Debug,MT_Release等,每当我们选定一个配置的时候,Configuration Manager会列出当前解决方案下的所有工程对应当前配置的配置。如下图。

 

我们可以点击对应工程的Configuration的下拉框,设置当前MT_Debug配置下,该工程对应的配置名称,每个工程默认也是只有Debug和Release的,如果需要增加,也可以对每一个工程进行配置。

       当这些都配置好以后,我们就可以非常方便地切换到不同的版本去生成程序。


发布了15 篇原创文章 · 获赞 2 · 访问量 5万+

Guess you like

Origin blog.csdn.net/imhikaru/article/details/8056664