c++cmakepybind11cmake-gui

I've been trying to make shared c++ libraries for python using cmake and pybind11 but i get errors i dont know how to fix


Let's start with CMake. Everytime i try to create the shared libraries,either through the command prompt or the cmake app, i get the same error:

The C compiler identification is unknown
The CXX compiler identification is unknown
Detecting C compiler ABI info
Detecting C compiler ABI info - failed
Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "C:/msys64/mingw64/bin/gcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: 'C:/Users/Exspiravit/Desktop/Sudoku/build/CMakeFiles/CMakeScratch/TryCompile-d79xak'
    
    Run Build Command(s): "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/amd64/MSBuild.exe" cmTC_d902b.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:n
    MSBuild version 17.10.4+10fbfbf2e for .NET Framework

    Build started 16/8/2024 11:01:50 ΞΌΞΌ.

    

    Project "C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\cmTC_d902b.vcxproj" on node 1 (default targets).

    PrepareForBuild:

      Creating directory "cmTC_d902b.dir\Debug\".

    C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(513,5): warning MSB8003: The WindowsSDKDir property is not defined. Some build tools may not be found. [C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\cmTC_d902b.vcxproj]

      Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.

      Creating directory "C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\Debug\".

      Creating directory "cmTC_d902b.dir\Debug\cmTC_d902b.tlog\".

    InitializeBuildStatus:

      Creating "cmTC_d902b.dir\Debug\cmTC_d902b.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.

      Touching "cmTC_d902b.dir\Debug\cmTC_d902b.tlog\unsuccessfulbuild".

    ClCompile:

      C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\CL.exe /c /W1 /WX- /diagnostics:column /D _MBCS /D "CMAKE_INTDIR=\"Debug\"" /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_d902b.dir\Debug\\" /Fd"cmTC_d902b.dir\Debug\vc143.pdb" /external:W1 /Gd /TC /errorReport:queue "C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\testCCompiler.c"

      Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33812 for x64

      Copyright (C) Microsoft Corporation.  All rights reserved.

      cl /c /W1 /WX- /diagnostics:column /D _MBCS /D "CMAKE_INTDIR=\"Debug\"" /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_d902b.dir\Debug\\" /Fd"cmTC_d902b.dir\Debug\vc143.pdb" /external:W1 /Gd /TC /errorReport:queue "C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\testCCompiler.c"

      testCCompiler.c

    Link:

      C:\msys64\mingw64\bin\ld.exe /ERRORREPORT:QUEUE /OUT:"C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\Debug\cmTC_d902b.exe" /INCREMENTAL /ILK:"cmTC_d902b.dir\Debug\cmTC_d902b.ilk" /NOLOGO /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:"C:/Users/Exspiravit/Desktop/Sudoku/build/CMakeFiles/CMakeScratch/TryCompile-d79xak/Debug/cmTC_d902b.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/Users/Exspiravit/Desktop/Sudoku/build/CMakeFiles/CMakeScratch/TryCompile-d79xak/Debug/cmTC_d902b.lib" /MACHINE:X64 cmTC_d902b.dir\Debug\testCCompiler.obj

      C:\msys64\mingw64\bin\ld.exe: cannot find /ERRORREPORT:QUEUE: No such file or directory

      C:\msys64\mingw64\bin\ld.exe: cannot find Β β– /: No such file or directory

    C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(1151,5): error MSB6006: "C:\msys64\mingw64\bin\ld.exe" exited with code 1. [C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\cmTC_d902b.vcxproj]

    Done Building Project "C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\cmTC_d902b.vcxproj" (default targets) -- FAILED.

    

    Build FAILED.

    

    "C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\cmTC_d902b.vcxproj" (default target) (1) ->

    (PrepareForBuild target) -> 

      C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(513,5): warning MSB8003: The WindowsSDKDir property is not defined. Some build tools may not be found. [C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\cmTC_d902b.vcxproj]

    

    

    "C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\cmTC_d902b.vcxproj" (default target) (1) ->

    (Link target) -> 

      C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(1151,5): error MSB6006: "C:\msys64\mingw64\bin\ld.exe" exited with code 1. [C:\Users\Exspiravit\Desktop\Sudoku\build\CMakeFiles\CMakeScratch\TryCompile-d79xak\cmTC_d902b.vcxproj]

    

        1 Warning(s)

        1 Error(s)

    

    Time Elapsed 00:00:00.98

    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:10 (project)

