So I'm currently trying to build a .lib file out of my exe utilizing visual studio build scripts as suggested by the accepted answer to this post: Linking to multiple .obj for unit testing a console application. Basically, the post-build script they recommend to place within my project's post-build event is:
lib /NOLOGO /OUT:"$(TargetPath).lib" "$(ProjectDir)\$(Configuration)\*.obj"
Here's what my current directory structure looks like:
-Solution
- Project
-Source
.cpp files
- ProjectTester
- Solution.sln
So my command looks like this:
lib /NOLOGO /OUT:"$(TargetPath).lib" "$(ProjectDir)\Source\*.obj"
This currently does nothing, as though visual studio is ignoring this build script completely. My quesitons are:
What exactly does $(TargetPath).lib resolve to?
and
Is my current understanding of this build script correct? If so, how do I change this script to do what I want?
Update:
I've changed a few spaces in the target path and now I get an LNK1146 no argument specified with option /OUT:
error.
You don't mention what version of Visual Studio you are working with. From memory the answer doesn't change very much but I'll answer for Visual Studio 2015 because that's what I've got handy.
One way to explore macro values that should work for all Visual Studio versions is to use the ECHO
command. Change your post-build script to be
echo TargetPath: "$(TargetPath)"
and you should be able to read the value of the macro in the Output window when you build the project. In most modern versions of Visual Studio, the Echo
trick shouldn't be necessary however.
In the Post-Build Event property page click on the drop-down at the end of the Command Line field and then click on < Edit...>. In Visual Studio 2015 the ensuing dialog will show you the command line(s) and the evaluated value so that you can see the command line(s) with the macros expanded.
There's also the Macros>> button. Click on that button and you'll get a dialog that shows every macro name and its value. The text box at the top of the list lets you filter results to those that contain a character sequence.
$(TargetPath)
is described here as "The absolute path name of the primary output file for the build (defined as drive + path + base name + file extension)". What that really means is the value of the Output Directory, Target Name, and Target Extension properties on the General property page.
The LIB tool is described here. To get more information on the LIB run you could add the /VERBOSE option. You might also remove the /NOLOGO option so you at least get confirmation that you are running LIB (and running the correct version of LIB).
It's difficult to tell what "does nothing" really means. I'd guess the most likely failures are either the lib file is being created - but not where you expect; or there are no obj files in $(ProjectDir)\Source.
One way to explore that latter case would be to change your post-build event to
dir "$(ProjectDir)\Source\*.obj"
and then examine the build output to see if there are obj files listed. If there are no .obj files in the directory the Output Window will show something similar to
1> Directory of C:\TestPrograms\vc.net.2015\VCConsole
1>
1> File Not Found
and the Error List window will show that the dir command exited with code 1.