Part I - This original post bounced off CMake mail list due to 40kb limit. I am was attempting to build the nbody source in the CUDA sdk to both learn CMake and CUDA build settings (this is a documentation of that experience - heck maybe this will help someone else). After moving the sources into my tree and creating the necessary CMakeList.txt file containing:
find( cuda ) MESSAGE( STATUS "Nbody - project is being generated" ) SET( NBODY_SRC src/bodysystemcpu.cpp src/bodysystemcuda.cpp src/bodysystemcuda.cu src/nbody.cpp src/nbody_gold.cpp src/nbody_kernel.cu src/render_particles.cpp ) MESSAGE( "NBODY_SRC = " ${NBODY_SRC} ) CUDA_ADD_EXECUTABLE( nbody ${NBODY_SRC} ) INSTALL_TARGETS( ${INSTALL_BINDIR} nbody) 1>------ Build started: Project: nbody, Configuration: Debug x64 ------ 1>Building NVCC (Device) object cpp_source/nbody-new/Debug/ nbody_generated_nbody_kernel.cu.obj 1>nbody_kernel.cu 1>nbody_kernel.cu 1>tmpxft_00001ac4_00000000-3_nbody_kernel.cudafe1.gpu 1>tmpxft_00001ac4_00000000-8_nbody_kernel.cudafe2.gpu 1>tmpxft_00001ac4_00000000-3_nbody_kernel.cudafe1.cpp 1>tmpxft_00001ac4_00000000-13_nbody_kernel.ii 1>Building NVCC (Device) object cpp_source/nbody-new/Debug/nbody_generated_bodysystemcuda.cu.obj 1>nbody_kernel.cu 1>nbody_kernel.cu 1>tmpxft_00001b5c_00000000-3_nbody_kernel.cudafe1.gpu 1>tmpxft_00001b5c_00000000-8_nbody_kernel.cudafe2.gpu 1>tmpxft_00001b5c_00000000-3_nbody_kernel.cudafe1.cpp 1>tmpxft_00001b5c_00000000-13_nbody_kernel.ii 1>Compiling... 1>render_particles.cpp 1>..\..\..\..\source\cpp\app\testing\cudaTests\nbody\src\render_particles.cpp(31) : fatal error C1083: Cannot open include file: 'GL/glew.h': No such file or directory 1>nbody_gold.cpp 1>nbody.cpp 1>..\..\..\..\source\cpp\app\testing\cudaTests\nbody\src\nbody.cpp(30) : fatal error C1083: Cannot open include file: 'GL/glew.h': No such file or directory 1>bodysystemcuda.cpp 1>..\..\..\..\source\cpp\app\testing\cudaTests\nbody\src\bodysystemcuda.cpp(32) : fatal error C1083: Cannot open include file: 'cutil_inline.h': No such file or directory 1>bodysystemcpu.cpp 1>..\..\..\..\source\cpp\app\testing\cudaTests\nbody\src\bodysystemcpu.cpp(37) : fatal error C1083: Cannot open include file: 'cutil_inline.h': No such file or directory 1>Generating Code... 1>Build log was saved at "file://c:\projects\NIH2009\source\branches\brian\build\dvip4-Win64\cpp_source\nbody-new\nbody.dir\Debug\BuildLog.htm" 1>nbody - 4 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ========== Ok and that's all fine and good except for the "Cannot open include file: 'GL/gluwl.h': No such file or directory. So I compare above to the build of nbody supplied by NVIDIA Compiling with CUDA Build Rule... "C:\CUDA\bin\nvcc.exe" -arch sm_10 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin" -Xcompiler "/EHsc /W3 /nologo /Od /Zi /MTd " -I"C:\CUDA\include" -I"./" -I"../../common/inc" -maxrregcount=32 --compile -o "x64\Debug\bodysystemcuda.cu.obj" "c:\NVIDIA Corporation\NVIDIA CUDA SDK\projects\nbody\bodysystemcuda.cu" bodysystemcuda.cu tmpxft_000011a0_00000000-3_bodysystemcuda.cudafe1.gpu tmpxft_000011a0_00000000-8_bodysystemcuda.cudafe2.gpu tmpxft_000011a0_00000000-3_bodysystemcuda.cudafe1.cpp tmpxft_000011a0_00000000-13_bodysystemcuda.ii Note: including lib: glut32.lib Compiling... cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release bodysystemcpu.cpp bodysystemcuda.cpp nbody.cpp Note: including lib: glut32.lib nbody_gold.cpp render_particles.cpp Note: including lib: glut32.lib param.cpp paramgl.cpp Note: including lib: glut32.lib Generating Code... Linking... Embedding manifest... Performing Post-Build Event... Note the ../../common/inc (yep - sdk include directory) So then I look at my CMakeCache.txt and find: //Semi-colon delimit multiple arguments. CUDA_NVCC_FLAGS:STRING= //Semi-colon delimit multiple arguments. CUDA_NVCC_FLAGS_DEBUG:STRING= //Semi-colon delimit multiple arguments. CUDA_NVCC_FLAGS_MINSIZEREL:STRING= //Semi-colon delimit multiple arguments. CUDA_NVCC_FLAGS_RELEASE:STRING= //Semi-colon delimit multiple arguments. CUDA_NVCC_FLAGS_RELWITHDEBINFO:STRING= ... ... //Path to a file. CUDA_SDK_ROOT_DIR:PATH=C:/NVIDIA Corporation/NVIDIA CUDA SDK //Path to a file. CUDA_TOOLKIT_INCLUDE:PATH=C:/CUDA/include I ask my self two questions: 1) Why is CUDA_NVCC_FLAGS not set to some default build setting that would just work out of the box? - I get the answer to this question when I turn on CUDA_VERBOSE_BUILD_MODE - It is being set under the hood. 2) There is a CUDA_TOOLKIT_INCLUDE, but no CUDA_SDK_INCLUDE (or _LIB)... why? (this would prevent ${CUDA_SDK_ROOT_DIR}/common/inc - see below) Maybe these guys could answer question 2: James Bigler, NVIDIA Corp (nvidia.com - jbigler) Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html A request here would be to seperate FindCUDA into : FindCUDA and FindNVIDIACUDASDK and add include and lib dirs environment vars. I also turn on CUDA_VERBOSE_BUILD as I like spam (mmm spam) and seeing my build parameters. I then get: blah... blah...blah (working stuff) then: 1>C:/CUDA/bin/nvcc.exe C:/projects/NIH2009/source/branches/brian/source/cpp/app/testing/cudaTests/nbody/src/ nbody_kernel.cu -m64 -ccbin "c:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin" -Xcompiler ,\"/DWIN32\",\"/D_WINDOWS\",\"/W3\",\"/Zm1000\",\"/EHsc\",\"/GR\",\"/D_DEBUG\",\"/MDd\",\"/Zi\",\"/Ob0\",\"/Od\",\"/RTC1\" -DNVCC -c -o C:/projects/NIH2009/source/branches/brian/build/dvip4-Win64/cpp_source/nbody-new/Debug/nbody_generated_bodysystemcuda.cu.obj -IC:/CUDA/include -IC:/CUDA/include 1>nbody_kernel.cu 1>tmpxft_00000fac_00000000-3_nbody_kernel.cudafe1.gpu 1>tmpxft_00000fac_00000000-8_nbody_kernel.cudafe2.gpu 1>tmpxft_00000fac_00000000-3_nbody_kernel.cudafe1.cpp 1>tmpxft_00000fac_00000000-13_nbody_kernel.ii 1>Generated C:/projects/NIH2009/source/branches/brian/build/dvip4-Win64/cpp_source/nbody-new/Debug/nbody_generated_bodysystemcuda.cu.obj successfully. 1>Compiling... 1>render_particles.cpp 1>..\..\..\..\source\cpp\app\testing\cudaTests\nbody\src\render_particles.cpp(31) : fatal error C1083: Cannot open include file: 'GL/glew.h': No such file or directory 1>nbody_gold.cpp 1>nbody.cpp 1>..\..\..\..\source\cpp\app\testing\cudaTests\nbody\src\nbody.cpp(30) : fatal error C1083: Cannot open include file: 'GL/glew.h': No such file or directory 1>bodysystemcuda.cpp 1>..\..\..\..\source\cpp\app\testing\cudaTests\nbody\src\bodysystemcuda.cpp(32) : fatal error C1083: Cannot open include file: 'cutil_inline.h': No such file or directory 1>bodysystemcpu.cpp 1>..\..\..\..\source\cpp\app\testing\cudaTests\nbody\src\bodysystemcpu.cpp(37) : fatal error C1083: Cannot open include file: 'cutil_inline.h': No such file or directory 1>Generating Code... 1>Build log was saved at "file://c:\projects\NIH2009\source\branches\brian\build\dvip4-Win64\cpp_source\nbody-new\nbody.dir\Debug\BuildLog.htm" 1>nbody - 4 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ========== The I notice that CMAKE is doublely uber certain to add C:/CUDA/include to the include path (NOTE: -IC:/CUDA/include -IC:/CUDA/include above) , but not C:\NVIDIA Corporation\NVIDIA CUDA SDK\common\inc. It looks as though a cpp file cannot find glew.h and cutil_inline.h in the NVIDIA CUDA SDK directory So I then add to my CMakeLists.txt file (I think in a vain attempt to make it work): INCLUDE_DIRECTORIES( ${CUDA_SDK_ROOT_DIR}/common/inc ) "C:/Program Files (x86)/CMake 2.8/bin/cmake.exe" -E remove C:/projects/NIH2009/source/branches/brian/build/dvip4-Win64/cpp_source/nbody-new/CMakeFiles/nbody_generated_nbody_kernel.cu.obj.depend.tmp C:/projects/NIH2009/source/branches/brian/build/dvip4-Win64/cpp_source/nbody-new/CMakeFiles/nbody_generated_nbody_kernel.cu.obj.NVCC-depend -- Generating C:/projects/NIH2009/source/branches/brian/build/dvip4-Win64/cpp_source/nbody-new/Debug/nbody_generated_bodysystemcuda.cu.obj C:/CUDA/bin/nvcc.exe C:/projects/NIH2009/source/branches/brian/source/cpp/app/testing/cudaTests/nbody/src/ nbody_kernel.cu -m64 -ccbin "c:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin" -Xcompiler ,\"/DWIN32\",\"/D_WINDOWS\",\"/W3\",\"/Zm1000\",\"/EHsc\",\"/GR\",\"/D_DEBUG\",\"/MDd\",\"/Zi\",\"/Ob0\",\"/Od\",\"/RTC1\" -DNVCC -c -o C:/projects/NIH2009/source/branches/brian/build/dvip4-Win64/cpp_source/nbody-new/Debug/nbody_generated_bodysystemcuda.cu.obj -IC:/CUDA/include "-IC:/NVIDIA Corporation/NVIDIA CUDA SDK/common/inc" -IC:/CUDA/include nbody_kernel.cutmpxft_0000167c_00000000-3_nbody_kernel.cudafe1.gpu tmpxft_0000167c_00000000-8_nbody_kernel.cudafe2.gpu tmpxft_0000167c_00000000-3_nbody_kernel.cudafe1.cpp tmpxft_0000167c_00000000-13_nbody_kernel.ii Generated C:/projects/NIH2009/source/branches/brian/build/dvip4-Win64/cpp_source/nbody-new/Debug/nbody_generated_bodysystemcuda.cu.obj successfully. Compiling... render_particles.cpp Note: including lib: glut32.lib nbody.cpp Note: including lib: glut32.lib bodysystemcuda.cpp bodysystemcpu.cpp Generating Code... Compiling manifest to resources... Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0 Copyright (C) Microsoft Corporation. All rights reserved. Linking... LINK : fatal error LNK1104: cannot open file 'glut32.lib' And I would sure hope so as this is a 64bit system even though both glut32.lib and glut64.lib can be found in (either way the original NVIDIA nbody compiles for x64 and still links to glut32.lib): C:\NVIDIA Corporation\NVIDIA CUDA SDK\common\lib So I add: link_directories( ${CUDA_SDK_ROOT_DIR}/common/lib ) And I get: Linking... bodysystemcuda.obj : error LNK2019: unresolved external symbol allocateNBodyArrays referenced in function "protected: virtual void __cdecl BodySystemCUDA::_initialize(int)" (?_initial...@bodysystemcuda@@mea...@z) bodysystemcuda.obj : error LNK2019: unresolved external symbol registerGLBufferObject referenced in function "protected: virtual void __cdecl BodySystemCUDA::_initialize(int)" (?_initial...@bodysystemcuda @@mea...@z) bodysystemcuda.obj : error LNK2001: unresolved external symbol __imp___glewGetBufferParameteriv bodysystemcuda.obj : error LNK2001: unresolved external symbol __imp___glewBufferData ... There is lots more of this wherever this came from ... render_particles.obj : error LNK2001: unresolved external symbol __imp___glewAttachShader render_particles.obj : error LNK2001: unresolved external symbol __imp___glewCreateProgram render_particles.obj : error LNK2001: unresolved external symbol __imp___glewCompileShader render_particles.obj : error LNK2001: unresolved external symbol __imp___glewShaderSource render_particles.obj : error LNK2001: unresolved external symbol __imp___glewCreateShader C:\projects\NIH2009\source\branches\brian\build\Windows-6.1\ouput\bin\Debug\nbody.exe : fatal error LNK1120: 60 unresolved externals So then I add: add_library( cudart STATIC IMPORTED ) add_library( cutil64D STATIC IMPORTED ) add_library( glew64 STATIC IMPORTED ) add_library( glut64 STATIC IMPORTED ) #add_library( paramgl64 STATIC IMPORTED ) <- An attempt to build param and paramgl into a lib # Gotta love the syntax below... Is there anything less verbose than this in CMAKE? set_property(TARGET cudart PROPERTY IMPORTED_LOCATION ${CUDA_TOOLKIT_ROOT_DIR}/lib/cudart.lib ) set_property(TARGET cutil64D PROPERTY IMPORTED_LOCATION ${CUDA_SDK_ROOT_DIR}/common/lib/cutil64D.lib ) set_property(TARGET glew64 PROPERTY IMPORTED_LOCATION ${CUDA_SDK_ROOT_DIR}/common/lib/glew64.lib ) set_property(TARGET glut64 PROPERTY IMPORTED_LOCATION ${CUDA_SDK_ROOT_DIR}/common/lib/glut64.lib ) #set_property(TARGET paramgl64 PROPERTY IMPORTED_LOCATION ${CUDA_SDK_ROOT_DIR}/common/lib/paramgl64.lib ) #CUDA_ADD_LIBRARY( paramgl64 ${CUDA_SDK_ROOT_DIR}/common/src/param.cpp ${CUDA_SDK_ROOT_DIR}/common/src/paramgl.cpp STATIC ) #SET(NBODY_LIBS cudart cutil64D glew64 glut64 paramgl64 ) SET(NBODY_LIBS cudart cutil64D glew64 glut64 ) CUDA_ADD_EXECUTABLE( nbody ${NBODY_SRC} ) target_link_libraries (nbody ${NBODY_LIBS} ) And I get among other things: 1>nbody.obj : error LNK2019: unresolved external symbol "public: __cdecl ParamListGL::ParamListGL(char const *)" (??0ParamListGL@@q...@pebd@Z) referenced in function "void __cdecl initParameters(void)" (?initParameters@ @YAXXZ) 1>nbody.obj : error LNK2019: unresolved external symbol "public: void __cdecl ParamListGL::Render(int,int,bool)" (?ren...@paramlistgl@@qeaaxh...@z) referenced in function "void __cdecl display(void)" (?display@@YAXXZ) 1>nbody.obj : error LNK2019: unresolved external symbol "public: bool __cdecl ParamListGL::Mouse(int,int,int,int)" (?mo...@paramlistgl @@qeaa_nh...@z) referenced in function "void __cdecl mouse(int,int,int,int)" (?mouse@@yaxh...@z) 1>nbody.obj : error LNK2019: unresolved external symbol "public: bool __cdecl ParamListGL::Motion(int,int)" (?mot...@paramlistgl@@qeaa_...@z) referenced in function "void __cdecl motion(int,int)" (?motion@@ya...@z) 1>nbody.obj : error LNK2019: unresolved external symbol "public: void __cdecl ParamListGL::Special(int,int,int)" (?spec...@paramlistgl@@qeaax...@z) referenced in function "void __cdecl special(int,int,int)" (?special@ @yax...@z) So I change: SET( NBODY_SRC src/bodysystem.h src/render_particles.h src/bodysystemcpu.h src/bodysystemcuda.h src/bodysystemcuda.cu src/nbody_kernel.cu src/bodysystemcpu.cpp src/bodysystemcuda.cpp src/nbody.cpp src/nbody_gold.cpp src/render_particles.cpp ${CUDA_SDK_ROOT_DIR}/common/src/param.cpp ${CUDA_SDK_ROOT_DIR}/common/src/paramgl.cpp ) To add param and pramgl And I get: 1>------ Build started: Project: nbody, Configuration: Debug x64 ------ 1>Linking... 1>bodysystemcuda.obj : error LNK2019: unresolved external symbol allocateNBodyArrays referenced in function "protected: virtual void __cdecl BodySystemCUDA::_initialize(int)" (?_initial...@bodysystemcuda@@mea...@z) 1>bodysystemcuda.obj : error LNK2019: unresolved external symbol registerGLBufferObject referenced in function "protected: virtual void __cdecl BodySystemCUDA::_initialize(int)" (?_initial...@bodysystemcuda @@mea...@z) 1>bodysystemcuda.obj : error LNK2019: unresolved external symbol unregisterGLBufferObject referenced in function "protected: virtual void __cdecl BodySystemCUDA::_finalize(void)" (?_final...@bodysystemcuda @@MEAAXXZ) 1>bodysystemcuda.obj : error LNK2019: unresolved external symbol deleteNBodyArrays referenced in function "protected: virtual void __cdecl BodySystemCUDA::_finalize(void)" (?_final...@bodysystemcuda@@MEAAXXZ) 1>bodysystemcuda.obj : error LNK2019: unresolved external symbol setDeviceSoftening referenced in function "public: virtual void __cdecl BodySystemCUDA::setSoftening(float)" (?setsoften...@bodysystemcuda@@uea...@z ) 1>bodysystemcuda.obj : error LNK2019: unresolved external symbol integrateNbodySystem referenced in function "public: virtual void __cdecl BodySystemCUDA::update(float)" (?upd...@bodysystemcuda@@uea...@z) 1>bodysystemcuda.obj : error LNK2019: unresolved external symbol copyArrayFromDevice referenced in function "public: virtual float * __cdecl BodySystemCUDA::getArray(enum BodySystem::BodyArray)" (?getar...@bodysystemcuda@@ueaapeamw4bodyar...@bodysystem@@@Z) 1>bodysystemcuda.obj : error LNK2019: unresolved external symbol copyArrayToDevice referenced in function "public: virtual void __cdecl BodySystemCUDA::setArray(enum BodySystem::BodyArray,float const *)" (?setar...@bodysystemcuda@@ueaaxw4bodyar...@bodysystem@@p...@z) 1>bodysystemcuda.obj : error LNK2019: unresolved external symbol threadSync referenced in function "public: virtual void __cdecl BodySystemCUDA::synchronizeThreads(void)const " (?synchronizethre...@bodysystemcuda@@UEBAXXZ) 1>C:\projects\NIH2009\source\branches\brian\build\Windows-6.1\ouput\bin\Debug\nbody.exe : fatal error LNK1120: 9 unresolved externals 1>Build log was saved at "file://c:\projects\NIH2009\source\branches\brian\build\dvip4-Win64\cpp_source\nbody-new\nbody.dir\Debug\BuildLog.htm" 1>nbody - 10 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ========== ... to be continued -- Brian J. Davis
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake