1
votes

I am trying to link a dynamic library (dylib) on mac mountian-lion. Nothing I try has worked.

$ gcc main.cpp -l/usr/local/lib/libopencv_core.2.4.6.dylib ld: library not found for -llibopencv_core.2.4.6.dylib

The library exists:

$ ls /usr/local/lib/libopencv_core.2.4.6.dylib /usr/local/lib/libopencv_core.2.4.6.dylib

I get the same null result using clang. Using otool to reveal dependencies ...

$ otool -L /usr/local/lib/libopencv_core.2.4.6.dylib /usr/local/lib/libopencv_core.2.4.6.dylib: lib/libopencv_core.2.4.dylib (compatibility version 2.4.0, current version 2.4.6) /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

I am not sure what the problem is, it could be a versioning issue, I do not know. I am probably missing something simple but essential: can anyone tell me what I am missing?

1

1 Answers

0
votes

In order to refer to a library with a filename of:

libMyLib.{a,so,dylib}

using the -l command line option, you use the form:

-lMyLib

So try this:

$ gcc main.cpp -L/usr/local/lib -lopencv_core

(also note that it's normally undesirable to link with a versioned dynamic library most of the time, so I have dropped it from the command line).