Linking OpenCV 2.3 program in Mac OS X Lion: symbo

2019-03-01 00:03发布

问题:

I'm having a problem when trying to compile the program in this tutorial from the OpenCV 2.3 official documentation. I have created the CMakeList.txt like it's said in the link. Well, it didn't work.

After a good time searching Google and trying to fix it, I have added the correct lib and include folders to the OpenCVConfig.make (at /opt/local/share/opencv here). Well, this is the output when I try to make it:

$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/carlosagarie/dropbox/code/c++/opencv

$ make
Linking CXX executable teste
Undefined symbols for architecture x86_64:
  "cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
      _main in teste.cc.o
  "cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
      _main in teste.cc.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[2]: *** [teste] Error 1
make[1]: *** [CMakeFiles/teste.dir/all] Error 2
make: *** [all] Error 2

Trying to find out why it said ld: symbol(s) not found for architecture x86_64, I looked at my libraries folder (/opt/local/lib) and used the file command:

libopencv_calib3d.2.2.0.dylib:    Mach-O 64-bit dynamically linked shared library x86_64

The same for all the other libs. So, I assume that it's not a problem with them. But, why isn't ld working them? I really don't know what to do.

The code is the same as in the tutorial presented earlier. My CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8)
project( teste )
find_package( OpenCV REQUIRED )
add_executable( teste teste )
target_link_libraries( teste ${OpenCV_LIBS} )

Thanks in advance!

回答1:

I noticed you are following the 2.3.x guide, but the link error is referring to 2.2.0. Which version are you using?

Have you tried compiling it manually?

With something like this:

Assuming OPENCV_ROOT is set to your install location (e.g., /opt/local)

g++ -I$OPENCV_ROOT/include -L$OPENCV_ROOT/lib -lopencv_core2.2.0 -lopencv_calib3d2.2.0 -c test.cpp

If that doesn't work, have you tried running ldconfig as root? Is the install location for the opencv libraries setup in /etc/ld.so.conf (If not, you need to do this first before ldconfig will do anything useful)?

Edit you answer with updates to these questions. And, I'll try to help you with the rest.

EDIT :
You might also try adding this to your ~/.profile and see it fixes it:

export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib

Have you tried following this guide starting from Section 2 with XCode?