I have a C++ project where I use Google Test to write my unit tests. The project has been around for a while and is quite messy, so I just added a line at the beginning of the main function that starts the unit tests and then exits the program. I would then comment and uncomment this line for switching between the unit tests and the real application.
This worked okey when only I used my code, but now I'm trying to solve this in a proper way, with two projects and .exe files, one for the real application and one for the tests, like toussa's answer here: Visual Studio C++: Unit test exe project with google test?
And his explanation for doing so here: Linking to multiple .obj for unit testing a console application
The problem is that all the .obj-files are put into this library, including the main function. This makes it impossible for me to link with my testmain, as _main is already defined. I tried adding the "/REMOVE" option to the command, so it looks like this:
lib /NOLOGO /OUT:"$(TargetPath).lib" /REMOVE:"$(ProjectDir)$(Configuration)\mainfile.obj" "$(ProjectDir)$(Configuration)\*.obj"
where mainfile.cpp is compiled to mainfile.obj, I hope. The output from lnk is:
LINK : warning LNK4014: cannot find member object C:\dev\solutions\currentSolution\currentProject\Debug\mainfile.obj
The only thing I found about how to write the name of the object file is from here: http://msdn.microsoft.com/en-us/library/5ff8sk86(v=vs.100).aspx
where they write:
The /REMOVE and /EXTRACT options require the full name of the member object that is to be deleted or copied to a file. The full name includes the path of the original object file. To see the full names of member objects in a library, use DUMPBIN /ARCHIVEMEMBERS or LIB /LIST.
If I type any of those two I get a list where "C:\dev\solutions\currentSolution\currentProject\Debug\mainfile.obj" is one of the entries.
What am I doing wrong? Is there some place that I type something wrong, or is there an easier solution to this problem?