I was trying to install opencv in one machine. And I met with an issue: for the library libavcodec-dev there are two copies in the machine,
/usr/local/lib
and /usr/lib
. The version in /usr/lib
is compatible with opencv. But CMake found /usr/local/lib
first. Could anyone help me? How to configure the cmake to find correct version? Thanks.
Asked
Active
Viewed 1,005 times
1

Alfred
- 71
- 1
- 7
-
This question has extensive information on how to affect the linking of libs: http://stackoverflow.com/questions/1487752/how-do-i-instruct-cmake-to-look-for-libraries-installed-by-macports – Soren May 07 '16 at 14:17
2 Answers
3
To specify a specific lib "Foo" found exactly in /usr/lib
you should use;
find_library(Foo foo PATHS /usr/lib NO_DEFAULT_PATH)
From the documentation;
If NO_DEFAULT_PATH is specified, then no additional paths are added to the search.
Documentation also goes on to say that the default search for libs are dictated and controlled by the CMAKE_LIBRARY_PATH
env variable.

Soren
- 14,402
- 4
- 41
- 67
-
I don't think this will work; it only appends the given `PATHS` to the *end* of the paths to search. – John Zwinck May 07 '16 at 15:26
-
1
find_library(AVCODEC avcodec-dev PATHS /usr/lib NO_DEFAULT_PATH)

John Zwinck
- 239,568
- 38
- 324
- 436
-
Is there any general way to change the search path order? Since there are many libraries in such case. Thanks. – Alfred May 07 '16 at 14:37
-