What options are needed to compile ATL programs using the MSVC 2010 command line tools? - visual-c++

I'm trying to build an ATL program using the MS command line tools from the Windows SDK 7.1. I've installed the Windows Driver Kit 7.1.0 in order to get the ATL headers and libraries and for the most part I've been successful. I can build it perfectly for x86 systems using either MSBuild or a custom makefile for nmake but when I try and build it for x64 I get the following errors:
<project>\include\atl71\atlplus.h(21): error C3360: 'ATL4': cannot create IAttributeHandler [<project>.vcxproj]
<project>\include\atl71\atlplus.h(21): fatal error C1903: unable to recover from previous error(s); stopping compilation [<project.vcxproj]
0 Warning(s)
2 Error(s)
The really annoying thing is that using the exact same solution file and configuration, Visual Studio can build the x64 version fine. Clearly I'm missing something as all these tools use the same version of cl.exe to perform the actual compilation...

I ran into the same problem using the full DevStudio IDE. I had done exactly as you (copied Win32 settings to thex64 target platform) I Configuration Manager but kept getting that same annoying message. I fixed it by NOT using the WinSDK v7.1 toolchain which is selectable in the project's property pages: specifically, within the "Configuration Properties" node, "General" items. The property is called "Platform Toolset" (again, all this is within the IDE) and I changed my selection in the dropdown from Windows7.1SDK to v100. The latter purports to utilize the DevStudio-only tools and utilities for building just about everything (e.g. HTML Help Compiler is still external). I have a theory that if you download the latest and greatest ATL found in the Windows Driver Kit SDK from Microsoft.
I hope that tidbit may be useful in steering you in the right direction. Good luck!
S. Sean Stagner

Create a batch fiel with the following script, then run it:
pause
setx DevEnvDir %%VSINSTALLDIR%%\Common7\IDE\
setx Framework35Version v3.5
setx FrameworkDir C:\Windows\Microsoft.NET\Framework\
setx FrameworkVersion v4.0.30319
setx LIBPATH %%FrameworkDir%%%%FrameworkVersion%%;%%FrameworkDir%%%%Framework35Version%%
setx PATH ""
setx PATH "%%DevEnvDir%%;%%VSINSTALLDIR%%\VC\Bin;%%VSINSTALLDIR%%\Common7\Tools;%%FrameworkDir%%%%FrameworkVersion%%;%%FrameworkDir%%%%Framework35Version%%;%%VSINSTALLDIR%%\VC\VCPackages;%%PATH%%"
setx VC_PROJECT_ENGINE_NOT_USING_REGISTRY_FOR_INIT 1
setx VCINSTALLDIR %%VSINSTALLDIR%%\Bin\
setx VS100COMNTOOLS ""
setx VSINSTALLDIR "D:\Program Files\Microsoft Visual Studio 10.0"

Related

MSBuild using the wrong cl.exe when building with the 2015 C++ v140 Platform Toolkit

We're currently making a build environment for some of our projects.
In particular we're using VC++ 6.0 and VS2019 to build some of these projects.
When building our C++ project in VS2019 with the Platform Toolkit set to C++ 2015 v140, MSBuild attempts to use the VC++ 6.0 compiler to build the project. If I switch the Toolkit to any other version it builds with the correct cl.exe.
If I remove the VC98 folder that contains cl.exe from the path environment variable I get a cl.exe can't be found error in VS2019.
So I think there's something hardcoding the 2015 toolkit against the VC6.0 cl.exe.
I've tried installing and reinstalling the additional components in the VS Installer but no luck.
Repair of VS2019 didn't fix it either.
I've tried all versions of Visual Studio back to 2013 same issue.
This looks like an MSBuild issue, it's in the wrong location.
Is there any place where I can view the mapping for the toolkits in MSBuild? I couldn't see much in the registry.
The output when I build shows the following, the version is clearly a very old compiler (the VC6.0 one):
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86

PhoneGap add wp8 platform requires MSBuild x86

