BullyWiiPlaza
BullyWiiPlaza

Reputation: 19223

"No Target Architecture" compilation error in Visual Studio using CMake

I'm trying to compile my C++ CMake project in Visual Studio. However, I'm getting the following error message:

#error:  "No Target Architecture"   C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CMakeLists.txt   C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winnt.h  154

I checked my code and I'm never including winnt.h but I'm including windows.h so this rules out the solution of never including winnt.h.

This is the winnt.h code snippet where it throws the error:

//
// TODO: WOWXX - Unblock ARM. Make all alignment checks DWORD for now.
//

#define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
#elif !defined(RC_INVOKED)
#error "No Target Architecture"
#endif

I've previously successfully compiled this project using MinGW and WSL (Windows Subsystem for Linux) outside of Visual Studio. How do I tell Visual Studio that my architecture is 64-bit and amd64 (?). What is necessary in addition to make it compile? The run configuration is set to x64-Debug. Including stdafx.h is not possible since the header file is not found. I'm also using Boost but that is resolved properly by adding the following line to my CMakeLists.txt:

set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")

Upvotes: 3

Views: 9777

Answers (3)

fdk1342
fdk1342

Reputation: 3564

It is not specified if the error happens when the project is being configured or when the project has been configured and you are trying to build.

It could be an issue with your Visual Studio installation as it seems like you are not using cmake at the command line but using the cmake built into Visual Studio.

In both cases cmake will run to verify that a valid program can be built.

In Visual Studio create a new CMake project and it will create a generic c++ project with a CMakeLists.txt file. When you build this project it will run through the compiler detection phase, project configuration, and build. On my system this defaults for x86-Debug switch this to x64-Debug and it will go through the process again for x64 architecture.

Personally I think that the bundled CMake interface is very confusing and I don't use it. It is also using an older CMake and Ninja tools.

If this all works then it is something else that is going wrong and you need to include the full error message. The full error message will show the chain of include files and may pinpoint if you are using the wrong windows header file.

Upvotes: 0

Silmathoron
Silmathoron

Reputation: 2001

I think this should be fixed by -DCMAKE_GENERATOR_PLATFORM=x64

Upvotes: 2

BullyWiiPlaza
BullyWiiPlaza

Reputation: 19223

Since the error message mentioned a file of mine (e.g. file_operations.h) I decided to define the architecture inside it using the following macro:

#define _AMD64_ 1

This fixed the problem but I believe that a "better" solution exists by configuring the CMakeLists.txt or Visual Studio.

Upvotes: 3

Related Questions