VS engineering link optimization problem, vs engineering Link
I plan to try CATCH this test framework in the project. I asked my colleagues to perform a test in the project, but a problem occurred.
Like a framework such as CATCH and GTest, you can define a test function in the C ++ file to automatically register it in the test list, you do not need to explicitly Register Code such as a function to test. In fact, the principle is very simple. It is to define a macro (TEST_CASE). After the macro is expanded, a global object will be defined. The test function is passed in as a constructor parameter, then, the constructor performs the corresponding "Registration" action. Since the constructor of the global variable is executed before the Main function is executed, you can register all the test functions in the test list before the Main function is executed.
The CATCH framework is very easy to use. You only need to include a catch. hpp header file. This is why I am interested in this framework. Although it should be very simple, I first created a new project for testing. In this project, there are three files, one of which contains the main function, the other two are simply defining test functions. Everything went smoothly. Both test cases were executed and the results were correct.
My idea is that the "main function" is defined in a file. Other files only need to write TestCase happily, so it is easy to divide the work, and the merge workload is also very small.
However, when our colleagues do the same thing in our formal development project, there is a problem. The Test case function defined in a separate file is always not executable. I am dumb.
I copied his project to my machine to run it, and the results were the same. A little headache. Later, I noticed that when I put a breakpoint in the newly added TEST_CASE function and run it, the breakpoint will display information like "this breakpoint cannot hit. I had to guess that every time I modify this file VS, the project will be re-compiled and the generated obj file will be visible, but this file may not be linked to the project. Because our formal development project is relatively large and there are many files, it may be because VS did its best to optimize it when compiling a large project, do not link files that are never used. Why does VS think that the newly added TestCase file has never been used? Because the registration method of the CATCH framework (I think GTest is the same) is implicit, and the constructor of the global variables it defines associates another function with the entire TestCase table, then, use the TestCase function table in the Main function to call all the test functions. VS is likely to analyze errors here, mistakenly thinking that these functions will not be used. If I define a function in this file and call it in other functions that will be executed, VS will not optimize it. So I tried this and the TEST_CASE file was executed.
(Optimization is not so easy ~ Who will report it to ~)
For VS2010 MFC optimized Compilation
This is normal. If you want to optimize the size, you can select Favor code size in the optimization options of the c ++ option.
For VS2010 Engineering Problems
The consystemic app is a console application, that is, your program is compiled and run in the console window provided by the system. project is the meaning of the project, you can write a consystemic app in it or a windows gui app. You can use APIs or a form editor to add controls to the window, but you must interact with the space, you still have to call the api.