0

I want to build an executable that includes all of libs that I used (opencv, dlib) so it can work on any computer. Here is my current CMakeList.txt

cmake_minimum_required(VERSION 3.5.1)
project(adc_fr)

set(CMAKE_CXX_STANDARD 14)

add_subdirectory(/media/sf_dlib-19.9/dlib dlib_build)

FIND_PACKAGE(OpenCV REQUIRED)

set(SOURCE_FILES
        FDetect.cpp
        FDetect.h
        FExtract.cpp
        FExtract.h
        main.cpp
        )

add_executable(adc_fr ${SOURCE_FILES})
set_target_properties(adc_fr PROPERTIES LINK_FLAGS "-static")

target_link_libraries(adc_fr
        ${OpenCV_LIBS}
        dlib
        )

Here is the error I got when linking

/usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libwebp.so'
collect2: error: ld returned 1 exit status
CMakeFiles/adc_fr.dir/build.make:409: recipe for target 'adc_fr' failed
make[2]: *** [adc_fr] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/adc_fr.dir/all' failed
make[1]: *** [CMakeFiles/adc_fr.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

I do have libwebp.a available in /usr/lib/x86_64-linux-gnu/

How can I force to use static libwebp.a instead of libwebp.so?

I did try to add #SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") but it still gave the same error.

Much appreciated!

D R
  • 21
  • 7
  • Possible duplicate of [Compiling a static executable with CMake](https://stackoverflow.com/questions/24648357/compiling-a-static-executable-with-cmake) – nega Apr 20 '18 at 03:04

1 Answers1

0

How about this:

find_library(LIBWEBP_LOCATION libwebp.a)
target_link_libraries(adc_fr
        ${OpenCV_LIBS}
        dlib
        ${LIBWEBP_LOCATION}
        )
thachnb
  • 1,503
  • 10
  • 13
  • Got the same error. I think linker can find correct location, in this case `/usr/lib/x86_64-linux-gnu/` but it still uses the shared `.so` lib. – D R Apr 12 '18 at 22:46
  • Right under find_library, can you add this `message(STATUS ${LIBWEBP_LOCATION})` And see the result? – thachnb Apr 12 '18 at 22:54