CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Using MSVC from a command line

    For quite some time I've been using VC++8 to build apps that use glib and gtk+. Up to now, these have always been built in the Visual Studio IDE.

    I've set up a special folder for glib/gtk include files (it happens to be F:\+GTK-SOURCES\gnu-win32\include). So in the VS IDE I selected Tools->Options->Projects and Solutions->VC++ Directories->Include Files and I added F:\+GTK-SOURCES\gnu-win32\include (so that I don't need to add it to every project). So far, so good - this all works fine.

    BUT... now I've been given some projects which must be built from the command line. They still get built with MSVC but rather than using VC projects and solutions, the build system is waf. Unfortunately, when I build from the command line, it doesn't seem to know about that extra #include folder that I added - so any header files there simply don't get found.

    I'm sure I could modify each waf script to add that folder but it'd be a lot neater if building from the command line could somehow "know about" that extra folder so that I didn't need to modify all the waf scripts. I tried the obvious method (adding the folder to my path variable) but that didn't help.

    Is there a config file somewhere that I can edit - so that my command-line builds will also use the extra #include folder?
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Using MSVC from a command line

    Quote Originally Posted by John E View Post
    I tried the obvious method (adding the folder to my path variable) but that didn't help.
    Pretty close. VC++ is looking for an environment variable named INCLUDE to locate include file directories. Its syntax is just like PATH. There's also one named LIB for locating library files.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Using MSVC from a command line

    D'oh!

    Yes, I can see it now you've mentioned it but where does it get set up? Usually I select My Computer->Properties->Advanced to set environment variables - but it isn't listed there.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Using MSVC from a command line

    In my VC++ 2010 Express I have a vcvarsall.bat that starts a command prompt with all the related environment variables set up. It's available as Visual Studio Command Prompt in the VS start menu group. I don't know whether that gets automatically updated to reflect changes to the settings made in the IDE. (Actually, I rather doubt that.)
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  5. #5
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Using MSVC from a command line

    Another option instead of setting up everything yourself is to use vcbuild. I've used it in a very large project that contains a lot of solutions by creating a bat file like this
    Code:
    call "%VS90COMNTOOLS%vsvars32.bat"
    
    if not exist msvc_build_all_logs mkdir msvc_build_all_logs
    
    vcbuild /useenv path1\Project1.sln       "Debug|Win32" > msvc_build_all_logs\Project1.log
    vcbuild /useenv path2\Project2.sln       "Debug|Win32" > msvc_build_all_logs\Project2.log
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  6. #6
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Using MSVC from a command line

    Thanks guys. I realised that by selecting My Computer->Properties->Advanced I can set up an INCLUDE var and a LIB var. The Visual Studio command prompt then just adds its own directories to the ones I've predefined.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  7. #7
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Using MSVC from a command line

    Yes but the bad side effect of that method is that you can't have different setups for different situations. In my opinion it's better to setup the same thing in a bat file that is executed whenever you build thru wef.

    I have a lot of projects that uses different versions of inhouse stuff so to not having to manually edit header and lib paths in the IDE I use environment variables that are defined in a bat file before opening MSVC. I agree that it's a bit akward to always open the IDE via a bat file but I haven't found any other way of having the path flexibility.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  8. #8
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Using MSVC from a command line

    Quote Originally Posted by S_M_A View Post
    [...] I agree that it's a bit akward to always open the IDE via a bat file but I haven't found any other way of having the path flexibility.
    You can put a link to the .bat file on the start menu, the desktop or wherever you want. (It's even possible to put the .bat file itself on the desktop but I don't think that's good style.) Then you just have a suerfluous console window lying around, and there's certainly something that can be done about that as well, I just can't tell off the top of my head.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  9. #9
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Using MSVC from a command line

    I'm a keyboard guy so I have the bat files where the other project files are. Maybe I was a bit negative saying that it's akward, it's really only when switching project it feels a bit strange to close the IDE instead of just using File - Recent Projects since the environment has to be changed.

    Opening the IDE from the bat file using start "path to IDE exe" solutionfile.sln spawns the IDE and then closes the console window so in practice it works pretty well.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  10. #10
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Using MSVC from a command line

    Definitely worth keeping in mind
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  11. #11
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Using MSVC from a command line

    Quote Originally Posted by S_M_A View Post
    I'm a keyboard guy [...]. [...]
    Oh, ok, then I obviously misunderstood your question and my suggestion even was somewhat counterproductive...

    Opening the IDE from the bat file using start "path to IDE exe" solutionfile.sln spawns the IDE and then closes the console window so in practice it works pretty well.
    I had something like that in mind but was only about 96% sure that way the environment variables would properly get inherited by the IDE process. OTOH, with hindsight: What else could happen to the environment variables...?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  12. #12
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Using MSVC from a command line

    Just to make the thread complete I post an example of a project bat file as well.
    Code:
    set BOOST_ROOT=z:\common\boost_1_47_0
    set EXPAT_ROOT=z:\common\expat-2.0.1
    ...
    
    path=%BOOST_ROOT%\...\...;%path%   only if path is needed for something
    
    start "%VS90COMNTOOLS%\..\IDE\VCExpress.exe" project.sln
    In the project properties I use the environment vars ( i.e. $(BOOST_ROOT) ) wherever a path is needed. If several projects needs to have the same base I extract the setting of environment vars to a separate bat file to be able 'upgrade' all projects by just changing a single line.

    As said, it works pretty well if one has to be able to maintain projects that uses different versions of stuff like boost and so on.

    I saw your comment Eri523 about environment vars when preview-ing and yes they are inherited so using the bat files also avoid a common source for irritation... I can't count how many times I've changed the global environment and afterwards ripped my hair off trying to understand why there was no change just to find out that I forgot to restart the IDE...
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured