Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 苹果_Macos_Makefile_Cmake_Openmp - Fatal编程技术网

Macos 苹果

Macos 苹果,macos,makefile,cmake,openmp,Macos,Makefile,Cmake,Openmp,我目前正试图使用cmake在Mac上编译一个项目,但遇到了麻烦。我已经看过这篇文章了,但仍然遇到一些麻烦。我的CMakeLists.txt如下所示 project(tpch_framework) # enable c++11 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAK

我目前正试图使用cmake在Mac上编译一个项目,但遇到了麻烦。我已经看过这篇文章了,但仍然遇到一些麻烦。我的CMakeLists.txt如下所示

project(tpch_framework)

# enable c++11
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_BUILD_TYPE "Release")

set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/10.0.0_3/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/10.0.0_3/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/10.0.0_3/lib")
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/10.0.0_3/include")

OPTION (USE_OpenMP "Use OpenMP to enamble <omp.h>" ON)

# Find OpenMP
if(APPLE AND USE_OpenMP)
    if(CMAKE_C_COMPILER_ID MATCHES "Clang")
        set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
        set(OpenMP_C_LIB_NAMES "omp")
        set(OpenMP_omp_LIBRARY omp)
    endif()
    if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
        set(OpenMP_CXX_LIB_NAMES "omp")
        set(OpenMP_omp_LIBRARY omp)
    endif()
endif()

if(USE_OpenMP)
  find_package(OpenMP REQUIRED)
endif(USE_OpenMP)

if (OPENMP_FOUND)
    include_directories("${OPENMP_INCLUDES}")
    link_directories("${OPENMP_LIBRARIES}")
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} -libomp")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -libomp")
    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif(OPENMP_FOUND)

# Configure required Boost libraries
set(BOOST_ROOT "" CACHE PATH "Boost build root (useful on Windows)")
option(Boost_USE_STATIC_LIBS
       "Search for static boost libs" OFF)
option(Boost_USE_MULTITHREADED
       "Search for multithreaded boost libs" ON)
option(Boost_USE_STATIC_RUNTIME
       "Search for boost libs linked against static C++ runtime" OFF)
find_package(Boost 1.47.0 REQUIRED filesystem system)

# ensure that dependant libraries not explicitly specified here
# are found by the linker:
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Boost_LIBRARIES})
 
#Bring the headers into the project
include_directories(include)
  
FILE(GLOB_RECURSE INC_ALL "include/*.hpp")

#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "src/*.cpp")
 
add_library(tpch_framework ${SOURCES})
add_executable(framework main.cpp ${INC_ALL})
target_link_libraries(framework tpch_framework)
#target_link_libraries(framework stdc++fs)
target_link_libraries(framework ${LIBS})
然而,当我使用make时,我得到以下错误

/Users/myname/Desktop/Uni/MHD/tpch_framework_challenge_mhd_2020/src/task4.cpp:48:5: error: use of undeclared identifier 'omp_set_num_threads'
    omp_set_num_threads(4);
我猜是这样的,因为我得到了这个警告:
clang-10:warning:-libomp:'linker'输入未使用[-Wunused命令行参数]

有人有什么想法吗?我已经被这个问题困扰太久了,如果有任何建议,我将不胜感激

亲切问候,,
Moritz

如果您可以使用最新版本的CMake,此版本应该可以正常工作

# NOTE: Every top-level CMakeLists.txt must start with these two lines
cmake_minimum_required(VERSION 3.16)
project(tpch_framework)

## Enable C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

## Find dependencies

# OpenMP
find_package(OpenMP REQUIRED)

# Boost
set(BOOST_ROOT "" CACHE PATH "Boost build root (useful on Windows)")
option(Boost_USE_STATIC_LIBS
       "Search for static boost libs" OFF)
option(Boost_USE_MULTITHREADED
       "Search for multithreaded boost libs" ON)
option(Boost_USE_STATIC_RUNTIME
       "Search for boost libs linked against static C++ runtime" OFF)
find_package(Boost 1.47.0 REQUIRED COMPONENTS filesystem system)

## Add main project targets

# NOTE: This is completely wrong and will break incremental builds after
#       doing a "git pull" or similar. You should never glob for source
#       files, but instead list them explicitly.
file(GLOB SOURCES "src/*.cpp")
 
add_library(tpch_framework ${SOURCES})
target_include_directories(tpch_framework PUBLIC BUILD_INTERFACE:include)
target_link_libraries(tpch_framework
                      PUBLIC
                      OpenMP::OpenMP_CXX
                      Boost::boost 
                      Boost::filesystem
                      Boost::system)

