0

I have a project that I added a gtest project to, then turned the original project into a .lib project and called its main() function from a 3rd, new project. This way, I can build the test .exe with the project .exe. Except, it's not working.

These are the steps I've followed as mentioned here
Create or open a project, then create a Win32 Console Application test project for it.
Right click the test project, go to properties, and set Configuration to debug.
Go to Configuration Properties > C/C++ > General > Additional Include Directories and add the gtest includes folder.
Under Code Generation > Runtime Library, choose MDt or MTd; whatever is used by the project to be tested.
Under Linker > General > Additional Library Directories, add a reference to the folder with gtestd.lib.
Under Input > Additional Dependencies, add gtestd.lib.
Right click the test project, go to properties, and set Configuration to release, then perform steps 3 and 4.
Under Linker > General > Additional Library Directories, add a reference to the folder with gtest.lib.
Under Input > Additional Dependencies, add gtest.lib.

These are the steps I've followed for linking the test project, as mentioned here
Right click the test project, go to Build Dependencies > Project Dependencies, and add the project to be tested.
Go to Properties > C/C++ > General > Additional Include Directories and include headers from the project to test.
Under Linker > Input > Additional Dependencies, enter the .lib file of the project

Here is the problem
For some reason, the test project surprisingly works, but only in release mode. The wrapper project doesn't work in either mode, despite having the same settings as the test project. I've looked at 20 possible solutions and have yet to find one. I also tried __declspec(dllexport) in front of every method in the library project, but that doesn't do any justice. VS is fighting me tooth-and-nail.

Other stuff I tried
I don't want to change the project to build a .lib every time I need to test. So I looked into creating both a .exe and .lib from the project using a pre-link build event, but it seems to only take console commands and I couldn't figure out how to hook up the resulting .lib file from the console commands I got from another SO answer.

Here is the current .sln file with these problems. URLs are absolute: https://drive.google.com/file/d/0B6r81tGW7hODeXNpR3ROc3hYMWc/view?usp=sharing

How do I simply make a test project and wrapper project to launch a normal project (that works in both debug and release mode)?

Community
  • 1
  • 1
person27
  • 65
  • 1
  • 10
  • I'm asking for the normal project as a .lib, a test project, and a wrapper to launch the .lib project. There are no blogs or documentation that do all three points, so I supplemented with advice from other areas, but it doesn't work. What posts say I should do (linker -> include libraries, C++ -> General -> add include headers here) is apparently insufficient. I've set up for debug and release mode. Now I'm wondering if people just pretend that it works; this is beyond difficult. By the way, I'll take a working .sln file at this point without complaint or further question. – person27 Nov 23 '16 at 17:58
  • Every resource I listed and similar questions were on Stack Overflow so I didn't think about whether this fit the site or not. On the other hand, I can't say it would do well in superuser unless they like to discuss project config, so I don't know if a migration would be useful. What I do know is that if it does get answered, somebody will appreciate it :) There is a critical lack of working gtest examples in my experience. – person27 Nov 27 '16 at 16:25

1 Answers1

1

Fixes:

  1. In SimpleCalc (debug), change Project | Properties | General | Configuration type to Static Library. This is why Release worked but Debug didn't.
  2. For SimpleCalcWrapper, select Project | Add reference... and add SimpleCalc. This is why SimpleCalcWrapper didn't work.
  3. For SimpleCalcTest (release), reset to default Project | Properties | Linker | Advanced | Import Library or SimpleCalcTest.exe will not compile.
  4. For SimpleCalcTest, change Project | Properties | C/C++ | Additional Include Directories to $(SolutionDir)\gtest\include;$(SolutionDir)\SimpleCalc;%(AdditionalIncludeDirectories). This will have them relative to the project.
  5. For SimpleCalcTest, change Project | Properties | Linker | Additional Library Directories to $(SolutionDir)\gtest;%(AdditionalLibraryDirectories) - you don't need SimpleCalc directory because the project is added to references.
  6. For SimpleCalcWrapper, change Project | Properties | C/C++ | Additional Include Directories to $(SolutionDir)\SimpleCalc;%(AdditionalIncludeDirectories)
  7. For SimpleCalcWrapper, reset to default Project | Properties | Linker | Additional Library Directories - you don't need SimpleCalc directory because the project is added to references.
Codeguard
  • 7,787
  • 2
  • 38
  • 41
  • Fantastic. It looks like I performed the steps wrong, probably between the debug/release versions. I know I tried to fix it using a hodgepodge of answers I *thought* I was able to undo correctly. Thanks especially for the $(SolutionDir) tip. – person27 Nov 28 '16 at 00:53