1

I need to control the library order during linking, but CMake is doing weird things with OpenCV libs. See the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.13)
project(cvtest)

set( CMAKE_VERBOSE_MAKEFILE on )

add_executable(cvtest "test.cpp")

find_package(OpenCV 3 REQUIRED core)
target_link_libraries(cvtest ${OpenCV_LIBS} FOO)

When building the resulting makefile, libraries are linked in the following order:

libopencv_core.3.4.2.dylib -lFOO

All good so far (FOO needs to go last). However, if I add another opencv lib:

cmake_minimum_required(VERSION 3.13)
project(cvtest)

set( CMAKE_VERBOSE_MAKEFILE on )

add_executable(cvtest "test.cpp")

find_package(OpenCV 3 REQUIRED core highgui)
target_link_libraries(cvtest ${OpenCV_LIBS} FOO)

Then the linker recieves libraries in the following order:

libopencv_highgui.3.4.2.dylib -lFOO libopencv_videoio.3.4.2.dylib libopencv_imgcodecs.3.4.2.dylib libopencv_imgproc.3.4.2.dylib libopencv_core.3.4.2.dylib

Importantly, FOO is not last anymore! I tried everything but I cannot make FOO appear at the end of the linking list. Does anyone know how this can be done?

Thanks,

user2385408
  • 79
  • 1
  • 3
  • Here: https://stackoverflow.com/questions/12204820/cmake-and-order-dependent-linking-of-shared-libraries – Nuzhny Mar 14 '19 at 07:16
  • Thanks @nuzhny, unfortunately this does not fix my problem. I tried both the link orders in `target_link_libraries` and making a list, but as you can see above, cmake is still linking libraries after FOO. – user2385408 Mar 14 '19 at 16:44

0 Answers0