MSBuild in x64 environment with vcproj

Hello,

With a quick search in the MSDN, I did not find the issue I am having. If this is already discussed, I apologize.

I just got the latest VS2005, and tried to build 64 bit. It fails to build with MSbuild from command line.
I have played just short time, and started with very basic.
Still I am not successful.

I am using VS2005 version is 8.0.50727.42


Here is the very basic scenario.

I have created a new blank project "hello", my default is VC++, and added x64 'platform', then removed Win32 from 'platform' and 'active solution platform' via configuration manager.
I add a new item C++ file as "test.c"

I typed in the famous hello world in test.c:

#include <stdio.h>

int main()
{
   printf("Hello, World\n");
   return 0;
}


Save this project and exit the IDE.
Now I open the "Visual Studio 2005 x64 Win64 Command Prompt" from start menu under "Visual Studio Tools"

In this command prompt, go to the directory where my hello.vcproj
, then typed the following command. 

MSBuild /p:Configuration=Debug hello.vcproj

I get an error:
test.c(1): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory


Does anybody have any idea
Please help!

Thanks,

Ys



Answer this question

MSBuild in x64 environment with vcproj

  • Elliott Downing

    the native 64-bit tools (compiler etc), including vcbuild.exe, only support building 64-bit applications for the machine type you are running on. so, for example, when running vcbuild using the x64 VS command prompt you need to build only x64 configurations of your project. as in:

    vcbuild.exe hello.vcproj "Debug|x64"

    the default configuration to build, if none is specified, is $ALL (i.e. all the configurations in the project) and the non-x64 configs (Win32, Itanium, Smartphone, etc) won't build correctly. that might be the problem you are seeing.

    josh

  • sam8sam

    In VC2005 you will need to use VCBuild.exe. I just checked with the IDE folks.

    VSBuild might work in somecases but I don't believe you can pass options to VCBuild via MSBuild.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • Vincent Randal

    josh,

    I thought having multiple platforms may cause extra problem. So, for this hello example, I believe vcproj contains x64 configuraion only.
    Please see my original post if I did anything wrong creating this project.

    Here is the result from x64 Win64 Command Prompt:
    C:\TEMP\hello>vcbuild hello.vcproj "Debug|x64"
    Microsoft (R) Visual C++ Project Builder - Command Line Version 8.00.50727
    Copyright (C) Microsoft Corp 1993-2003. All rights reserved.

    Build started: Project: hello, Configuration: Debug|x64
    Compiling...
    test.c
    .\test.c(1) : fatal error C1083: Cannot open include file: 'stdio.h': No such fi
    le or directory
    Build log was saved at "
    file://c:\TEMP\hello\x64\Debug\BuildLog.htm"
    hello - 1 error(s), 0 warning(s)

    Extra information on machine, hope this helps:
    C:\TEMP\hello>set PROCESSOR
    PROCESSOR_ARCHITECTURE=AMD64
    PROCESSOR_IDENTIFIER=EM64T Family 15 Model 3 Stepping 4, GenuineIntel
    PROCESSOR_LEVEL=15
    PROCESSOR_REVISION=0304


    Here is the result with Cross Tool Command Prompt:
    C:\TEMP\hello>vcbuild hello.vcproj
    Microsoft (R) Visual C++ Project Builder - Command Line Version 8.00.50727
    Copyright (C) Microsoft Corp 1993-2003. All rights reserved.

    Build started: Project: hello, Configuration: Debug|x64
    Compiling...
    test.c
    Linking...
    Embedding manifest...
    Build log was saved at "
    file://c:\TEMP\hello\x64\Debug\BuildLog.htm"
    hello - 0 error(s), 0 warning(s)
    Build started: Project: hello, Configuration: Release|x64
    Compiling...
    test.c
    Linking...
    Embedding manifest...
    Build log was saved at "
    file://c:\TEMP\hello\x64\Release\BuildLog.htm"
    hello - 0 error(s), 0 warning(s)

    Used dumpbin to see if x64 (copied just top portion):
    C:\TEMP\hello>dumpbin /headers x64\Debug\hello.exe
    Microsoft (R) COFF/PE Dumper Version 8.00.50727.42
    Copyright (C) Microsoft Corporation.  All rights reserved.


    Dump of file x64\Debug\hello.exe

    PE signature found

    File Type: EXECUTABLE IMAGE

    FILE HEADER VALUES
                8664 machine (x64)
                  :
                  :


    Hope this helps,

    Ys


  • JuanJ

    Ayman,

    Thank you for the reply. However, I do not think it is a problem with the .vcproj file itself.
    In fact, vcproj file works with "vcbuild.exe /useenv" as is.

    I guess my question was not clear.
    Due to the RC1, I started using MSBuild.exe to build the project.
    At the time of RC1, I did not build 64 bit. So I do not know how it worked before.

    Anyways, I was hoping I could use MSBuild to build the vcproj.
    Unfortunately it was not working.

    Does this mean MSBuild.exe does not work or support vcproj files so that I should use vcbuild.exe instead

    Hope there is some sort of MSBuild option or environment variable to make msbuild.exe work with vcproj file in x64 environment.


    Do you see if I missed any switch for MSBuild

    Thanks,

    Ys

  • asmand

    Hello Ys,

    To be clear about a few things:

    1) using msbuild.exe on a .vcproj file does nothing other than spawn vcbuild.exe to build that project. you will get much better control (over the switches passed, for instance) if you run vcbuild.exe yourself. unless you have a specific need to run msbuild rather than vcbuild, I suggest you use vcbuild directly.

    2) vcbuild has no reliance on the environment that it is run under *unless* you call it with the /useenv switch. vcbuild uses its own environment (PATH, LIB, INCLUDE etc) settings per target platform, and thus does not need the parent environment (so there is no need to call it from within the VS Command Prompt). I recommend not using /useenv unless you have a particular need that requires that you do so.

    3) there is a native 64-bit vcbuild.exe, but your project file must still contain a 64-bit "configuration" to build a 64-bit output. (while it is possible to build a 64-bit output using a 32-bit configuration by means of /useenv, I would very much discourage anyone from doing this; it is asking for trouble down the road). 

    josh
    Visual C++ Project/Build team developer

  • Thiago Silva

    Ayman,

    Thanks again. I understand MSBuild may or may not work with vcproj files.
    I might have accidentally find the "somecases" work, so I am going to give it a try.


    Ys

  • MikeTheFid

    Ys,

    I'm in the process of setting up a new x64 based machine - I'll take a look into this from the MSBuild side of things and let you know what I find out.

    Kieran Mockford


  • GUYO

    if you set the "show environment in build log" option (from the tools->options->projects and solutions->vc++ project settings dialog) and then rebuild the html build log will contain the environment for the process in which the compiler is run. the INCLUDE variable will contain the path to the system include files. could you try this and let me know what the result is (I'm guessing INCLUDE will not be pointing to where your headers are actually installed.)

    [FYI: the paths for these environment variables are initially loaded from a .config file for each target platform. these files are XML files that are installed alongside the project system binaries in <VSInstallDir>\vc\vcpackages. if you make changes to the paths via the tools->options->projects and solutions->VC++ directories dialog, the changes are saved into a file called VCComponents.dat which is stored in your local application settings directory for Visual Studio. if you edit this file (it is a .ini file) those changes will be reflected in your builds, and if you remove the file the defaults will be re-loaded from the .config files.]

    josh

  • RajuRaman

    Ys,

    MSBuild isn't used to build C++ projects in Visual Studio 2005. All we do is call out to vcbuild.exe to do the build. I'm moving this post over to the VC++ forum so people there can assist. It's most likely something to do with how your include paths are set up for x64 builds.

    Neil

  • gc_asd

    Kieran,

    Thank you for digging into further.
    I am still fighting with my projects with otehr build issue, but
    if I configure the "Command Prompt" to x86 setting to use MSBuild.exe, it seems okay for these include issue.

    FYI, the example I put here only have x64 confing, and it seems succesfully built the "hello" for x64 in x86 configured "command prompt" via assume 32bit MSBuid.exe.

    Let me know if this is okay to do from MSBuild point of vew.
    Thanks,

    Ys

  • Simon L

    Ys,

    Its probably best to take Josh's advice if you have no need to call MSBuild, then go with VCBuild. You should use MSBuild though if you are building a .SLN, particularly there the .SLN contains a mixture of C#/VB/VC++ projects.

    I've just finished getting this going with MSBuild, and it I can't seem to get it to fail.

    I'm using the x64 Cross Tools command prompt, building either the .SLN or the .vcproj works just fine.

    Did you try passing in /p:Platform=x64 I tried both ways and it did work either way.

    Kieran Mockford



  • SSG2006

    You can use vcbuild.exe but you need to specifiy to use the environment supplied by the command window you opened. This could be done using the /useenv switch.

    For example, to build the debug version of your project:

     vcbuild.exe  /useenv temp.vcproj debug

    Of course make sure that not only you add the new x64 platform but you need to change the link /machine option to be /machine:x64 so that not to have linker errors due to conflicts of platforms. You can do that by going to the properties of your project --> Configuration Properties --> Linker --> Advanced and change the Machine Target field to MachineX64 (/MACHINE:X64).

    Hope this helps!

    Thanks,
      Ayman Shoukry
      VC++ Team

     

  • snakey_tv

    josh,

    I have enabled the option. Environments are wrong. Here is INCLUDE, LIB, and PATH from BuildLog.htm from failed build in x64 Win64 Command Prompt.
        INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\include;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\PlatformSDK\include;C:\Program Files\Microsoft.NET\SDK\v2.0 64bit\include
        LIB=C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\lib\amd64;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\atlmfc\lib\amd64;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\PlatformSDK\lib\amd64;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\SDK\v2.0\lib\amd64
        LIBPATH=C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\atlmfc\lib\amd64
        PATH=C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\bin\x86_amd64;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\bin;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\PlatformSDK\bin;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\Common7\Tools\bin;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\Common7\tools;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\Common7\ide;C:\Program Files\HTML Help Workshop;C:\Program Files\Microsoft.NET\SDK\v2.0 64bit\bin;C:\Program Files\Microsoft.NET\SDK\v2.0 64bit\lib\win64;C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727;;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\amd64;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\bin\win64\amd64;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\bin;C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools;C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools\bin;C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;K:\bin;k:\bin\perl5


    There is no VCComponents.dat file exists under my "Local Settings\Application Data" area, or I have never changed the defaults. I did not know if it could be done.

    Here are the INSTALLDIR in x64 Win64 Command prompt
    VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 8
    VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 8\VC

    I assume AMD64.VCPlatform.config is the .config you mentioned. Here is the contents:
    < xml version="1.0" encoding="utf-8" >
    <VCPlatformConfigurationFile
     Version="8.00"
     >
        <Platform
      Name="VCProjectAMD64Platform.dll"
      Identifier="{656d8763-2429-11d7-8bf6-00b0d03daa06}"
      >
      <Directories
       Include="$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(VCInstallDir)PlatformSDK\include;$(FrameworkSDKDir)include"
       Library="$(VCInstallDir)lib\amd64;$(VCInstallDir)atlmfc\lib\amd64;$(VCInstallDir)PlatformSDK\lib\amd64;$(VSInstallDir)SDK\v2.0\lib\amd64"
       Path="$(VCInstallDir)bin\x86_amd64;$(VCInstallDir)bin;$(VCInstallDir)PlatformSDK\bin;$(VSInstallDir)Common7\Tools\bin;$(VSInstallDir)Common7\tools;$(VSInstallDir)Common7\ide;$(ProgramFiles)\HTML Help Workshop;$(FrameworkSDKDir)bin;$(FrameworkSDKDir)lib\win64;$(FrameworkDir)$(FrameworkVersion);$(FxCopDir);$(PATH)"
       Reference="$(FrameworkDir)$(FrameworkVersion);$(VCInstallDir)atlmfc\lib\amd64"
       Source="$(VCInstallDir)atlmfc\src\mfc;$(VCInstallDir)atlmfc\src\mfcm;$(VCInstallDir)atlmfc\src\atl;$(VCInstallDir)crt\src"
      />
        </Platform>
    </VCPlatformConfigurationFile>


    Now looking at these, I have a question. Since PATH is pointing to x86_amd64, isn't it Cross Compiler
    Does this mean VCBuild.exe is actually using Cross Compiler If that is the case, should I use Cross Tool configuration Cross Tool configuration works.

    What do you think

    Ys

  • Vikash Sharma

    Kieran,

    I do not have any trouble with MSBuild either if I am using x64 Cross Tools or Visual Studio 2005 command prompt where it is configured to 32 bit environment.
    As I mentioned this fails in Visual Studio x64 Win64 Command prompt.


    Josh,

    Thank you, it becomes clear it looks to be a vcbuild.exe issue in 64bit environment.
    As you are saying, if it has own INCLUDE environment, it should find a standard C include files <stdio.h>, right

    In Visual Studio x64 Win64 Command prompt,
    if I just type "vcbuild.exe hello.vcproj" it could not find stdio.h.
    However, if I specify /useenv as Ayman mentioned, it works.
    Could this be a installer issue I installed the VS 2005 to default location, but used complete option.

    Path to vcbuild.exe is:
    C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\amd64\vcbuild.exe


    For now, I am using in 32 bit environment to move forward for sorting out 64bit porting issue.
    What I am concerned doing this way is which compiler it is using, cross compiler or native 64bit. Perhaps, it should not make any difference.

    If I should check registry or anything for where those path is set, I am more than happy to do so.


    Thank you for all and willingness to help me.

    Ys


  • MSBuild in x64 environment with vcproj