When trying to add the wp8 platform to a project, using:
phonegap local build wp8
It fails. Requiring msbuild x86.
C:\Program Files (x86)\MSBuild\Microsoft\WindowsPhone\v8.0\Microsoft.WindowsPhon
e.v8.0.Overrides.targets(15,9): error : Building Windows Phone application using
MSBuild 64 bit is not supported. If you are using TFS build definitions, change
the MSBuild platform to x86. [C:\funiz\platforms\wp8\Funiz.csproj]
ERROR: MSBuild failed to create .xap when building cordova-wp8 for debugging.
This is a Windows 8.1 machine, with Visual Studio Ultimate 2013, Update 2 RC.
The PATH environment variable is set to:
C:\Users\Yoram Kornatzky\AppData\Roaming\npm;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Windows\Microsoft.NET\Framework\v4.0.30319
I tried removing the Frame64 element from the PATH. But it still fails.
Any insight would be appreciated.
You haven't specified the build template you are using. But if you are using DefaultTemplate in your team build definition, change value of parameter "MSBuild Platform" from Auto to X86

Various issues installing igraph in Visual Studio 2010 and Cygwin/MinGW ("sys/time.h not found")

I couldn't get igraph to work with Visual Studio 2010 (supposedly many known issues), and so decided to try installing it in Cygwin. ./configure went fine. But make gave this error:
f2c/dtime_.c:16:23: fatal error: sys/times.h: No such file or directory
Makefile:2190: recipe for target `libf2c_la-dtime_.lo' failed
make[3]: *** [libf2c_la-dtime_.lo] Error 1
I tried installing it in MinGW and get the same error when I make. Should I be providing "sys/time.h" or a path to it? Where is sys/time.h? Using Windows 7.
Edit
The problems in Cygwin and MinGW was due to the wrong version of gcc being used by my clean installation of Cygwin (and a characteristic of MinGW). Solution here: Installing/compiling in Cygwin/MinGW - How to set the include "path"? (symbolic link?)
The problem in Visual Studio 2010 was due to building in "Debug" instead of "Release". One of igraph's creator, Gábor Csárdi, graciously provided an excellent step-by-step guide below that identified and resolved it.
Igraph actually does work with Visual C++ 2010 Express, we test this before releases, and I have just tried it. You need to do the following steps.
Download the source package specifically created for Visual Studio.
Uncompress the file into My Documents\Visual Studio 2010\Projects.
Open the igraph.sln solution file in igraph-0.6-msvc\igraph-0.6-msvc directory from Visual Studio.
Visual Studio offers to convert the solution file to the current format, do that. Just click on Next, Next and Finish.
On the toolbar, change 'Debug' to 'Release' to make release builds.
Choose Debug -> Build solution and wait until the library is built.
To test it you can open the solution file in the igraphtest directory, convert it as well, choose 'Release' builds, and then build it and run it from the command line. It is a simple C++ program that uses igraph to create a graph and write it into the file out.txt.
You don't have to set up include and library directories at all, everything is set up properly in the solution file, both for igraph and igraphtest.
is there an sys/times.h file?
I have a vague memory that I had to make that symlink on a system once.

fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'

I'm using CUDA (VC++, Visual studio 2008sp1) to debug a FEM program. The program can only run on a Win32 platform, for the insufficiency of cuda. I think the library files linked are all compiled on the x86 platform, but when I compile it, I get the error message
fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'.
I have tried to convert the platform to x64, but it didn't work. Please tell me: what is "module machine type" and what is "target machine type"? How can I overcome it?
I wrote a blog entry about this, as I encountered this maddening problem, and finally yanked my system back into working order.
These are the things to check, in this order:
Check your properties options in your linker settings at: Properties > Configuration Properties > Linker > Advanced > Target Machine. Select MachineX64 if you are targeting a 64 bit build, or MachineX86 if you are making a 32 bit build.
Select Build > Configuration Manager from the main menu in visual studio. Make sure your project has the correct platform specified. It is possible for the IDE to be set to build x64 but an individual project in the solution can be set to target win32. So yeah, visual studio leaves a lot of rope to hang yourself, but that's life.
Check your library files that they really are of the type of platform are targeting. This can be used by using dumpbin.exe which is in your visual studio VC\bin directory. use the -headers option to dump all your functions. Look for the machine entry for each function. it should include x64 if it's a 64 bit build.
In visual studio, select Tools > Options from the main menu. select Projects and Solutions > VC++ Directories. Select x64 from the Platform dropdown. Make sure that the first entry is: $(VCInstallDir)\bin\x86_amd64 followed by $(VCInstallDir)\bin.
Once I did step 4 everything worked again for me. The thing was I was encountering this problem on all my projects where I wanted to compile towards a 64 bit target.
In addition to C Johnson list I would add the following point:
Check in Visual Studio:
Project Properties -> Configuration Properties -> Linker -> Command line.
"Additional Options" should NOT contain /machine:X86
I have such key, generated by CMake output: CMake generated x86 project, then I added x64 platform via Configuration Manager in Visual Studio 2010 - everything was created fine for the new platform except that the linker command line, specified /machine:X86 separately.
I experienced the same problem in VS2008 when I tried to add a X64 build to a project converted from VS2003.
I looked at everything found when searching for this error on Google (Target machine, VC++Directories, DUMPBIN....) and everything looked OK.
Finally I created a new test project and did the same changes and it seemed to work.
Doing a diff between the vcproj files revealed the problem....
My converted project had /MACHINE:i386 set as additional option set under Linker->Command Line. Thus there was two /MACHINE options set (both x64 and i386) and the additional one took preference.
Removing this and setting it properly under Linker->Advanced->Target Machine made the problem disappeared.
All project settings seemed perfect, but I still got the error. Looking into the .vcxproj file and searching for "x86" revealed the problem:
<Lib>
<AdditionalOptions> /machine:X86 %(AdditionalOptions)</AdditionalOptions>
</Lib>
A quick search/replace for all occurrances (ten individual file settings) fixed the problem.
You probably have one .OBJ or .LIB file that's targeted for x64 (that's the module machine type) while you're linking for x86 (that's the target machine type).
Use DUMPBIN /HEADERS on your .OBJ files and check for the machine entry in the FILE HEADER VALUES block.
Since the problem is due to the difference in compilation and target machine specifications (x86 & x64)
Follow the steps below:
Open the C++ project that you want to configure.
Choose the Configuration Manager button to open the Configuration Manager dialog box.
In the Active Solution Platform drop-down list, select the option to open the New Solution Platform dialog box.
In the Type or select the new platform drop-down list, select a 64-bit platform.
It solved my problem.
In Visual Studio 2012 +/-, the property page for "Configuration Properties'.Linker."Command Line" contains a box labeled "Additional Options". If you're building x64, make sure that box doesn't contain /MACHINE:I386. My projects did and it generated the error in question.
I came across this problem when building QT. The instructions I read somewhere suggested that I configure nmake using VS command prompt.
I chose the x64 command prompt and performed configure without much hassle. When i tried nmake, it gave this error.
I think some of the components were pre-built for 32-bit. The error even reported which modules were built for x86.
I used the 32 bit default VS command prompt and it worked.
"project property - CUDA Runtime API - GPU - NVCC Compilation Type"
Set the 64 bit compile option -m64 -cubin
The hint is at compile log.
Like this:
nvcc.exe ~~~~~~ -machine 32 -ccbin ~~~~~
That "-machine 32" is problem.
First set 64bit compile option,
next re setting hybrid compile option.
Then u can see the succeed.
In Visual Studio 2013,
1) Check in the Project Property Pages / Configuration Properties / Linker / All Options and correct all the miss configured machine and directories.
2) Check in the Project Property Pages / Configuration Properties / Linker / Input and correct all the miss configured directories.
See example of 1)
If your solution has lib projects check Target Machine property in Property->Librarian->General
vcxproj file may contain 'MACHINE:i386'
Edit vcxproj file with editor. remove it !
My target is a x64 Windows 10 text mode DOSBox application in C language.
Using "Visual Studio 2019 Community" to compile through DOS prompt "nmake -f makefile".
The error is similar but on the opposite side:
fatal error LNK1112: module machine type 'x32' conflicts with target machine type 'X64'
It's ok to compile by VC++ 2010 on another computer. But failed on this computer by "Visual Studio 2019 Community". So my settings are correct and all above answers do not work.
I'd like to share you that the solution is a make.bat like this:
call "c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
nmake -f makefile
You will find there are many other vcvarsxxxx.bat, only this one words.
In my case, setting environment variable PROCESSOR_ARCHITECTURE to AMD64
fixed the problem.
https://social.msdn.microsoft.com/Forums/en-US/f9303904-81ce-405d-85b3-b66d97e49971
In addition to Jhonson's list, also check library's folders
In visual studio, select Tools > Options from the main menu. select Projects and Solutions > VC++ Directories. Select x64 from the Platform dropdown.
$(VCInstallDir)lib\AMD64;
$(VCInstallDir)atlmfc\lib\amd64;
$(WindowsSdkDir)lib\x64;
This happened to me today because I had added a library directory while still in x86 mode, and accidently removed the inherited directories, making them hardcoded instead.
Then after switching to x64, my VC++ Directories still read:
"...;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);"
instead of the _x64.
I was using CMake & then added a win32 configuration. The property page showed x86 but actually when opening the vcxproj file in a text editor it was x64! Manually changing to x86 solved this.
First of all try the following things:
1. goto configuration Manager and create a new x64 if it is not already there.
2. select the x64 solution.
3. go to project properties and then Linker->Advanced select x64 machine.
4. Now rebuild the solution.
If still you are getting the same error. try clean solution and then rebuild again and open visual studio you will get list of recent opened project , right click on the project and remove it from there. Now go to the solution and reopen the solution again.
It's a very frustrating and annoying problem but once you understand it, it's quite simple: you have some element in you're build that building one architecture type (in your case x64) despite the fact that it's been target for another type (say x86).
You can dissect the source of your problem by looking at which obj file is causing the crash and start looking for the problem there. Every obj will have a source code analog: either in cpp, c, asm etc. There may be special build events around it that are using the wrong tool. Check for that in the property sheets.
I'd look there first before going through C Johnson list of things to do.
I solved this problem by changing Win32 to *64 in Visual Studio 2013.
Many good suggestions above.
Also if you are trying to build in x86 Win32:
Make sure that any libraries you link to in Program Files(x86) are actually x86 libraries because they are not necessarily...
For example a lib file I linked to in C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\SDK threw that error, eventually I found an x86 version of it in C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x86 and everything worked fine.
Properties->configurationManager-> ActiveSolutionPlatform . Here select x64 .thats all.
It should take care of all dependencies and compilation should work smoothly
module machine type is the machine on which you are compiling and the target machine type is the the architecture x86 or x64 for which you are building your binaries.
This problem may also happen if your project set up to have the same intermediate directories in Project Properties -> Configuration Properties -> General
this happens to me when i convert my VS2008 solution to VS2010 & change win32 configuration to X64, in my old solution I have mfcs90d.lib (Configuration->Linker->Input->Additional dependencies), as I am using VS010 i just checked in VS2010 folder where it is mfcs100d.lib, so I changed mfcs90d.lib to mfcs100d.lib in (Configuration->Linker->Input->Additional dependencies) it worked fine.
For those who are with QT Creator, the issue is same (as described by #c-johnson).
Make sure the compiler settings for MSVC in your kit is set to x86 as shown below.
for some using command prompt (dos prompt)
this might be helpful:
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" --help
Error in script usage. The correct usage is:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option]
or
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option] store
or
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option] [version number]
or
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option] store [version number]
where [option] is: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm
where [version number] is either the full Windows 10 SDK version number or "8.1" to use the windows 8.1 SDK
:
The store parameter sets environment variables to support
store (rather than desktop) development.
:
For example:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_arm store
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 10.0.10240.0
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_arm store 10.0.10240.0
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 8.1
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 store 8.1
:
Please make sure either Visual Studio or C++ Build SKU is installed.
Also If you do like this:
CL "%1%2%3" /EHsc /link user32.lib Gdi32.lib Winmm.lib comctl32.lib *.obj /SUBSYSTEM:CONSOLE /MACHINE:x86
you have to del *.obj before; to avoid confusing linker with both 64 and 32 bit objects left over from prior compilations?
I have fixed this problem for myself as follows.
First of all, I followed the other answers for this question, only to conclude that all the project settings were correct.
Then I inspected the .vcxproj file with an editor and noticed that the < Link > properties for the two (Debug and Release) x64 configurations did not specify < TargetMachine >, while the Win32 configurations both contained < TargetMachine > MachineX86 < /TargetMachine >.
However, I had already verified, looking from Visual Studio at Properties > Configuration Properties > Linker > Advanced > Target Machine, that the x64 configurations said MachineX64 (/MACHINE:X64).
So, I edited the .vcxproj file to include < TargetMachine > MachineX64 < /TargetMachine > in the two x64 configs. Going back to the Visual Studio project properties dialog, I noticed that the MachineX64 (/MACHINE:X64) setting was there as before, except that now it showed in bold (apparently meaning that the value is not the default one).
I rebuilt, and it worked.

fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'AMD64'

I am using VS 2003 .Net on 32 bit XP OS. I have also installed "Microsoft Platform SDK" on my machine. Can I build vc++ application (binaries) targeted for 64 bit OS?
I am using following project options :
Name="VCLinkerTool"
AdditionalOptions="/machine:AMD64 bufferoverflowU.lib"
OutputFile="\bin\Release\MM64.dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=""C:\Program Files\Microsoft Platform SDK\Lib\AMD64""
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="\bin\Release\MM64.pdb"
GenerateMapFile="TRUE"
MapFileName="\bin\Release\MM64.map"
MapExports="TRUE"
MapLines="TRUE"
OptimizeReferences="2"
EnableCOMDATFolding="2"
ImportLibrary=".\Release/MM64.lib"
TargetMachine="0"/>
I am getting following error:
fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'AMD64'
Do I need to build project on 64 bit OS or I need to change project settings to resolve this error.
Please help me to resolve this issue.
I had the same problem today, here's how I solved it (in Visual Studio 2008):
Went to Project Properties -> Linker -> Command Line -> Additional Options and removed the /MACHINE:I386 from the linker additional options.
Hope it helps
Having the same problem in VS2008. My solution was to change the active solution platform located in Build -> Configuration Manager and creating a new solution platform using the x64 and copuing the settings from Win32. This allowed me to use the pre-build 32bit libraries in my 64 bit OS.
For 64-bit Windows users:
I had the same problem today, here's how I solved it (in Visual Studio 2008): I went to:
Project Properties -> Linker -> Command Line -> Additional Options
and added the /MACHINE:I364 from the linker additional options.
This worked fine for me.
I faced above error when I tried to build my custom library for ARM64 in Visual Studio 2017. And my target machine was already ARM64 as expected.
Apparently, problem was in ARM64 compiler which was not installed(though I could run build in ARM64). I installed it by running Visual Studio Installer Individual Components -> Visual C++ compiler and libraries for ARM64
Next I got error MSB8022: Compiling Desktop applications for the ARM platform is not supported.
It was resolved by adding
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
...
<PlatformToolset>v141</PlatformToolset>
<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>
</PropertyGroup>
into my project file.
After all of above I could succefully build my project in ARM64.
Hope it will be useful.
This error comes up because something in you build is being compiled in the wrong architecture (say as a x86 binary when everything else is x64). The linker panics and doesn't know what to do with it, so it breaks your build.
I can speak for your problem because the error message you quoted is incomplete. Usually it goes something like this:
SOME_KIND_OF_OBJECT.obj: fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'AMD64'
You look at the name of the obj file and you'll find the root of your problem there. Whatever obj is listed will have some kind source code analog with the same name. Have a look at it and see how it's being compiled. Usually all that stuff is automated in VS but sometimes there are special build steps that were added in by the developer. Inspect the custom, pre- and post- build events to see if a x86 tool is being used to assemble it. The property sheet in VS2010+ will be specific to the obj and the platform so you can inspect the library directories being used to verify that they are not 32 bit.

Resources