Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
C++ 使用cuda_add_可执行命令时发生Cmake错误_C++_Cmake_Cuda_Qt Creator - Fatal编程技术网

C++ 使用cuda_add_可执行命令时发生Cmake错误

C++ 使用cuda_add_可执行命令时发生Cmake错误,c++,cmake,cuda,qt-creator,C++,Cmake,Cuda,Qt Creator,我是cuda编程新手,我想构建我的程序,有一个.cu函数正在使用cuda。我加入了这个项目,这个项目是巨大的。使用script files.cmake将项目的*.cpp文件添加到项目中 SUBDIRS( src/ThirdParty/Matrice ) set(SRC_CPP_FILES Operation.cpp Operator.cpp ThirdParty/mt97.cpp Mesh.cpp ... ) ... 本项目的CmakeList.txt写为:

我是cuda编程新手,我想构建我的程序,有一个.cu函数正在使用cuda。我加入了这个项目,这个项目是巨大的。使用script files.cmake将项目的*.cpp文件添加到项目中

SUBDIRS(
src/ThirdParty/Matrice
)

set(SRC_CPP_FILES 
  Operation.cpp 
  Operator.cpp 
  ThirdParty/mt97.cpp 
  Mesh.cpp 
 ...
)
...
本项目的CmakeList.txt写为:

    project(PILOT_plugin)


#set(CMAKE_MODULE_PATH
#  ${${MY_PROJECT_NAME}_SOURCE_DIR}/CMake
#  ${CMAKE_MODULE_PATH}
#  )

MACRO_CREATE_MITK_CTK_PLUGIN(
  EXPORT_DIRECTIVE PLANNING_EXPORTS
  EXPORTED_INCLUDE_SUFFIXES src
  #MODULE_DEPENDS QmitkExt Qmitk
  MODULE_DEPENDS MitkQtWidgetsExt MitkQtWidgets MitkMapperExt MitkSceneSerialization

)

# Check the architecture and set CMAKE_LIBRARY_ARCHITECTURE accordingly
#if(UNIX)
#  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
#    set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
#  endif()
#endif()

function(echo_all_cmake_variable_values)
  message(STATUS "")
  get_cmake_property(vs VARIABLES)
  foreach(v ${vs})
    message(STATUS "${v}='${${v}}'")
  endforeach(v)
  message(STATUS "")
endfunction()

#echo_all_cmake_variable_values()

