How to set up cmake to enable dynamic and static builds?

asked 2019-11-07 04:35:53 -0600

constantine gravatar image

I've built and make installed opencv on my mac with SHARED_LIBS. What do I need to do in order to be able to build with static linking so that I can build standalone apps which on other computers. I want to be able to choose between a built with or without shared libs.

I assume I have to recompile OpenCV with -DBUILD_SHARED_LIBS=OFF but I don't know what I have to do in cmake to make it work. I have the source in my ~/opencv and I've already compiled it in ~/opencv/build followed by make install.

Can I create another dir like ~/opencv/static_build and compile with the relevant flag? Do I need to make installas well? And how do I reference the specific opencv build in cmake? I suppose the cmake variables in

    find_package( OpenCV REQUIRED )

    include_directories(${OpenCV_INCLUDE_DIRS})
    target_link_libraries(test ${OpenCV_LIBS} "-static")

are all defined when make installis invoked. Is that correct?

edit retag flag offensive close merge delete