<br>Part I - This original post bounced off CMake mail list due to 40kb limit.<br><br>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:<br>
<br>find( cuda )<br><br>MESSAGE( STATUS "Nbody - project is being generated" )<br><br>SET( NBODY_SRC<br> src/bodysystemcpu.cpp<br> src/bodysystemcuda.cpp<br> src/<a href="http://bodysystemcuda.cu">bodysystemcuda.cu</a><br>
src/nbody.cpp<br> src/nbody_gold.cpp<br> src/<a href="http://nbody_kernel.cu">nbody_kernel.cu</a><br> src/render_particles.cpp<br>)<br><br><br>MESSAGE( "NBODY_SRC = " ${NBODY_SRC} )<br><br>CUDA_ADD_EXECUTABLE( nbody ${NBODY_SRC} )<br>
<br>INSTALL_TARGETS( ${INSTALL_BINDIR} nbody)<br><br><br><br>1>------ Build started: Project: nbody, Configuration: Debug x64 ------<br>1>Building NVCC (Device) object cpp_source/nbody-new/Debug/<br>nbody_generated_nbody_kernel.cu.obj<br>
1><a href="http://nbody_kernel.cu">nbody_kernel.cu</a><br>1><a href="http://nbody_kernel.cu">nbody_kernel.cu</a><br>1>tmpxft_00001ac4_00000000-3_nbody_kernel.cudafe1.gpu<br>1>tmpxft_00001ac4_00000000-8_nbody_kernel.cudafe2.gpu<br>
1>tmpxft_00001ac4_00000000-3_nbody_kernel.cudafe1.cpp<br>1>tmpxft_00001ac4_00000000-13_nbody_kernel.ii<br>1>Building NVCC (Device) object cpp_source/nbody-new/Debug/nbody_generated_bodysystemcuda.cu.obj<br>1><a href="http://nbody_kernel.cu">nbody_kernel.cu</a><br>
1><a href="http://nbody_kernel.cu">nbody_kernel.cu</a><br>1>tmpxft_00001b5c_00000000-3_nbody_kernel.cudafe1.gpu<br>1>tmpxft_00001b5c_00000000-8_nbody_kernel.cudafe2.gpu<br>1>tmpxft_00001b5c_00000000-3_nbody_kernel.cudafe1.cpp<br>
1>tmpxft_00001b5c_00000000-13_nbody_kernel.ii<br>1>Compiling...<br>1>render_particles.cpp<br>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<br>
1>nbody_gold.cpp<br>1>nbody.cpp<br>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<br>1>bodysystemcuda.cpp<br>
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<br>1>bodysystemcpu.cpp<br>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<br>
1>Generating Code...<br>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"<br>1>nbody - 4 error(s), 0 warning(s)<br>
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========<br><br><br>Ok and that's all fine and good except for the "Cannot open include file: 'GL/gluwl.h': No such file or directory.<br>
<br>So I compare above to the build of nbody supplied by NVIDIA<br><br>Compiling with CUDA Build Rule...<br>"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\<a href="http://bodysystemcuda.cu">bodysystemcuda.cu</a>"<br>
<a href="http://bodysystemcuda.cu">bodysystemcuda.cu</a><br>tmpxft_000011a0_00000000-3_bodysystemcuda.cudafe1.gpu<br>tmpxft_000011a0_00000000-8_bodysystemcuda.cudafe2.gpu<br>tmpxft_000011a0_00000000-3_bodysystemcuda.cudafe1.cpp<br>
tmpxft_000011a0_00000000-13_bodysystemcuda.ii<br>Note: including lib: glut32.lib<br>Compiling...<br>cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release<br>bodysystemcpu.cpp<br>
bodysystemcuda.cpp<br>nbody.cpp<br>Note: including lib: glut32.lib<br>nbody_gold.cpp<br>render_particles.cpp<br>Note: including lib: glut32.lib<br>param.cpp<br>paramgl.cpp<br>Note: including lib: glut32.lib<br>Generating Code...<br>
Linking...<br>Embedding manifest...<br>Performing Post-Build Event...<br><br><br>Note the ../../common/inc (yep - sdk include directory)<br><br>So then I look at my CMakeCache.txt and find:<br><br><br>//Semi-colon delimit multiple arguments.<br>
CUDA_NVCC_FLAGS:STRING=<br><br>//Semi-colon delimit multiple arguments.<br>CUDA_NVCC_FLAGS_DEBUG:STRING=<br><br>//Semi-colon delimit multiple arguments.<br>CUDA_NVCC_FLAGS_MINSIZEREL:STRING=<br><br>//Semi-colon delimit multiple arguments.<br>
CUDA_NVCC_FLAGS_RELEASE:STRING=<br><br>//Semi-colon delimit multiple arguments.<br>CUDA_NVCC_FLAGS_RELWITHDEBINFO:STRING=<br>...<br>...<br><br>//Path to a file.<br>CUDA_SDK_ROOT_DIR:PATH=C:/NVIDIA Corporation/NVIDIA CUDA SDK<br>
<br>//Path to a file.<br>CUDA_TOOLKIT_INCLUDE:PATH=C:/CUDA/include<br><br><br>I ask my self two questions:<br><br>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.<br>
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)<br><br>Maybe these guys could answer question 2:<br><br>James Bigler, NVIDIA Corp (<a href="http://nvidia.com">nvidia.com</a> - jbigler)<br>
Abe Stephens, SCI Institute -- <a href="http://www.sci.utah.edu/~abe/FindCuda.html">http://www.sci.utah.edu/~abe/FindCuda.html</a><br><br><br>A request here would be to seperate FindCUDA into :<br><br>FindCUDA<br><br>and<br>
<br>FindNVIDIACUDASDK<br><br>and add include and lib dirs environment vars.<br><br><br>I also turn on CUDA_VERBOSE_BUILD as I like spam (mmm spam) and seeing my build parameters.<br><br> <br>I then get:<br><br>blah... blah...blah (working stuff) then:<br>
<br><br>1>C:/CUDA/bin/nvcc.exe C:/projects/NIH2009/source/branches/brian/source/cpp/app/testing/cudaTests/nbody/src/<a href="http://nbody_kernel.cu">nbody_kernel.cu</a> -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<br>
1><a href="http://nbody_kernel.cu">nbody_kernel.cu</a><br>1>tmpxft_00000fac_00000000-3_nbody_kernel.cudafe1.gpu<br>1>tmpxft_00000fac_00000000-8_nbody_kernel.cudafe2.gpu<br>1>tmpxft_00000fac_00000000-3_nbody_kernel.cudafe1.cpp<br>
1>tmpxft_00000fac_00000000-13_nbody_kernel.ii<br>1>Generated C:/projects/NIH2009/source/branches/brian/build/dvip4-Win64/cpp_source/nbody-new/Debug/nbody_generated_bodysystemcuda.cu.obj successfully.<br>1>Compiling...<br>
1>render_particles.cpp<br>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<br>1>nbody_gold.cpp<br>
1>nbody.cpp<br>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<br>1>bodysystemcuda.cpp<br>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<br>
1>bodysystemcpu.cpp<br>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<br>1>Generating Code...<br>
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"<br>1>nbody - 4 error(s), 0 warning(s)<br>========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========<br>
<br><br>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.<br><br>It looks as though a cpp file cannot find glew.h and cutil_inline.h in the NVIDIA CUDA SDK directory<br>
<br>So I then add to my CMakeLists.txt file (I think in a vain attempt to make it work):<br><br>INCLUDE_DIRECTORIES( ${CUDA_SDK_ROOT_DIR}/common/inc )<br><br><br>"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/<a href="http://nbody_kernel.cu">nbody_kernel.cu</a> -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 <a href="http://nbody_kernel.cu">nbody_kernel.cu</a> tmpxft_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'<br>
<br>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):<br><br>C:\NVIDIA Corporation\NVIDIA CUDA SDK\common\lib<br>
<br>So I add:<br><br>link_directories( ${CUDA_SDK_ROOT_DIR}/common/lib )<br><br>And I get:<br><br>Linking...<br>bodysystemcuda.obj : error LNK2019: unresolved external symbol allocateNBodyArrays referenced in function "protected: virtual void __cdecl BodySystemCUDA::_initialize(int)" (?_initialize@BodySystemCUDA@@MEAAXH@Z)<br>
bodysystemcuda.obj : error LNK2019: unresolved external symbol registerGLBufferObject referenced in function "protected: virtual void __cdecl BodySystemCUDA::_initialize(int)" (?_initialize@BodySystemCUDA@@MEAAXH@Z)<br>
bodysystemcuda.obj : error LNK2001: unresolved external symbol __imp___glewGetBufferParameteriv<br>bodysystemcuda.obj : error LNK2001: unresolved external symbol __imp___glewBufferData<br><br>...<br>There is lots more of this wherever this came from<br>
...<br><br>render_particles.obj : error LNK2001: unresolved external symbol __imp___glewAttachShader<br>render_particles.obj : error LNK2001: unresolved external symbol __imp___glewCreateProgram<br>render_particles.obj : error LNK2001: unresolved external symbol __imp___glewCompileShader<br>
render_particles.obj : error LNK2001: unresolved external symbol __imp___glewShaderSource<br>render_particles.obj : error LNK2001: unresolved external symbol __imp___glewCreateShader<br>C:\projects\NIH2009\source\branches\brian\build\Windows-6.1\ouput\bin\Debug\nbody.exe : fatal error LNK1120: 60 unresolved externals<br>
<br>So then I add:<br><br>add_library( cudart STATIC IMPORTED )<br>add_library( cutil64D STATIC IMPORTED )<br>add_library( glew64 STATIC IMPORTED )<br>add_library( glut64 STATIC IMPORTED )<br>#add_library( paramgl64 STATIC IMPORTED ) <- An attempt to build param and paramgl into a lib<br>
<br># Gotta love the syntax below... Is there anything less verbose than this in CMAKE?<br><br>set_property(TARGET cudart PROPERTY IMPORTED_LOCATION ${CUDA_TOOLKIT_ROOT_DIR}/lib/cudart.lib )<br>set_property(TARGET cutil64D PROPERTY IMPORTED_LOCATION ${CUDA_SDK_ROOT_DIR}/common/lib/cutil64D.lib )<br>
set_property(TARGET glew64 PROPERTY IMPORTED_LOCATION ${CUDA_SDK_ROOT_DIR}/common/lib/glew64.lib )<br>set_property(TARGET glut64 PROPERTY IMPORTED_LOCATION ${CUDA_SDK_ROOT_DIR}/common/lib/glut64.lib )<br>#set_property(TARGET paramgl64 PROPERTY IMPORTED_LOCATION ${CUDA_SDK_ROOT_DIR}/common/lib/paramgl64.lib )<br>
<br><br>#CUDA_ADD_LIBRARY( paramgl64 ${CUDA_SDK_ROOT_DIR}/common/src/param.cpp ${CUDA_SDK_ROOT_DIR}/common/src/paramgl.cpp STATIC )<br><br><br>#SET(NBODY_LIBS cudart cutil64D glew64 glut64 paramgl64 )<br>SET(NBODY_LIBS cudart cutil64D glew64 glut64 )<br>
<br><br>CUDA_ADD_EXECUTABLE( nbody ${NBODY_SRC} )<br>target_link_libraries (nbody ${NBODY_LIBS} )<br><br>And I get among other things:<br><br>1>nbody.obj : error LNK2019: unresolved external symbol "public: __cdecl ParamListGL::ParamListGL(char const *)" (??0ParamListGL@@QEAA@PEBD@Z) referenced in function "void __cdecl initParameters(void)" (?initParameters@@YAXXZ)<br>
1>nbody.obj : error LNK2019: unresolved external symbol "public: void __cdecl ParamListGL::Render(int,int,bool)" (?Render@ParamListGL@@QEAAXHH_N@Z) referenced in function "void __cdecl display(void)" (?display@@YAXXZ)<br>
1>nbody.obj : error LNK2019: unresolved external symbol "public: bool __cdecl ParamListGL::Mouse(int,int,int,int)" (?Mouse@ParamListGL@@QEAA_NHHHH@Z) referenced in function "void __cdecl mouse(int,int,int,int)" (?mouse@@YAXHHHH@Z)<br>
1>nbody.obj : error LNK2019: unresolved external symbol "public: bool __cdecl ParamListGL::Motion(int,int)" (?Motion@ParamListGL@@QEAA_NHH@Z) referenced in function "void __cdecl motion(int,int)" (?motion@@YAXHH@Z)<br>
1>nbody.obj : error LNK2019: unresolved external symbol "public: void __cdecl ParamListGL::Special(int,int,int)" (?Special@ParamListGL@@QEAAXHHH@Z) referenced in function "void __cdecl special(int,int,int)" (?special@@YAXHHH@Z)<br>
<br><br>So I change:<br><br>SET( NBODY_SRC<br> src/bodysystem.h<br> src/render_particles.h<br> src/bodysystemcpu.h<br> src/bodysystemcuda.h<br> src/<a href="http://bodysystemcuda.cu">bodysystemcuda.cu</a><br>
src/<a href="http://nbody_kernel.cu">nbody_kernel.cu</a><br> src/bodysystemcpu.cpp<br> src/bodysystemcuda.cpp<br> src/nbody.cpp<br> src/nbody_gold.cpp<br> src/render_particles.cpp<br> ${CUDA_SDK_ROOT_DIR}/common/src/param.cpp<br>
${CUDA_SDK_ROOT_DIR}/common/src/paramgl.cpp<br>)<br><br><br>To add param and pramgl<br><br>And I get:<br><br>1>------ Build started: Project: nbody, Configuration: Debug x64 ------<br>1>Linking...<br>1>bodysystemcuda.obj : error LNK2019: unresolved external symbol allocateNBodyArrays referenced in function "protected: virtual void __cdecl BodySystemCUDA::_initialize(int)" (?_initialize@BodySystemCUDA@@MEAAXH@Z)<br>
1>bodysystemcuda.obj : error LNK2019: unresolved external symbol registerGLBufferObject referenced in function "protected: virtual void __cdecl BodySystemCUDA::_initialize(int)" (?_initialize@BodySystemCUDA@@MEAAXH@Z)<br>
1>bodysystemcuda.obj : error LNK2019: unresolved external symbol unregisterGLBufferObject referenced in function "protected: virtual void __cdecl BodySystemCUDA::_finalize(void)" (?_finalize@BodySystemCUDA@@MEAAXXZ)<br>
1>bodysystemcuda.obj : error LNK2019: unresolved external symbol deleteNBodyArrays referenced in function "protected: virtual void __cdecl BodySystemCUDA::_finalize(void)" (?_finalize@BodySystemCUDA@@MEAAXXZ)<br>
1>bodysystemcuda.obj : error LNK2019: unresolved external symbol setDeviceSoftening referenced in function "public: virtual void __cdecl BodySystemCUDA::setSoftening(float)" (?setSoftening@BodySystemCUDA@@UEAAXM@Z)<br>
1>bodysystemcuda.obj : error LNK2019: unresolved external symbol integrateNbodySystem referenced in function "public: virtual void __cdecl BodySystemCUDA::update(float)" (?update@BodySystemCUDA@@UEAAXM@Z)<br>
1>bodysystemcuda.obj : error LNK2019: unresolved external symbol copyArrayFromDevice referenced in function "public: virtual float * __cdecl BodySystemCUDA::getArray(enum BodySystem::BodyArray)" (?getArray@BodySystemCUDA@@UEAAPEAMW4BodyArray@BodySystem@@@Z)<br>
1>bodysystemcuda.obj : error LNK2019: unresolved external symbol copyArrayToDevice referenced in function "public: virtual void __cdecl BodySystemCUDA::setArray(enum BodySystem::BodyArray,float const *)" (?setArray@BodySystemCUDA@@UEAAXW4BodyArray@BodySystem@@PEBM@Z)<br>
1>bodysystemcuda.obj : error LNK2019: unresolved external symbol threadSync referenced in function "public: virtual void __cdecl BodySystemCUDA::synchronizeThreads(void)const " (?synchronizeThreads@BodySystemCUDA@@UEBAXXZ)<br>
1>C:\projects\NIH2009\source\branches\brian\build\Windows-6.1\ouput\bin\Debug\nbody.exe : fatal error LNK1120: 9 unresolved externals<br>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"<br>
1>nbody - 10 error(s), 0 warning(s)<br>========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========<br><br>... to be continued<br><br>-- <br>Brian J. Davis<br><br><br>