CMAKE同時編譯C++和CUDA文件


1. 首先是運行環境

  •  Ubuntu 16.04
  •  G++ 5.4.0
  •  CUDA 8.0

2. 文件結構

cv@cv:~/myproject$ tree src
src/
|-- CMakeLists.txt
|-- main.cc
`-- base
    |-- CMakeLists.txt
    |-- mat.h
    |-- match_test.cc
    |-- match_test.h
    |-- match_test_cuda.cu
    `-- match_test_cuda.h

3. 編譯過程中遇到的問題及解決方案

問題1:編譯c++項目時有如下錯誤

問題描述

/usr/lib/gcc/x86_64-linux-gnu/5/include/mwaitxintrin.h(42): error: identifier "__builtin_ia32_mwaitx" is undefined

解決方案

  1.  目前比較好的解決方法是在編譯的時候增加 _MWAITXINTRIN_H_INCLUDED 宏。
  2.  如果是使用 cmake,只需在 src/CMakeLists.txt 中增加如下語句
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_MWAITXINTRIN_H_INCLUDED")

問題2:Not support for ISO C++ 2011 standard

問題描述

error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental,

and must be enabled with the -std=c++11 or -std=gnu++11 compiler op

解決方案

src/CMakeLists.txt 中添加編譯選項

set(CMAKE_NVCC_FLAGS "CMAKE_NVCC_FLAGS -std=c++11")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM