2
votes

I am having considerable difficulty compiling a standard opencv sample with opencv4tegra - installed as instructed by the nvidia wiki for the Jetson TK1.

Out of frustration I built opencv from the 2.4.10.1 source and I installed it directly into /usr/local... and it worked great! After I uninstalled it I had the same issue compiling against theirs, so clearly it is something that I am doing. Funny thing is, I can run the compiled sample app against their opencv4tegra lib just fine... but I cannot compile against their lib.

Test environment:

I did not change the sample file from 2.4.10.1 release of opencv - it is the same stereo_match.cpp file. I'm just trying to compile it.

The functions are inside the gpu.hpp file - I have already looked. I have also run:

nm /usr/lib/libopencv_gpu.so | grep StereoBM_GPU | c++filt

...just to ensure the symbols are in the library.

What is going on?? So, it's clearly not linking - but I can't figure out what g++ wants...

$:~/opencv/samples/gpu$ g++ -I/usr/include -L/usr/local/cuda/lib `pkg-config opencv --libs` stereo_match.cpp -o stereo_m

/tmp/ccvj1IgD.o: In function App::App(Params const&)': stereo_match.cpp:(.text+0x8b0): undefined reference to cv::gpu::StereoBM_GPU::StereoBM_GPU()' stereo_match.cpp:(.text+0x8c6): undefined reference to cv::gpu::StereoBeliefPropagation::StereoBeliefPropagation(int, int, int, int)' stereo_match.cpp:(.text+0x8e0): undefined reference to cv::gpu::StereoConstantSpaceBP::StereoConstantSpaceBP(int, int, int, int, int)' stereo_match.cpp:(.text+0x8e4): undefined reference to cv::gpu::getDevice()' stereo_match.cpp:(.text+0x8ec): undefined reference tocv::gpu::printShortCudaDeviceInfo(int)' /tmp/ccvj1IgD.o: In function App::run()': stereo_match.cpp:(.text+0xa42): undefined reference tocv::imread(std::string const&, int)' stereo_match.cpp:(.text+0xa70): undefined reference to cv::imread(std::string const&, int)' stereo_match.cpp:(.text+0xb90): undefined reference tocv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0xba0): undefined reference to cv::_OutputArray::_OutputArray(cv::Mat&)' stereo_match.cpp:(.text+0xbb4): undefined reference to cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' stereo_match.cpp:(.text+0xbc4): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0xbd4): undefined reference to cv::_OutputArray::_OutputArray(cv::Mat&)' stereo_match.cpp:(.text+0xbe8): undefined reference to cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' stereo_match.cpp:(.text+0xbfa): undefined reference to cv::gpu::GpuMat::upload(cv::Mat const&)' stereo_match.cpp:(.text+0xc0c): undefined reference to cv::gpu::GpuMat::upload(cv::Mat const&)' stereo_match.cpp:(.text+0xc3e): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0xc4e): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' stereo_match.cpp:(.text+0xc94): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0xca4): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' stereo_match.cpp:(.text+0xdaa): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0xdba): undefined reference to cv::_OutputArray::_OutputArray(cv::Mat&)' stereo_match.cpp:(.text+0xdce): undefined reference to cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' stereo_match.cpp:(.text+0xdde): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0xdee): undefined reference to cv::_OutputArray::_OutputArray(cv::Mat&)' stereo_match.cpp:(.text+0xe02): undefined reference to cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' stereo_match.cpp:(.text+0xe4e): undefined reference to cv::gpu::GpuMat::upload(cv::Mat const&)' stereo_match.cpp:(.text+0xe60): undefined reference to cv::gpu::GpuMat::upload(cv::Mat const&)' stereo_match.cpp:(.text+0xe92): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0xea2): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' stereo_match.cpp:(.text+0xee8): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0xef8): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' stereo_match.cpp:(.text+0xf22): undefined reference to cv::gpu::Stream::Null()' stereo_match.cpp:(.text+0xf34): undefined reference to cv::gpu::StereoBM_GPU::operator()(cv::gpu::GpuMat const&, cv::gpu::GpuMat const&, cv::gpu::GpuMat&, cv::gpu::Stream&)' stereo_match.cpp:(.text+0xf4c): undefined reference to cv::gpu::Stream::Null()' stereo_match.cpp:(.text+0xf5e): undefined reference to cv::gpu::StereoBeliefPropagation::operator()(cv::gpu::GpuMat const&, cv::gpu::GpuMat const&, cv::gpu::GpuMat&, cv::gpu::Stream&)' stereo_match.cpp:(.text+0xf76): undefined reference to cv::gpu::Stream::Null()' stereo_match.cpp:(.text+0xf88): undefined reference to cv::gpu::StereoConstantSpaceBP::operator()(cv::gpu::GpuMat const&, cv::gpu::GpuMat const&, cv::gpu::GpuMat&, cv::gpu::Stream&)' stereo_match.cpp:(.text+0xfa0): undefined reference to cv::gpu::GpuMat::download(cv::Mat&) const' stereo_match.cpp:(.text+0xff6): undefined reference to cv::putText(cv::Mat&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)' stereo_match.cpp:(.text+0x1032): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0x1042): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' stereo_match.cpp:(.text+0x105c): undefined reference to cv::waitKey(int)' /tmp/ccvj1IgD.o: In function App::handleKey(char)': stereo_match.cpp:(.text+0x1630): undefined reference tocv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0x1640): undefined reference to cv::_OutputArray::_OutputArray(cv::Mat&)' stereo_match.cpp:(.text+0x1654): undefined reference to cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' stereo_match.cpp:(.text+0x1664): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0x1674): undefined reference to cv::_OutputArray::_OutputArray(cv::Mat&)' stereo_match.cpp:(.text+0x1688): undefined reference to cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)' stereo_match.cpp:(.text+0x169a): undefined reference to cv::gpu::GpuMat::upload(cv::Mat const&)' stereo_match.cpp:(.text+0x16ac): undefined reference to cv::gpu::GpuMat::upload(cv::Mat const&)' stereo_match.cpp:(.text+0x1718): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0x1728): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' stereo_match.cpp:(.text+0x176e): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0x177e): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' /tmp/ccvj1IgD.o: In functioncv::Mat::~Mat()': stereo_match.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x20): undefined reference to cv::fastFree(void*)' /tmp/ccvj1IgD.o: In functioncv::Mat::operator=(cv::Mat const&)': stereo_match.cpp:(.text.ZN2cv3MataSERKS0[ZN2cv3MataSERKS0]+0xa2): undefined reference to cv::Mat::copySize(cv::Mat const&)' /tmp/ccvj1IgD.o: In functioncv::Mat::create(int, int, int)': stereo_match.cpp:(.text._ZN2cv3Mat6createEiii[_ZN2cv3Mat6createEiii]+0x66): undefined reference to cv::Mat::create(int, int const*, int)' /tmp/ccvj1IgD.o: In functioncv::Mat::release()': stereo_match.cpp:(.text._ZN2cv3Mat7releaseEv[ZN2cv3Mat7releaseEv]+0x30): undefined reference to cv::Mat::deallocate()' /tmp/ccvj1IgD.o: In functioncv::gpu::GpuMat::GpuMat(cv::Size, int)': stereo_match.cpp:(.text._ZN2cv3gpu6GpuMatC2ENS_5Size_IiEEi[_ZN2cv3gpu6GpuMatC5ENS_5Size_IiEEi]+0x5c): undefined reference to cv::gpu::GpuMat::create(int, int, int)' /tmp/ccvj1IgD.o: In functioncv::gpu::GpuMat::~GpuMat()': stereo_match.cpp:(.text._ZN2cv3gpu6GpuMatD2Ev[_ZN2cv3gpu6GpuMatD5Ev]+0xa): undefined reference to cv::gpu::GpuMat::release()' /tmp/ccvj1IgD.o: In functionApp::workBegin()': stereo_match.cpp:(.text._ZN3App9workBeginEv[_ZN3App9workBeginEv]+0x8): undefined reference to cv::getTickCount()' /tmp/ccvj1IgD.o: In functionApp::workEnd()': stereo_match.cpp:(.text._ZN3App7workEndEv[_ZN3App7workEndEv]+0x8): undefined reference to cv::getTickCount()' stereo_match.cpp:(.text._ZN3App7workEndEv[_ZN3App7workEndEv]+0x20): undefined reference tocv::getTickFrequency()' collect2: error: ld returned 1 exit status

