admin管理员组

文章数量:1023282

I am working on a cross-platform game project. Having developed on Macintosh, I'm now working to get it to build on Windows as well. After cloning the repository on Windows, I went into the folder and did "Select a kit” from the CMake Tools extension and chose Visual Studio. Soon I realized I didn't like that choice, as it is picky about Macintosh line endings on files – a very bad arrangement when you're doing cross-platform work. So I went back and selected a different kit, using gcc which I installed with MSYS2.

Something isn't right. Here's the output of my CMake configure:

[main] Configuring project: Drawbox 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\g++.exe --no-warn-unused-cli -SC:/Users/ken/Desktop/Drawbox -Bc:/Users/ken/Desktop/Drawbox/build -G "Visual Studio 17 2022"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
[cmake] -- DRAWBOX=C:/Users/ken/Desktop/Drawbox/Library/SpaceCalc.cppC:/Users/ken/Desktop/Drawbox/Library/Color.cppC:/Users/ken/Desktop/Drawbox/Library/FinePoint.cppC:/Users/ken/Desktop/Drawbox/Library/DrawboxWindow.cppC:/Users/ken/Desktop/Drawbox/Library/DrErrMessages.cppC:/Users/ken/Desktop/Drawbox/Library/DrEventQ.cppC:/Users/ken/Desktop/Drawbox/Library/Image.cppC:/Users/ken/Desktop/Drawbox/Library/PVector.cppC:/Users/ken/Desktop/Drawbox/Library/Point.cppC:/Users/ken/Desktop/Drawbox/Library/Rect.cppC:/Users/ken/Desktop/Drawbox/Library/Timer.cppC:/Users/ken/Desktop/Drawbox/Library/Win/Drawbox.Win.cppC:/Users/ken/Desktop/Drawbox/Library/Win/Keyboard.Win.cpp
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.1s)
[cmake] -- Build files have been written to: C:/Users/ken/Desktop/Drawbox/build

Take a look at that command line: it chooses GCC as the compiler but ends with -G "Visual Studio 17 2022". This is a mess, and here's some of the mess that follows when I actually compile:

[build]   CheckerCheckerBoardBoard.cpp
[build] C:\Users\ken\Desktop\Drawbox\Tools\GraphicUtil.h(1,1): warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format [C:\Users\ken\Desktop\Drawbox\build\TestProgram.vcxproj]
[build]   (compiling source file '../Test/CheckerCheckerBoardBoard.cpp')
[build]   
[build] C:\Users\ken\Desktop\Drawbox\APClass\apmatrix.h(2,1): error C1070: mismatched #if/#endif pair in file 'C:\Users\ken\Desktop\Drawbox\APClass\apmatrix.h' [C:\Users\ken\Desktop\Drawbox\build\TestProgram.vcxproj]
[build]   (compiling source file '../Test/CheckerCheckerBoardBoard.cpp')

. . . Those sure look like warnings and errors from MSVC rather than gcc! So what's the best way to straighten this out? Is there some way to delete the information that was stored when I first chose Visual Studio, so that it will start from scratch as I choose GCC?

I am working on a cross-platform game project. Having developed on Macintosh, I'm now working to get it to build on Windows as well. After cloning the repository on Windows, I went into the folder and did "Select a kit” from the CMake Tools extension and chose Visual Studio. Soon I realized I didn't like that choice, as it is picky about Macintosh line endings on files – a very bad arrangement when you're doing cross-platform work. So I went back and selected a different kit, using gcc which I installed with MSYS2.

Something isn't right. Here's the output of my CMake configure:

[main] Configuring project: Drawbox 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\g++.exe --no-warn-unused-cli -SC:/Users/ken/Desktop/Drawbox -Bc:/Users/ken/Desktop/Drawbox/build -G "Visual Studio 17 2022"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
[cmake] -- DRAWBOX=C:/Users/ken/Desktop/Drawbox/Library/SpaceCalc.cppC:/Users/ken/Desktop/Drawbox/Library/Color.cppC:/Users/ken/Desktop/Drawbox/Library/FinePoint.cppC:/Users/ken/Desktop/Drawbox/Library/DrawboxWindow.cppC:/Users/ken/Desktop/Drawbox/Library/DrErrMessages.cppC:/Users/ken/Desktop/Drawbox/Library/DrEventQ.cppC:/Users/ken/Desktop/Drawbox/Library/Image.cppC:/Users/ken/Desktop/Drawbox/Library/PVector.cppC:/Users/ken/Desktop/Drawbox/Library/Point.cppC:/Users/ken/Desktop/Drawbox/Library/Rect.cppC:/Users/ken/Desktop/Drawbox/Library/Timer.cppC:/Users/ken/Desktop/Drawbox/Library/Win/Drawbox.Win.cppC:/Users/ken/Desktop/Drawbox/Library/Win/Keyboard.Win.cpp
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.1s)
[cmake] -- Build files have been written to: C:/Users/ken/Desktop/Drawbox/build

