我是新的cuda編程,我想建立我的程序,並有一個使用cuda的.cu功能。我參與了這個項目,這個項目非常龐大。項目的* .cpp文件中添加使用腳本files.cmakeCmake錯誤使用cuda_add_executable命令
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_check_build_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進行編譯?
PS:如果我做一個簡單的項目,做同樣的事情如上面的CMakeLists.txt運作良好,但我不明白爲什麼我不能.CU加入到這個龐大的項目 任何的幫助深表感謝
你是對的,我正在使用最新版本的Cmake,上面的新功能看起來也很酷;但通過改變它爲新的命令是行不通的!該程序運行良好,沒有.cu文件;因此,我不認爲問題來自Qt4。正如我之前所說的,使用同一版本的Cmake,一個簡單的程序運行良好。謝謝 – Ehsan
發佈的CMake日誌文件中的錯誤都與cuda無關。請注意,您需要使用CMAKE_CUDA_FLAGS而不是CUDA_NVCC_FLAGS以上述樣式傳遞CUDA標誌。 如果沒有來自控制檯的實際錯誤消息,我們無法真正幫助您。 –