Reputation: 33
I'm trying to run the following code on MAC OS 10.10:
#include <cv.h>
#include <highgui.h>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("xxx.jpg");
imshow("image", img);
waitKey(0);
return 0;
}
This code can be built successfully. But, when I run it, I always get the error message:
dyld: lazy symbol binding failed: Symbol not found:
__ZN2cv6imreadERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi
Referenced from:
/Users/Coldmoon/ComputerVisionApps/opencvTest/Build/Products/Debug/opencvTest
Expected in: /usr/local/lib/libopencv_highgui.2.4.dylib
I have two different versions of opencv. One is built with libstdc++
, the other is built with libc++
. Both are opencv 2.4.9. I want to build the above code using libc++
opencv.
So, in the Xcode 6.1, I set Header Search Path
and Library Search Path
to point to libc++
opencv which is in /Users/Coldmoon/MyLibraries/opencv-2.4.9
and set C++ Standard Library
to libc++
.
My question: It seems that compiler does not link the libc++
opencv but libstdc++
opencv instead which is in /usr/local/lib
.
I'm totally confused. Is there anything I miss?
Upvotes: 1
Views: 3095
Reputation: 13238
Library Search Paths
tells linker where to search for the library to link to. But when the executable is run, the library may be searched by dynamic loader (dyld
) in different places. This is controlled by 'Install Name' of the library that may be queried by otool -D libFoo.dylib
.
So, for example, if the library you are linking to is in /bar/libFoo.dylib
, but its install name is /baz/libFoo.dylib
, you need to put /bar
in Library Search Paths
, but when you run the binary it'll be searched in /baz
.
You can also find out where the libraries are seachred when the executable is run by otool -L <executable>
.
If the path to shared library is not absolute, dynamic loader tries to load it from some standard paths. If you set DYLD_PRINT_LIBRARIES
environment variable, dyld
will log the filenames of the libraries it tries to load to stderr
. You can override the paths where dyld
searches for libraries by setting DYLD_LIBRARY_PATH
variable (:
-separated list of paths).
More info about dyld
environment variables can be found in man dyld
.
Upvotes: 4