Take a look at that command line: it chooses GCC as the compiler but ends with -G "Visual Studio 17 2022". This is a mess, and here's some of the mess that follows when I actually compile:

[build]   CheckerCheckerBoardBoard.cpp
[build] C:\Users\ken\Desktop\Drawbox\Tools\GraphicUtil.h(1,1): warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format [C:\Users\ken\Desktop\Drawbox\build\TestProgram.vcxproj]
[build]   (compiling source file '../Test/CheckerCheckerBoardBoard.cpp')
[build]   
[build] C:\Users\ken\Desktop\Drawbox\APClass\apmatrix.h(2,1): error C1070: mismatched #if/#endif pair in file 'C:\Users\ken\Desktop\Drawbox\APClass\apmatrix.h' [C:\Users\ken\Desktop\Drawbox\build\TestProgram.vcxproj]
[build]   (compiling source file '../Test/CheckerCheckerBoardBoard.cpp')

. . . Those sure look like warnings and errors from MSVC rather than gcc! So what's the best way to straighten this out? Is there some way to delete the information that was stored when I first chose Visual Studio, so that it will start from scratch as I choose GCC?

Share Improve this question asked Nov 18, 2024 at 19:49 JoymakerJoymaker 1,4222 gold badges19 silver badges36 bronze badges 1
  • Looks like you selected the kit based on Visual Studio generator. With that generator it has no sense to select compilers: they will be ignored. You need to select a kit based on MinGW generator. – Tsyvarev Commented Nov 19, 2024 at 7:51
Add a comment  | 

1 Answer 1

Reset to default 0

Visual Studio is the Generator not the compiler (another option on windows platforms as far as generators go is Ninja). It seems to me that you explicitly set the compiler in your call to CMake to be gcc. I think with visual studio as the generator you will want to set it to Windows' c/c++ compiler cl.exe.

The better approach (in my opition) for cross-platform compilations/builds with cmake is to use CMakePresests. In that case you can define different presets and condition them on the operating system. For example your linux presets could set gcc and g++ as the compilers and your windows presets can set cl.exe as the compiler.

You can read about presets here cmake presets.

I am working on a cross-platform game project. Having developed on Macintosh, I'm now working to get it to build on Windows as well. After cloning the repository on Windows, I went into the folder and did "Select a kit” from the CMake Tools extension and chose Visual Studio. Soon I realized I didn't like that choice, as it is picky about Macintosh line endings on files – a very bad arrangement when you're doing cross-platform work. So I went back and selected a different kit, using gcc which I installed with MSYS2.

Something isn't right. Here's the output of my CMake configure:

[main] Configuring project: Drawbox 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\g++.exe --no-warn-unused-cli -SC:/Users/ken/Desktop/Drawbox -Bc:/Users/ken/Desktop/Drawbox/build -G "Visual Studio 17 2022"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
[cmake] -- DRAWBOX=C:/Users/ken/Desktop/Drawbox/Library/SpaceCalc.cppC:/Users/ken/Desktop/Drawbox/Library/Color.cppC:/Users/ken/Desktop/Drawbox/Library/FinePoint.cppC:/Users/ken/Desktop/Drawbox/Library/DrawboxWindow.cppC:/Users/ken/Desktop/Drawbox/Library/DrErrMessages.cppC:/Users/ken/Desktop/Drawbox/Library/DrEventQ.cppC:/Users/ken/Desktop/Drawbox/Library/Image.cppC:/Users/ken/Desktop/Drawbox/Library/PVector.cppC:/Users/ken/Desktop/Drawbox/Library/Point.cppC:/Users/ken/Desktop/Drawbox/Library/Rect.cppC:/Users/ken/Desktop/Drawbox/Library/Timer.cppC:/Users/ken/Desktop/Drawbox/Library/Win/Drawbox.Win.cppC:/Users/ken/Desktop/Drawbox/Library/Win/Keyboard.Win.cpp
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.1s)
[cmake] -- Build files have been written to: C:/Users/ken/Desktop/Drawbox/build

Take a look at that command line: it chooses GCC as the compiler but ends with -G "Visual Studio 17 2022". This is a mess, and here's some of the mess that follows when I actually compile:

