Compile a specific obj in a Visual Studio Project from the Command Line?
I want to compile file.obj
from the commandline. Within the IDE, if I'm viewing file.cpp
, I can click on Build -> Compile (or just hit Ctrl-F7), and it will compile just the file.obj object. I would like to be able to do this from the commandline. Ideally, something akin to:
vcbuild project.vcproj Debug file.obj // not a valid command
I have looked at the documentation for vcbuild
, msbuild
, and devenv
. I've also experimented with all three, but I cannot find a way to do this. I can find a way to build an entire project, but that's not what I want. I want to build a specific source file. /pass1
tells vcbuild to just compile (not link), but it compiles the entire project.
I also looked at using cl
, but that is just the compiler. In order to use it, I would have to know all the right parameters to pass to set up my environment co开发者_如何学编程rrectly. All that is automatically taken care of with msbuild/vcbuild.
With Makefiles, I could always do make file.obj
, and it would properly set path, include dirs, etc.
Any options for this? Is there an automated way to extract the appropriate settings from the .vcproj
file, and pass them to cl
?
Using cl is the way to compile single files from the command line. Like you say, it requires/allows you to specify exactly the options you want to use. All the options!
If you actually don't want to do that, why not use the IDE to have it done automagically for you? Why do it the hardest way, if you don't like that?
if you just want to compile the project, run the visual studio command line and call msbuild.
Example:
MSBuild.exe MyProj.proj /property:Configuration=Debug
this will compile the MyProj Project from the current directory.
more info on msbuild http://msdn.microsoft.com/en-us/library/dd393574.aspx
Or if you need to build a single file you can use cl as stated above. You can see all the parameters passed by visual studio to cl if you go in the properties of the project. Usually under:
Configuration Properties -> C/C++ -> Command Line
and for linking:
Configuration Properties -> Linker -> Command Line
精彩评论