链接从命令行转换为Make的库
Linking libraries translating from command line to Make
我正在尝试运行英特尔数学内核库(mkl(。有一个工具(https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor)它打印必要的、依赖于环境的cmd命令,以便将其用于C++脚本编写。对我来说,上面写着:
使用此链接行:${MKLROOT}/lib/libmkl_intel_lp64.a${MKLROOT}/lib/libmkl_intel_thread.a${MKLOOT}/lib/libmgl_core.a-lomap5-lpthread-lm-ldl
编译器选项:-m64-I${MKLROOT}/include
我的目标是用CMake脚本来写这个。我哪里出了问题/我必须写些什么才能完成这项工作?
cmake_minimum_required(VERSION 3.15)
project(PSD_Projections)
set(CMAKE_CXX_STANDARD 14)
set(MKL_DIR /opt/intel/mkl)
# Part for the linker line
# This seems to be somewhat okay
# However I can't figure out what to do about the other linker line arguments
find_library(LIB1 mkl_intel_lp64 ${MKL_DIR}/lib)
find_library(LIB2 mkl_intel_thread ${MKL_DIR}/lib)
find_library(LIB3 mkl_core ${MKL_DIR}/lib)
link_libraries(${LIB1} ${LIB2} ${LIB3})
# Part for the compiler options.
# ${MKL_DIR}/include is found and exists
# I don't know what to do about the -m64
include_directories(${MKL_DIR}/include)
add_executable(PSD_Projections main.cpp)
顺序ILP64版本的示例:
target_include_directories(PSD_Projections PUBLIC "${MKL_DIR}/include")
target_compile_definitions(PSD_Projections PUBLIC MKL_ILP64)
target_link_directories(PSD_Projections PUBLIC "${MKL_DIR}/lib/intel64")
target_link_libraries(PSD_Projections PUBLIC mkl_intel_ilp64 mkl_sequential mkl_core m dl)
target_link_options(PSD_Projections PUBLIC "-Wl,--no-as-needed")
它可以很容易地根据您的需要进行调整。
如何设置C++标准版本和编译器选项的示例:
target_compile_features(PSD_Projections PUBLIC cxx_std_14)
target_compile_options(PSD_Projections PUBLIC -Wall -Wpedantic -Wextra -m64 -march=native)
相关文章:
- C/C++编译器通常会删除重复的库吗
- 如何将C++中的库和头与MinGW一起使用
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 构建一个由C和C++文件组成的库
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- 为重写std::exception的库生成swig接口时出错
- 我可以在 Arduino 的库文件夹之外安装库吗?
- 我希望定义两个具有相同代码的不同名称的库
- 运行命令 "rosbag play example.bag" 时出错。找不到与插件 rosbag/NoEncryptor 对应的库
- 更新后的Android Studio现在需要Clang,不再链接到GCC的库
- 包括没有完整路径的我的库
- 如何允许编译器查找通过 brew 安装的库
- 以现代 CMake 方式控制包含的库中的构建选项(测试等)
- 从 CMake 中的库目录加载共享库?
- Windows (COM) API 的行为不同,没有特定的库
- 如何使用我构建的库,而不会从源代码出错,但不为我自己的项目编译?
- 如何编译使用从不同编译器编译的库的应用程序?
- OS X: ld: 找不到 -lstdc++ 的库
- 链接从命令行转换为Make的库
- 在我的 CMake C++ 项目中依赖基于 make 的 C 库的最干净方法