[英]Compiling a basic OpenCV + Cuda program on linux
我過去曾在linux上使用opencv,但沒有使用cuda。 幾個月來,我一直在努力解決以下編譯錯誤。 在嘗試了許多解決方案后,我放棄了並使用了Windows。 但是,我真的想在linux上工作。 這是我用來編譯opencv_gpu網站上給出的閾值示例的命令。
nvcc `pkg-config --libs opencv` -L. -L/usr/local/cuda/lib -lcuda -lcudart `pkg-config --cflags opencv` -I. -I/usr/local/cuda/include threshold.cpp -o threshold
這是錯誤:
/tmp/tmpxft_0000171b_00000000-1_threshold.o: In function `main':
threshold.cpp:(.text+0x124): undefined reference to `cv::gpu::Stream::Null()'
threshold.cpp:(.text+0x156): undefined reference to `cv::gpu::threshold(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, int, cv::gpu::Stream&)'
threshold.cpp:(.text+0x16d): undefined reference to `cv::gpu::GpuMat::download(cv::Mat&) const'
/tmp/tmpxft_0000171b_00000000-1_threshold.o: In function `cv::gpu::GpuMat::GpuMat(cv::Mat const&)':
threshold.cpp:(.text._ZN2cv3gpu6GpuMatC1ERKNS_3MatE[cv::gpu::GpuMat::GpuMat(cv::Mat const&)]+0x63): undefined reference to `cv::gpu::GpuMat::upload(cv::Mat const&)'
/tmp/tmpxft_0000171b_00000000-1_threshold.o: In function `cv::gpu::GpuMat::~GpuMat()':
threshold.cpp:(.text._ZN2cv3gpu6GpuMatD1Ev[cv::gpu::GpuMat::~GpuMat()]+0xd): undefined reference to `cv::gpu::GpuMat::release()'
collect2: ld returned 1 exit status
make: *** [all] Error 1
為了幫助您,我必須下載並安裝CUDA 4.0 (帶驅動程序4.0.21),然后在Mac OS X 10.6.8上為我的Macbook Pro下載和編譯OpenCV 2.3 。
OpenCV_GPU的示例代碼已在我的機器上通過以下方式成功編譯:
g++ threshold.cpp -o threshold `pkg-config --cflags --libs opencv` -lopencv_gpu
你錯過了標志-lopencv_gpu
,它不包含在pkg-config中 。
這看起來像鏈接器問題。 我不知道,如果nvcc
遵循與gcc
相同的約定,但我會嘗試:
nvcc`pkg-config --cflags opencv` -L。 -L / usr / local / cuda / lib -I。 -I / usr / local / cuda / include -o threshold threshold.cpp`pkg-config --libs opencv` -lcuda -lcudart
更一般:如果你寫
gcc t.cpp -lB -lA
這意味着libB
依賴於從符號libA
; t.cpp
可以依賴於來自libA
和libB
符號。
我建議只需手動將編譯器指向opencv庫並包含文件,而不是在nvcc行中使用pkg-config。 也許你可以在命令行上運行pkg-config --libs opencv並將必要的lib復制到你的nvcc命令中。 似乎nvcc只是在opencv libs上窒息(它無法找到它們!)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.