0
votes

I have an application consisting of many dll and exe projects. I'm porting to a 64-bit version and virtually everything works fine. However, I have one exe project that won't build correctly in the 64-bit configuration. The strange thing is that it won't build from the IDE build command. If I open a 64-bit VS command window and build with msbuild, it does build successfully.

I've looked at some of the other similar questions and answers that generally refer to an extra (or missing) windows.h include but it's hard to determine if this is the same thing. I've tried different combinations of includes, but I don't see a clear problem.

I can build the project in the VS IDE as a 32-bit exe I can not build the project in the VS IDE as a 64-bit exe I can build the project in a 64-bit command window as a 64-bit exe

I've got _WIN64 and _AMD64 defined as preprocessor definitions.

If I enable the compiler option to show includes, I see this:

1>  Note: including file: c:\dev\projects\myapp\myproject.root\myproject\stdafx.h
1>  Note: including file:  c:\dev\projects\myapp\myproject.root\myproject\targetver.h
1>  Note: including file:   C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\SDKDDKVer.h
1>  Note: including file:  c:\dev\projects\myapp\myproject.root\myproject\resource.h
1>  Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlbase.h
1>  Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atldef.h
1>  Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlrc.h
1>  Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\errno.h
1>  Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
1>  Note: including file:      C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sal.h
1>  Note: including file:       c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(27): error C2371: 'size_t' : redefinition; different basic types
1>          predefined C++ types (compiler internal)(19) : see declaration of 'size_t'
1>  Note: including file:      C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vadefs.h
1>  Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\malloc.h
1>  Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
1>  Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdlib.h
1>  Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
1>  Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\limits.h
1>  Note: including file:      C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
1>  Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdbg.h
1>  Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
1>  Note: including file:   C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h
1>  Note: including file:    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\windows.h
1>  Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\excpt.h
1>  Note: including file:      C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
1>  Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdarg.h
1>  Note: including file:     C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\windef.h
1>  Note: including file:      C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h
1>  Note: including file:       C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ctype.h
1>  Note: including file:        C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
1>  Note: including file:       C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\specstrings.h
1>  Note: including file:        c:\program files (x86)\microsoft sdks\windows\v7.0a\include\sal_supp.h
1>  Note: including file:        c:\program files (x86)\microsoft sdks\windows\v7.0a\include\specstrings_supp.h
1>  Note: including file:        C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\specstrings_strict.h
1>  Note: including file:         C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\specstrings_undef.h
1>  Note: including file:        C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\driverspecs.h
1>  Note: including file:         c:\program files (x86)\microsoft sdks\windows\v7.0a\include\sdv_driverspecs.h
1>  Note: including file:       C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\kernelspecs.h
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(135): fatal error C1189: #error :  "No Target Architecture"

Any suggestions?

1
There is no need to define _WIN64 or _AMD64 you just need to set project platform to x64 and linker target machine to machine64 in project settings. - user7860670
Interesting. I removed those defines and now everything compiles correctly but I get a linker error: "fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'". I've got the 'x64' as the platform and the linker settings are set to machine type X64. - Ken
Maybe you have different settings for one translation unit or something? For precompiled header .cpp for example? - user7860670
I've been checking that myself. It doesn't look to be the case. I think the problem is that somehow the architecture type just isn't defined. So when I try to compile through the IDE and it uses the 32-bit compiler, it can only build the 32-bit version because (I assume) it defaults to 32-bit unless otherwise defined. And likewise, when building with msbuild in the 64-bit VS command prompt and all of the env variables are set to 64-bit, that works because it defaults to a 64-bit build and there's nothing in the includes that tell it otherwise. - Ken

1 Answers

0
votes

I think I've got the answer. I compared my project settings to a new, empty project that I created. The VC++ Directories entry for Executable Directories was different than mine.

The default directories started with this: $(VCInstallDir)bin\x86_amd64;

My existing project did not have that. I added it to my project for the 64-bit platform debug and release configurations, and I can build the 64-bit version now. And I can still build the 32-bit version as well.

I'm assuming that directory is where the 64-bit compiler and linker reside. If that's right, the error "No target architecture" seems like a strange error message to give for that condition.