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 tocv::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 tocv::gpu::getDevice()' stereo_match.cpp:(.text+0x8ec): undefined reference to
cv::gpu::printShortCudaDeviceInfo(int)' /tmp/ccvj1IgD.o: In functionApp::run()': stereo_match.cpp:(.text+0xa42): undefined reference to
cv::imread(std::string const&, int)' stereo_match.cpp:(.text+0xa70): undefined reference tocv::imread(std::string const&, int)' stereo_match.cpp:(.text+0xb90): undefined reference to
cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0xba0): undefined reference tocv::_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 tocv::_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 tocv::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 tocv::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 tocv::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 tocv::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 tocv::_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 tocv::_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 tocv::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 tocv::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 tocv::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 tocv::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 tocv::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 tocv::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 tocv::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 tocv::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 tocv::imshow(std::string const&, cv::_InputArray const&)' stereo_match.cpp:(.text+0x105c): undefined reference to
cv::waitKey(int)' /tmp/ccvj1IgD.o: In functionApp::handleKey(char)': stereo_match.cpp:(.text+0x1630): undefined reference to
cv::_InputArray::_InputArray(cv::Mat const&)' stereo_match.cpp:(.text+0x1640): undefined reference tocv::_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 tocv::_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 tocv::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 tocv::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 tocv::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 tocv::imshow(std::string const&, cv::_InputArray const&)' /tmp/ccvj1IgD.o: In function
cv::Mat::~Mat()': stereo_match.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x20): undefined reference tocv::fastFree(void*)' /tmp/ccvj1IgD.o: In function
cv::Mat::operator=(cv::Mat const&)': stereo_match.cpp:(.text.ZN2cv3MataSERKS0[ZN2cv3MataSERKS0]+0xa2): undefined reference tocv::Mat::copySize(cv::Mat const&)' /tmp/ccvj1IgD.o: In function
cv::Mat::create(int, int, int)': stereo_match.cpp:(.text._ZN2cv3Mat6createEiii[_ZN2cv3Mat6createEiii]+0x66): undefined reference tocv::Mat::create(int, int const*, int)' /tmp/ccvj1IgD.o: In function
cv::Mat::release()': stereo_match.cpp:(.text._ZN2cv3Mat7releaseEv[ZN2cv3Mat7releaseEv]+0x30): undefined reference tocv::Mat::deallocate()' /tmp/ccvj1IgD.o: In function
cv::gpu::GpuMat::GpuMat(cv::Size, int)': stereo_match.cpp:(.text._ZN2cv3gpu6GpuMatC2ENS_5Size_IiEEi[_ZN2cv3gpu6GpuMatC5ENS_5Size_IiEEi]+0x5c): undefined reference tocv::gpu::GpuMat::create(int, int, int)' /tmp/ccvj1IgD.o: In function
cv::gpu::GpuMat::~GpuMat()': stereo_match.cpp:(.text._ZN2cv3gpu6GpuMatD2Ev[_ZN2cv3gpu6GpuMatD5Ev]+0xa): undefined reference tocv::gpu::GpuMat::release()' /tmp/ccvj1IgD.o: In function
App::workBegin()': stereo_match.cpp:(.text._ZN3App9workBeginEv[_ZN3App9workBeginEv]+0x8): undefined reference tocv::getTickCount()' /tmp/ccvj1IgD.o: In function
App::workEnd()': stereo_match.cpp:(.text._ZN3App7workEndEv[_ZN3App7workEndEv]+0x8): undefined reference tocv::getTickCount()' stereo_match.cpp:(.text._ZN3App7workEndEv[_ZN3App7workEndEv]+0x20): undefined reference to
cv::getTickFrequency()' collect2: error: ld returned 1 exit status
.a
) as-l
options and the directories where to find them with the-L
option in your linker command line? – πάντα ῥεῖ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. – hhonypkg-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