I am trying to run cmake in our school project, the CMakeList.txt looks as follows:
cmake_minimum_required(VERSION 3.0)
project(nagata)
FIND_PACKAGE( OpenMP )
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
set(CMAKE_C_COMPILER clang-omp CACHE STRING "C compiler" FORCE)
set(CMAKE_CXX_COMPILER clang-omp++ CACHE STRING "C++ compiler" FORCE)
FIND_PACKAGE( pybind11 REQUIRED )
FIND_PACKAGE(PythonInterp 3)
FIND_PACKAGE(PythonLibs 3)
IF( PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND PYBIND11_FOUND )
INCLUDE_DIRECTORIES(
${PYTHON_INCLUDE_DIRS}
${PYBIND11_INCLUDE_DIRS}
)
ENDIF()
INCLUDE_DIRECTORIES("/usr/include/python3.7m")
add_library(pynagata SHARED pythonlib.cpp)
# The library must not have any prefix and should be located in
# a subfolder that includes the package name. The setup will be
# more complicated otherwise.
SET_TARGET_PROPERTIES( pynagata
PROPERTIES
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pynagata"
)
add_executable(nagata main.cpp)
install(TARGETS nagata RUNTIME DESTINATION bin)
When I run cmake ..
in my build
directory I get this output which looks almost OK:
-- The C compiler identification is Clang 11.0.0
-- The CXX compiler identification is Clang 11.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -fopenmp=libomp (found version "5.0")
-- Found OpenMP_CXX: -fopenmp=libomp (found version "5.0")
-- Found OpenMP: TRUE (found version "5.0")
OPENMP FOUND
-- Found PythonInterp: /usr/local/bin/python3.8 (found version "3.8.6")
-- Found PythonLibs: /usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib
-- Performing Test HAS_CPP14_FLAG
-- Performing Test HAS_CPP14_FLAG - Success
-- Found PythonInterp: /usr/local/bin/python3.8 (found suitable version "3.8.6", minimum required is "3")
-- Could NOT find PythonLibs (missing: PYTHON_INCLUDE_DIRS) (Required is at least version "3")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/.../build
Except the line -- Could NOT find PythonLibs (missing: PYTHON_INCLUDE_DIRS) (Required is at least version "3")
which seems odd to me as few lines before it literally finds it: -- Found PythonLibs: /usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib
. I tried to set an env variable PYTHON_INCLUDE_DIRS="/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib"
which is the exact same path as from the line above. Still, I get this error .
How can I make it find the PythonLibs
? I really don't understand why the env variable doesn't work. I will also be happy to provide more info - I just don't know what.
I am using:
PS: When I try to run make
afterwards I get fatal error: 'string' file not found #include <string>
which is maybe somehow connected to this issue...
It looks like I got the flags' names wrong. Calling the cmake with the following flags solved the problem for me:
cmake -DPYTHON_LIBRARY=$(python3-config --prefix)/lib/libpython3.8.dylib -DPYTHON_INCLUDE_DIR=$(python3-config --prefix)/include/python3.8 ..
It finds the PythonLibs successfully now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.