[build]   CheckerCheckerBoardBoard.cpp
[build] C:\Users\ken\Desktop\Drawbox\Tools\GraphicUtil.h(1,1): warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format [C:\Users\ken\Desktop\Drawbox\build\TestProgram.vcxproj]
[build]   (compiling source file '../Test/CheckerCheckerBoardBoard.cpp')
[build]   
[build] C:\Users\ken\Desktop\Drawbox\APClass\apmatrix.h(2,1): error C1070: mismatched #if/#endif pair in file 'C:\Users\ken\Desktop\Drawbox\APClass\apmatrix.h' [C:\Users\ken\Desktop\Drawbox\build\TestProgram.vcxproj]
[build]   (compiling source file '../Test/CheckerCheckerBoardBoard.cpp')

. . . Those sure look like warnings and errors from MSVC rather than gcc! So what's the best way to straighten this out? Is there some way to delete the information that was stored when I first chose Visual Studio, so that it will start from scratch as I choose GCC?

I am working on a cross-platform game project. Having developed on Macintosh, I'm now working to get it to build on Windows as well. After cloning the repository on Windows, I went into the folder and did "Select a kit” from the CMake Tools extension and chose Visual Studio. Soon I realized I didn't like that choice, as it is picky about Macintosh line endings on files – a very bad arrangement when you're doing cross-platform work. So I went back and selected a different kit, using gcc which I installed with MSYS2.

Something isn't right. Here's the output of my CMake configure:

[main] Configuring project: Drawbox 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\g++.exe --no-warn-unused-cli -SC:/Users/ken/Desktop/Drawbox -Bc:/Users/ken/Desktop/Drawbox/build -G "Visual Studio 17 2022"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
[cmake] -- DRAWBOX=C:/Users/ken/Desktop/Drawbox/Library/SpaceCalc.cppC:/Users/ken/Desktop/Drawbox/Library/Color.cppC:/Users/ken/Desktop/Drawbox/Library/FinePoint.cppC:/Users/ken/Desktop/Drawbox/Library/DrawboxWindow.cppC:/Users/ken/Desktop/Drawbox/Library/DrErrMessages.cppC:/Users/ken/Desktop/Drawbox/Library/DrEventQ.cppC:/Users/ken/Desktop/Drawbox/Library/Image.cppC:/Users/ken/Desktop/Drawbox/Library/PVector.cppC:/Users/ken/Desktop/Drawbox/Library/Point.cppC:/Users/ken/Desktop/Drawbox/Library/Rect.cppC:/Users/ken/Desktop/Drawbox/Library/Timer.cppC:/Users/ken/Desktop/Drawbox/Library/Win/Drawbox.Win.cppC:/Users/ken/Desktop/Drawbox/Library/Win/Keyboard.Win.cpp
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.1s)
[cmake] -- Build files have been written to: C:/Users/ken/Desktop/Drawbox/build

Take a look at that command line: it chooses GCC as the compiler but ends with -G "Visual Studio 17 2022". This is a mess, and here's some of the mess that follows when I actually compile:

[build]   CheckerCheckerBoardBoard.cpp
[build] C:\Users\ken\Desktop\Drawbox\Tools\GraphicUtil.h(1,1): warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format [C:\Users\ken\Desktop\Drawbox\build\TestProgram.vcxproj]
[build]   (compiling source file '../Test/CheckerCheckerBoardBoard.cpp')
[build]   
[build] C:\Users\ken\Desktop\Drawbox\APClass\apmatrix.h(2,1): error C1070: mismatched #if/#endif pair in file 'C:\Users\ken\Desktop\Drawbox\APClass\apmatrix.h' [C:\Users\ken\Desktop\Drawbox\build\TestProgram.vcxproj]
[build]   (compiling source file '../Test/CheckerCheckerBoardBoard.cpp')

. . . Those sure look like warnings and errors from MSVC rather than gcc! So what's the best way to straighten this out? Is there some way to delete the information that was stored when I first chose Visual Studio, so that it will start from scratch as I choose GCC?

Share Improve this question asked Nov 18, 2024 at 19:49 JoymakerJoymaker 1,4222 gold badges19 silver badges36 bronze badges 1
  • Looks like you selected the kit based on Visual Studio generator. With that generator it has no sense to select compilers: they will be ignored. You need to select a kit based on MinGW generator. – Tsyvarev Commented Nov 19, 2024 at 7:51
Add a comment  | 

1 Answer 1

Reset to default 0

Visual Studio is the Generator not the compiler (another option on windows platforms as far as generators go is Ninja). It seems to me that you explicitly set the compiler in your call to CMake to be gcc. I think with visual studio as the generator you will want to set it to Windows' c/c++ compiler cl.exe.

The better approach (in my opition) for cross-platform compilations/builds with cmake is to use CMakePresests. In that case you can define different presets and condition them on the operating system. For example your linux presets could set gcc and g++ as the compilers and your windows presets can set cl.exe as the compiler.

You can read about presets here cmake presets.

本文标签: visual studio codeVSCode CMake g and MSVC mixed upStack Overflow