我正在使用可分離編譯的CUDA C++項目,並且在編譯推力函數時遇到了一些問題。使用推力時的未定義符號錯誤:: max_element
直到下面的函數調用被添加,項目纔會沒有問題。
thrust::device_ptr<float> max_int = thrust::max_element(
thrust::device_ptr<float>(dev_temp_intensity_buffer),
thrust::device_ptr<float>(dev_temp_intensity_buffer + INT_BUF_SIZE);
至於說,我得到的編譯錯誤:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol __fatbinwrap_66_tmpxft_00006db0_00000000_18_cuda_device_runtime_compute_61_cpp1_ii_8b1a5d37 referenced in function __cudaRegisterLinkedBinary_66_tmpxft_00006db0_00000000_18_cuda_device_runtime_compute_61_cpp1_ii_8b1a5d37 visualize C:\Users\13\Google Drive\WireMeshOT Rafael\CUDA\simulator\build\src\visualize_intermediate_link.obj 1
有趣的是,這一等推力函數調用編譯就好:
thrust::exclusive_scan(thrust::device_ptr<unsigned int>(dev_ray_alive),
thrust::device_ptr<unsigned int>(dev_ray_alive + NRAYS),
thrust::device_ptr<unsigned int>(dev_scanned_alive_rays));
OBS1:dev_temp_intensity_buffer
是一個浮動設備指針,我包括thrust/extrema.h
和thrust/device_ptr.h
。
Obs2:我正在使用CMake來配置構建。下面顯示了相關的CMake代碼摘錄。
SET(CUDA_SEPARABLE_COMPILATION ON)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -rdc=true -D_FORCE_INLINES)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -arch=compute_52 -code=sm_52 -lcudart -lcudadevrt -lcuda)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xptxas -v)
cuda_add_executable(
project
file1.cu
...)
target_link_libraries (project glut glew)
類似於這樣的問題:http://stackoverflow.com/questions/35704204/linking-cuda-plain-c-code-undefined-reference-to-fatbinwrap-66-tmpxft-e –
@JaredHoberock是的。我已經添加了-lcudadevrt到nvcc標誌,我也嘗試過使用'target_link_libraries(可視化utils cuda_utils glut glew $ {CUDA_LIBRARIES})'沒有任何成功。感謝您的評論。 –
問題是否獨立於您的CMake構建發生?你能夠從命令行手動鏈接一個程序嗎?你可以發佈一個小的再現程序來演示問題,以便其他人可以嘗試他們的系統嗎? –