SET(QT_USE_QTSQL TRUE)
find_package(Boost COMPONENTS serialization filesystem system REQUIRED)
find_package(PythonLibs 2.7 REQUIRED)
set(VTK_CMAKE_DIR ${PILOT_SUPERBUILD_BINARY_DIR}/MITK-superbuild/VTK-src/CMake)
add_subdirectory(${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/vtkbioeng ${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/vtkbioeng/Build)
add_subdirectory(${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/ompl)

include_directories(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIR} ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/include /usr/include/libxml2  ${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/vtkbioeng ${PILOT_plugin_SOURCE_DIR}/src/ThirdParty/ompl/src)

add_dependencies(${PROJECT_NAME} ompl vtkBioeng)

#find_path(CGOGN_LIB_DIR cgogn ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release)
#message(STATUS ${CGOGN_LIB_DIR})

#link_directories(${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release)
#set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release)
#set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${CGOGN_LIB_DIR})
#list(APPEND ALL_LIBRARY_DIRS ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release)


if(EXISTS ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release/libcgogn.a)
        TARGET_LINK_LIBRARIES(${PROJECT_NAME} gsl mat ${Boost_LIBRARIES} PythonQt ${PYTHON_LIBRARIES} ompl vtkBioeng  ${PILOT_plugin_SOURCE_DIR}/src/CGoGN/lib/Release/libcgogn.a z)
else()
        TARGET_LINK_LIBRARIES(${PROJECT_NAME} gsl mat ${Boost_LIBRARIES} PythonQt ${PYTHON_LIBRARIES} ompl vtkBioeng)
endif()


#TARGET_LINK_LIBRARIES(${PROJECT_NAME} mat ${Boost_LIBRARIES} PythonQt ${PYTHON_LIBRARIES} cgogn z)

#echo_all_cmake_variable_values()

add_definitions(-DBOOST_NO_CXX11_RVALUE_REFERENCES)
据我所知,我应该将下面的命令添加到.cmake文件或cmakeLists.txt

find_package(CUDA REQUIRED)
add_definitions(-D_FORCE_INLINES)
set (CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_21 -std=c++11)

cuda_add_executable(PILOT_plugin
    testcuda.cu)
“PILOT_plugin”是项目的名称,.cu文件是我的cuda文件。但我得到了“[cmake\U check\U build\U system]错误1”。在CmakeError.log文件中,我什么都不懂

这是cmakeError.log

Determining if the Q_WS_WIN exist failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec2072448143/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec2072448143.dir/build.make CMakeFiles/cmTryCompileExec2072448143.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o
/usr/bin/c++    -I/usr/include/qt4    -o CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: In function ‘int main(int, char**)’:
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:8:19: error: ‘Q_WS_WIN’ was not declared in this scope
   return ((int*)(&Q_WS_WIN))[argc];
                   ^
CMakeFiles/cmTryCompileExec2072448143.dir/build.make:57: recipe for target 'CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o' failed
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[4]: *** [CMakeFiles/cmTryCompileExec2072448143.dir/CheckSymbolExists.cxx.o] Error 1
Makefile:118: recipe for target 'cmTryCompileExec2072448143/fast' failed
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[3]: *** [cmTryCompileExec2072448143/fast] Error 2

File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <QtCore/qglobal.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef Q_WS_WIN
  return ((int*)(&Q_WS_WIN))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the Q_WS_QWS exist failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec3895328539/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec3895328539.dir/build.make CMakeFiles/cmTryCompileExec3895328539.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o
/usr/bin/c++    -I/usr/include/qt4    -o CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: In function ‘int main(int, char**)’:
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:8:19: error: ‘Q_WS_QWS’ was not declared in this scope
   return ((int*)(&Q_WS_QWS))[argc];
                   ^
CMakeFiles/cmTryCompileExec3895328539.dir/build.make:57: recipe for target 'CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o' failed
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[4]: *** [CMakeFiles/cmTryCompileExec3895328539.dir/CheckSymbolExists.cxx.o] Error 1
Makefile:118: recipe for target 'cmTryCompileExec3895328539/fast' failed
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[3]: *** [cmTryCompileExec3895328539/fast] Error 2

File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <QtCore/qglobal.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef Q_WS_QWS
  return ((int*)(&Q_WS_QWS))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the Q_WS_MAC exist failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec816771383/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec816771383.dir/build.make CMakeFiles/cmTryCompileExec816771383.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o
/usr/bin/c++    -I/usr/include/qt4    -o CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx: In function ‘int main(int, char**)’:
/home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:8:19: error: ‘Q_WS_MAC’ was not declared in this scope
   return ((int*)(&Q_WS_MAC))[argc];
                   ^
CMakeFiles/cmTryCompileExec816771383.dir/build.make:57: recipe for target 'CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o' failed
make[4]: *** [CMakeFiles/cmTryCompileExec816771383.dir/CheckSymbolExists.cxx.o] Error 1
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
Makefile:118: recipe for target 'cmTryCompileExec816771383/fast' failed
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[3]: *** [cmTryCompileExec816771383/fast] Error 2

File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.cxx:
/* */
#include <QtCore/qglobal.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef Q_WS_MAC
  return ((int*)(&Q_WS_MAC))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the pthread_create exist failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec3000733177/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec3000733177.dir/build.make CMakeFiles/cmTryCompileExec3000733177.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o
/usr/bin/cc   -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all     -o CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o   -c /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTryCompileExec3000733177
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec3000733177.dir/link.txt --verbose=1
/usr/bin/cc     -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all      CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o  -o cmTryCompileExec3000733177 -rdynamic 
CMakeFiles/cmTryCompileExec3000733177.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x29): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec3000733177.dir/build.make:88: recipe for target 'cmTryCompileExec3000733177' failed
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[4]: *** [cmTryCompileExec3000733177] Error 1
Makefile:118: recipe for target 'cmTryCompileExec3000733177/fast' failed
make[3]: *** [cmTryCompileExec3000733177/fast] Error 2
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'

File /home/.../CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/.../CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec2524936657/fast"
make[3]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTryCompileExec2524936657.dir/build.make CMakeFiles/cmTryCompileExec2524936657.dir/build
make[4]: Entering directory '/home/.../CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/.../CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec2524936657.dir/CheckFunctionExists.c.o
/usr/bin/cc   -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all  -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTryCompileExec2524936657.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.0/Modules/CheckFunctionExists.c
Linking C executable cmTryCompileExec2524936657
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec2524936657.dir/link.txt --verbose=1
/usr/bin/cc     -Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -Wno-error=unknown-pragmas -Wno-error=strict-overflow -Wno-unused-local-typedefs -Wno-array-bounds -fdiagnostics-show-option -fstack-protector-all  -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTryCompileExec2524936657.dir/CheckFunctionExists.c.o  -o cmTryCompileExec2524936657 -rdynamic -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec2524936657.dir/build.make:88: recipe for target 'cmTryCompileExec2524936657' failed
make[4]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[4]: *** [cmTryCompileExec2524936657] Error 1
Makefile:118: recipe for target 'cmTryCompileExec2524936657/fast' failed
make[3]: Leaving directory '/home/.../CMakeFiles/CMakeTmp'
make[3]: *** [cmTryCompileExec2524936657/fast] Error 2
为什么我不能将.cu文件添加到项目中?主项目使用gcc进行编译。有没有其他方法可以将.cu文件添加到主项目并使用nvcc进行编译

附言:如果我做了一个简单的项目,并在CmakeLists.txt中做了与上面相同的事情,效果会很好,但我不明白为什么我不能在这个庞大的项目中添加.cu
非常感谢您提供的任何帮助

如果您使用的是最新版本的cmake,则不应使用cuda_add_可执行扩展,而应使用内置功能来支持cuda请参阅

因此,您需要做的是如下修改您的CmakeList:

projectPILOT_插件语言C CXX CUDA

您可以使用普通的add_可执行文件/add_库宏


但是我不认为这是你的问题:我认为你安装的Qt4设置不正确。

你是对的,我使用的是最新版本的Cmake,上面的新功能看起来也很酷;但是,将其更改为新命令无效!。程序运行良好,没有.cu文件;因此,我不认为问题来自Qt4。正如我之前所说,使用同一版本的Cmake,一个简单的程序运行良好。感谢发布的CMake日志文件中有一个错误与cuda有关。请注意,您需要使用CMAKE_CUDA_标志而不是上述样式的CUDA_NVCC_标志来传递CUDA标志。如果没有来自控制台的实际错误消息,我们就无法为您提供更多帮助。