JakubOchnik / Cube-LUT-Loader

A simple command-line 1D/3D .cube LUT loader.
Other
28 stars 4 forks source link

How do you build the project to use static library? #20

Closed stephane-archer closed 1 year ago

stephane-archer commented 1 year ago

I struggled to build the project with OpenCV as a static library. Here is how I was able to do it. I downloaded OpenCV 4.8.0 source files. I build it with cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DWITH_OPENEXR=OFF ../ (OpenExr was causing linking issues) Then I added all the .a files from OpenCV to src/CMakeLists.txt like this:

target_link_libraries(${PROJECT_NAME} PUBLIC
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/ippicv/ippicv_mac/icv/lib/intel64/libippicv.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/libade.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/libippiw.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/libittnotify.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibjpeg-turbo.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibopenjp2.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibpng.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibprotobuf.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibtiff.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibwebp.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/libquirc.a
/Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/libzlib.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_calib3d.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_core.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_dnn.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_features2d.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_flann.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_gapi.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_highgui.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_imgcodecs.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_imgproc.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_ml.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_objdetect.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_photo.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_stitching.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_ts.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_video.a
/Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_videoio.a
OpenCL::OpenCL
    Boost::program_options
    Eigen3::Eigen
)

I had to add OpenCL as a dependency too at the end here are the libs that are still dynamically loaded:

$ otool -L build/src/lut_loader
/System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1500.65.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)

(which is fine, I wanted to remove OpenCV but I don't know yet if dynamically linking to OpenCL would cause any issues)

stephane-archer commented 1 year ago

@JakubOchnik do you think disabling OPENEXR would cause a problem?

JakubOchnik commented 1 year ago

Hi, @stephane-archer. OpenEXR is not necessary (unless you use EXR images). Actually, I only use OpenCV for loading and saving the image, so I left only the required libraries: opencv_core and opencv_imgcodecs. That should make the process much easier for you and probably remove the need for OpenCL.

stephane-archer commented 1 year ago

@JakubOchnik I was able to build the last version of the project by reusing the previous version I had of OpenCV 4.8.0 then modifying src/CMakeLists.txt the following way:

modified: src/CMakeLists.txt
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@ src/CMakeLists.txt:17 @ message(STATUS "Boost include dir: ${Boost_INCLUDE_DIRS}")

find_package (Eigen3 3.3 REQUIRED NO_MODULE)

+ find_package(OpenCL REQUIRED)

# Detect include directories for the external libraries
if (BUILD_CUDA)
    message(STATUS "CUDA include dir: ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}")
@ src/CMakeLists.txt:31 @ endif()
add_library(${MAIN_LIB_NAME} STATIC)

target_include_directories(${MAIN_LIB_NAME} PUBLIC ${INCLUDE_DIRS})
- target_link_libraries(${MAIN_LIB_NAME} PUBLIC ${LIBRARIES_TO_LINK})
+ target_link_libraries(${MAIN_LIB_NAME} PUBLIC
+     /Users/fractale/opencv-4.8.0/build_opencv/3rdparty/ippicv/ippicv_mac/icv/lib/intel64/libippicv.a
+     /Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/libippiw.a
+     /Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/libittnotify.a
+     /Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibjpeg-turbo.a
+     /Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibopenjp2.a
+     /Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibpng.a
+     /Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibtiff.a
+     /Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/liblibwebp.a
+     /Users/fractale/opencv-4.8.0/build_opencv/3rdparty/lib/libzlib.a
+     /Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_core.a
+     /Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_imgcodecs.a
+     /Users/fractale/opencv-4.8.0/build_opencv/lib/libopencv_imgproc.a
    OpenCL::OpenCL
    Boost::program_options
    Eigen3::Eigen
    )

add_subdirectory(${SOURCE_DIR}/ImageProcessing)
add_subdirectory(${SOURCE_DIR}/TaskDispatcher)
$ otool -L build/src/lut_loader
        /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1500.65.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)

As you can see OpenCL is still a dependency but it didn't cause me any issue for now