2

I am trying to use cmake to build my project. I want to link against libpng which is present in my system. This is my code:

cmake_minimum_required(VERSION 2.8.11)
project(main)

file(GLOB SOURCES *.c)
add_executable(sphstego ${SOURCES})

find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
target_link_libraries(main ${PNG_LIBRARY})

message(STATUS "PNG_LIBRARY: " ${PNG_LIBRARY}) # correct path to so file

My problem is that I want to link statically rather than dynamically. Furthermore, and although the variable set as PNG_LIBRARY is correctly set to /usr/local/lib/libpng.so, I get an error message when running my executable:

error while loading shared libraries: libpng16.so.16: cannot open shared object file: No such file or directory

Any suggestions on how to resolve this?

rocambille
  • 15,398
  • 12
  • 50
  • 68
Mike M
  • 4,879
  • 5
  • 38
  • 58
  • https://stackoverflow.com/questions/16991225/cmake-and-static-linking – user2807083 Oct 10 '16 at 08:29
  • Lots of information on linking internal and external libraies statically here: http://stackoverflow.com/questions/3762057/cmake-how-to-produce-binaries-as-static-as-possible – djrollins Oct 10 '16 at 08:30

0 Answers0