У меня есть файл CmakeLists.txt
cmake_minimum_required(VERSION 3.16.0)
project (MI)
file(GLOB_RECURSE HEADER_FILES include/*.h)
file(GLOB_RECURSE SOURCE_FILES source/*.cpp)
# Set the compiler standard to C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# find_package(Threads REQUIRED)
# find_package(TBB REQUIRED)
# endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /Zc:__cplusplus")
else(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -std=c++17")
endif(MSVC)
add_library (MI source/MI.EntryPoint.cpp)
target_include_directories (MI PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
add_executable (main ${SOURCE_FILES})
# if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# target_link_libraries(main PRIVATE Threads::Threads ${CMAKE_DL_LIBS} ${TBB_IMPORTED_TARGETS})
# endif()
target_link_libraries (main LINK_PUBLIC MI)
Когда я собираю проект на linux (ubuntu 18.04), получаю следующую ошибку:
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/bin/gcc - 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/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: /usr/bin/python3.6 (found version "3.6.9") found components: Interpreter
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/runner/work/MI/MI/build
[1/18] Building CXX object CMakeFiles/MI.dir/source/MI.EntryPoint.cpp.o
FAILED: CMakeFiles/MI.dir/source/MI.EntryPoint.cpp.o
/usr/local/bin/g++ -I/home/runner/work/MI/MI -Wall -Wextra -Werror -pedantic -std=c++17 -std=c++17 -MD -MT CMakeFiles/MI.dir/source/MI.EntryPoint.cpp.o -MF CMakeFiles/MI.dir/source/MI.EntryPoint.cpp.o.d -o CMakeFiles/MI.dir/source/MI.EntryPoint.cpp.o -c /home/runner/work/MI/MI/source/MI.EntryPoint.cpp
In file included from /usr/include/c++/9/pstl/parallel_backend.h:14,
from /usr/include/c++/9/pstl/algorithm_impl.h:25,
from /usr/include/c++/9/pstl/glue_execution_defs.h:52,
from /usr/include/c++/9/execution:32,
from /home/runner/work/MI/MI/source/../include/../include/MI.HexGenerator.h:11,
from /home/runner/work/MI/MI/source/../include/MI.EntryPoint.h:6,
from /home/runner/work/MI/MI/source/MI.EntryPoint.cpp:2:
/usr/include/c++/9/pstl/parallel_backend_tbb.h:19:10: fatal error: tbb/blocked_range.h: No such file or directory
19 | #include <tbb/blocked_range.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
[2/18] Building CXX object CMakeFiles/MI_test.dir/test/Common/MI.Check.cpp.o
[3/18] Building CXX object CMakeFiles/MI_test.dir/test/hello_test.cpp.o
ninja: build stopped: subcommand failed.
Error: Process completed with exit code 1.
Я пробовал добавить то, что у меня закомментировано, но тогда я получаю другую ошибку:
-- The C compiler identification is Clang 12.0.1
-- The CXX compiler identification is Clang 12.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/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/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: /usr/bin/python3.6 (found version "3.6.9") found components: Interpreter
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
CMake Error at CMakeLists.txt:35 (find_package):
By not providing "FindTBB.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "TBB", but
CMake did not find one.
Could not find a package configuration file provided by "TBB" with any of
the following names:
TBBConfig.cmake
tbb-config.cmake
Add the installation prefix of "TBB" to CMAKE_PREFIX_PATH or set "TBB_DIR"
to a directory containing one of the above files. If "TBB" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/runner/work/MI/MI/build/CMakeFiles/CMakeOutput.log".
See also "/home/runner/work/MI/MI/build/CMakeFiles/CMakeError.log".
Error: Process completed with exit code 1.
Если я правильно понимаю суть проблемы, то нужно добавить библиотеки Threads
и TBB
?
Как это можно сделать?