CMake tries to link with system libpng, even though I specifiy wxUSE_LIBPNG builtin

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
DerKnerd
Earned a small fee
Earned a small fee
Posts: 12
Joined: Wed Sep 29, 2021 11:50 pm

CMake tries to link with system libpng, even though I specifiy wxUSE_LIBPNG builtin

Post by DerKnerd »

Hey everyone,

today I started a new wxWidgets project, I use wxWidgets by submodules. The project is based on CMake, you can find it here: https://gitlab.imanuel.dev/DerKnerd/netcup-dns-tool

When I try to built the project I get a weird linking error that only happens with the most recent master branch, the previous versions (3.1.x) I used in other projects build fine. This is the error I get:

Code: Select all

/usr/bin/ld: libs/wxWidgets/lib/libwx_gtk3u_core-3.2.a(imagpng.cpp.o): undefined reference to symbol 'png_set_read_fn@@PNG16_0'
/usr/bin/ld: /usr/lib/libpng16.so.16: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/netcup_dns_tool.dir/build.make:170: netcup_dns_tool] Error 1
make[2]: *** [CMakeFiles/Makefile2:420: CMakeFiles/netcup_dns_tool.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:427: CMakeFiles/netcup_dns_tool.dir/rule] Error 2
make: *** [Makefile:169: netcup_dns_tool] Error 2
In the CMakeLists.txt I specify the following sets:

Code: Select all

set(wxUSE_STL ON)
set(wxUSE_OPENGL OFF)
set(wxBUILD_SHARED OFF)
set(wxUSE_ZLIB builtin)
set(wxUSE_EXPAT builtin)
set(wxUSE_LIBJPEG builtin)
set(wxUSE_LIBPNG builtin)
set(wxUSE_LIBTIFF builtin)
add_subdirectory(libs/wxWidgets)
Check below for the whole CMakeLists.txt

What confuses me, the CMakeLists.txt specifies to use the builtin version of libpng, but the linker tries to link against the system one. Can someone point me in the right direction?

Greetings
DerKnerd

Code: Select all

cmake_minimum_required(VERSION 3.24)
project(netcup_dns_tool)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(building/cmake/ucm.cmake)
include(conan.cmake)

ucm_set_runtime(STATIC)
if (WIN32 OR MINGW)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
    add_compile_definitions(__WXMSW__ _UNICODE)
    set(BUILD_SHARED_LIBS false)
    set(CMAKE_SYSTEM_NAME Windows)
    set(CMAKE_SYSTEM_PROCESSOR x86_64)
    set(CMAKE_WIN32_EXECUTABLE 1)
    set(CMAKE_CXX_COMPILER_WORKS TRUE)
    set(CMAKE_C_COMPILER_WORKS TRUE)
endif ()

set(wxUSE_STL ON)
set(wxUSE_OPENGL OFF)
set(wxBUILD_SHARED OFF)
set(wxUSE_ZLIB builtin)
set(wxUSE_EXPAT builtin)
set(wxUSE_LIBJPEG builtin)
set(wxUSE_LIBPNG builtin)
set(wxUSE_LIBTIFF builtin)
add_subdirectory(libs/wxWidgets)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})

conan_add_remote(NAME conan.imanuel.dev
        URL https://conan.imanuel.dev/artifactory/api/conan/conan-virtual)

conan_cmake_configure(
        REQUIRES
        cpp-httplib/0.11.3
        nlohmann_json/3.10.5
        GENERATORS cmake_find_package
)

if (MINGW)
    conan_cmake_install(PATH_OR_REFERENCE .
            BUILD missing
            REMOTE conan.imanuel.dev
            PROFILE ${CMAKE_SOURCE_DIR}/building/conan/linux_to_win64_conan)
else ()
    conan_cmake_autodetect(settings)
    conan_cmake_install(PATH_OR_REFERENCE .
            BUILD missing
            REMOTE conan.imanuel.dev
            SETTINGS ${settings})
endif ()

find_package(httplib)
find_package(nlohmann_json)
add_executable(netcup_dns_tool main.cpp netcup/client.cpp netcup/client.h windows/LoginDialog.cpp windows/LoginDialog.h windows/LoginDialog.cpp windows/LoginDialog.h NetcupApp.cpp NetcupApp.h wxDefaultHeader.h)

target_link_libraries(netcup_dns_tool PRIVATE wx::base wx::core httplib::httplib nlohmann_json::nlohmann_json)
DerKnerd
Earned a small fee
Earned a small fee
Posts: 12
Joined: Wed Sep 29, 2021 11:50 pm

Re: CMake tries to link with system libpng, even though I specifiy wxUSE_LIBPNG builtin

Post by DerKnerd »

I tried running it with

Code: Select all

wxUSE_LIBPNG sys
and then it works. Does someone know why?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: CMake tries to link with system libpng, even though I specifiy wxUSE_LIBPNG builtin

Post by ONEEYEMAN »

Hi,
How did you get the sources?
You should use:

git clone https://github.con/wxwidgets/wxwidgets.git --recurse-submodules

to get it.

Thank you.
DerKnerd
Earned a small fee
Earned a small fee
Posts: 12
Joined: Wed Sep 29, 2021 11:50 pm

Re: CMake tries to link with system libpng, even though I specifiy wxUSE_LIBPNG builtin

Post by DerKnerd »

Hey,

I got the sources as git submodule using the following list of commands:

Code: Select all

git submodule init 
git submodule add [email protected]:wxWidgets/wxWidgets.git libs/wxWidgets
git submodule update --init --recursive
Greetings
DerKnerd
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: CMake tries to link with system libpng, even though I specifiy wxUSE_LIBPNG builtin

Post by ONEEYEMAN »

Hi,
Does it work now?

Thank you.
DerKnerd
Earned a small fee
Earned a small fee
Posts: 12
Joined: Wed Sep 29, 2021 11:50 pm

Re: CMake tries to link with system libpng, even though I specifiy wxUSE_LIBPNG builtin

Post by DerKnerd »

Not with the submodule. I found a workaround using conan. By including libpng via Conan. But that is no real solution.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: CMake tries to link with system libpng, even though I specifiy wxUSE_LIBPNG builtin

Post by PB »

Disclaimer: I do not use Linux or configure.

AFAIK, the option must be used when building wxWidgets, did you do that? And if so, did you try building the minimal sample using wxWidgets cmakefile to see if the issue is present there?


Secondly, your Cmake is very complex (and seems using static linking which may not be common on Linux), so one cannot rule there is an issue there. Did you try true minimal (just hello world code, no libraries aside wxWidgets) test to see if the issue is still there?
Post Reply