add_executable(framework main.cpp)
target_link_libraries(framework PRIVATE tpch_framework)

在so和教程中有这么多糟糕的CMake建议,真是太可惜了。

如果你能使用最新版本的CMake,这个版本应该可以工作

# NOTE: Every top-level CMakeLists.txt must start with these two lines
cmake_minimum_required(VERSION 3.16)
project(tpch_framework)

## Enable C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

## Find dependencies

# OpenMP
find_package(OpenMP REQUIRED)

# Boost
set(BOOST_ROOT "" CACHE PATH "Boost build root (useful on Windows)")
option(Boost_USE_STATIC_LIBS
       "Search for static boost libs" OFF)
option(Boost_USE_MULTITHREADED
       "Search for multithreaded boost libs" ON)
option(Boost_USE_STATIC_RUNTIME
       "Search for boost libs linked against static C++ runtime" OFF)
find_package(Boost 1.47.0 REQUIRED COMPONENTS filesystem system)

## Add main project targets

# NOTE: This is completely wrong and will break incremental builds after
#       doing a "git pull" or similar. You should never glob for source
#       files, but instead list them explicitly.
file(GLOB SOURCES "src/*.cpp")
 
add_library(tpch_framework ${SOURCES})
target_include_directories(tpch_framework PUBLIC BUILD_INTERFACE:include)
target_link_libraries(tpch_framework
                      PUBLIC
                      OpenMP::OpenMP_CXX
                      Boost::boost 
                      Boost::filesystem
                      Boost::system)

add_executable(framework main.cpp)
target_link_libraries(framework PRIVATE tpch_framework)

在so和教程中有这么多糟糕的CMake建议,真是太可惜了。

您使用的是哪种版本的CMake?从您的列表文件来看,您似乎正在使用2.x,现在已经有将近十年的历史了<代码>cmake 3.17.0版我只是没有太多使用cmake的经验,我已经放弃了我所得到的,并根据我在SO上的发现做了一些调整。你正在使用哪一版本的cmake?从您的列表文件来看,您似乎正在使用2.x,现在已经有将近十年的历史了<代码>cmake 3.17.0版我只是没有太多使用cmake的经验,我已经放弃了我所得到的,并根据我在SO上的发现做了一些调整。嘿,Alex。感谢您的帮助,但遗憾的是,它没有起作用,我得到了以下输出:``CMakeLists.txt处的CMake错误:39(add_可执行文件):目标“framework”链接到目标“OpenMP::OpenMP”,但找不到目标。可能导入的目标缺少find_package()调用,或者缺少别名目标?CMakeLists.txt:30(添加库)处的CMake错误:目标“tpch_框架”链接到目标“OpenMP::OpenMP”,但未找到目标。可能导入的目标缺少find_package()调用,或者缺少别名目标```我相信,关键是问题末尾提到的警告
clang-10:warning:-libomp:“linker”input unused[-Wunused command line argument]
,因为小型测试程序需要编译此标志。有什么想法吗?哦。应该是OpenMP::OpenMP_CXXThanks,但是现在我得到了与以前相同的错误
错误:使用未声明的标识符“omp_set_num_threads”omp_set_num_threads(4)如何显式添加标志
-Xpreprocessor-lomp
?删除由CMake创建的所有文件就成功了。代码现在可以编译了,我在代码中看到了加速。非常感谢你的帮助,真的很感激。嘿,亚历克斯。感谢您的帮助,但遗憾的是,它没有起作用,我得到了以下输出:``CMakeLists.txt处的CMake错误:39(add_可执行文件):目标“framework”链接到目标“OpenMP::OpenMP”,但找不到目标。可能导入的目标缺少find_package()调用,或者缺少别名目标?CMakeLists.txt:30(添加库)处的CMake错误:目标“tpch_框架”链接到目标“OpenMP::OpenMP”,但未找到目标。可能导入的目标缺少find_package()调用,或者缺少别名目标```我相信,关键是问题末尾提到的警告
clang-10:warning:-libomp:“linker”input unused[-Wunused command line argument]
,因为小型测试程序需要编译此标志。有什么想法吗?哦。应该是OpenMP::OpenMP_CXXThanks,但是现在我得到了与以前相同的错误
错误:使用未声明的标识符“omp_set_num_threads”omp_set_num_threads(4)如何显式添加标志
-Xpreprocessor-lomp
?删除由CMake创建的所有文件就成功了。代码现在可以编译了,我在代码中看到了加速。非常感谢你的帮助,非常感谢。