Configuring incomplete, errors occurred!

Also here is the CMakeLists.txt i use now:

cmake_minimum_required(VERSION 3.30)

set(CMAKE_C_COMPILER "C:/msys64/mingw64/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/msys64/mingw64/bin/g++.exe")
set(CMAKE_LINKER "C:/msys64/mingw64/bin/ld.exe")



project(SudokuProject)


set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)


include_directories(${CMAKE_SOURCE_DIR}/include)


file(GLOB GEN_SOURCES "src/gen.cpp")
file(GLOB CHECK_SOURCES "src/check.cpp")
file(GLOB LOGGER_SOURCES "src/logger.cpp")
file(GLOB WRAPPER_SOURCES "src/wrapper.cpp")


add_library(gen SHARED ${GEN_SOURCES})
add_library(check SHARED ${CHECK_SOURCES})
add_library(logger SHARED ${LOGGER_SOURCES})


add_library(wrapper MODULE ${WRAPPER_SOURCES})


target_include_directories(wrapper PRIVATE ${CMAKE_SOURCE_DIR}/include)
find_package(Python3 REQUIRED COMPONENTS Development)
target_include_directories(wrapper PRIVATE ${Python3_INCLUDE_DIRS})
target_link_libraries(wrapper PRIVATE ${Python3_LIBRARIES})


target_include_directories(gen PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_include_directories(check PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_include_directories(logger PRIVATE ${CMAKE_SOURCE_DIR}/include)


target_link_libraries(gen PRIVATE logger)
target_link_libraries(check PRIVATE logger)


set_target_properties(gen PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_target_properties(check PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_target_properties(logger PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_target_properties(wrapper PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

Now let's talk about pybind11. For some reason i get an error on the #include <pybind11/pybind11.h> saying cannot open source file Python.h

Regarding CMake, i've originally installed it from the website and after i made a CMakeLists.txt i tried to make the libraries using the Windows CMD and then i get the error but i thought it had something to do with CMakeLists.txt because it was my first time using cmake and i dont know how it works, i thought i had done something wrong with the the text file. Then i tried to find a way to fix the CMakeLists.txt but then i thought that it wouldn't show me that error and specifically the starting part of the error that the compilers identification is unknown but the exact line where the problem is happening so i tried to look that up. After that i decided to uninstall it and install it using msys64 (since this is the way i installed C/C++ compilers) and of course the problem consisted, i checked %PATH% and i didnt find a problem there, i tried the cmake app this time, i press generate and same problem, i uninstalled it because after some searching i read someone say that installing it from mingw and not from the original website it creates problems like that and i tried again both with the app and command prompt, same, then i tried to specify the compilers using the app, same problem.


Now about pybind11, besides #include <pybind11/pybind11.h> i also use #include <pybind11/stl.h> and both of them had the same error. First time i installed it using pip install but after a bit of trial and error i thought i would install it using mingw64 and the error for the second header was fixed but after that i haven't figured out a way to fix the problem


Now i've just hit a wall and i can't continue with the project, probably due to my ignorance because it's my first time using both of them and i want figure out what is the problem, also the IDE i use is VSC, don't know if it has anything to do with the errors but at this point it could be anything.


Solution

  • The logs says that CMake could not detect a working compiler. If you want to use Microsoft Visual Studio Compiler, start a terminal window Visual Studio that has preconfigured environmental variables: Tools -> Command Line -> Developer Command Prompt.

    Also, ensure that you have Windows SDK installed by Visual Studio Installer - the logs says The WindowsSDKDir property is not defined. Some build tools may not be found. It might be related to the environmental variables not set (see point above).