1
Did you provide the libraries (.a) as -l options and the directories where to find them with the -L option in your linker command line?πάντα ῥεῖ
I don't know if we're speaking the same thing? and this is not a duplicate... So, pkg-config opencv --libs will return the path to all the library shared objects (.so) The -L I provided is for the -lcudart ect... provided by the pkg-config cmd... but to answer your question directly, adding -L/usr/lib additionally will not help. I've already tried it.hhony
You are linking. These are linker errors. I can only assume pkg-config is not returning the flags to include the library that contains the definitions of those symbols.Samuel Edwin Ward
$LD_LIBRARY_PATH has little to do here. It's an environment variable used by the dynamic linker when you attempt to run the program. It's GCC's -L/path/to/lib flags that you use to tell it to find libraries in non-default paths. And for your information, those are linker errors. Don't take our word, it even says so itself in your error message: collect2: error: ld returned 1 exit status, though it's conceivable that the preprocessor header GCC finds misdeclares those functions. And lastly, OpenCV4Tegra is closed-source.Iwillnotexist Idonotexist
Think I found my issue. Thanks for the clue @IwillnotexistIdonotexist. The macros inside the opencv cmake make references to opencv_nonfree... perhaps it was sobel or something. Hence, why the entire library builds it.hhony

1 Answers

2
votes

See the macros inside cmake instructions for packaging in opencv and stick to using make. Thanks again for the clue 'Iwillnotexist Idonotexist'.

In my case, there were two dependencies I missed: /modules/gpu/src/nvidia && /modules/gpu/src/nvidia/core ...and there were references to 'nonfree' in other parts.

Hidden dependency stuff... oh boy.

Thanks for all the contributing responses - seems trivial now.