0

I am building a C++ CMake application and I can't get the wxWidgets library to link correctly to the executable. When I build it in Visual Studio 2022 on Windows, the FFTW3 and SDL2 .dll files are in the same directory as the executable, however, wxWidgets .dll files are not. Therefore, after running the executable, an error message appears that wxWidgets .dll files are missing. They are in their separate /libs/wxWidgets/libs/.../*.dll directory, but they are not linked to the executable.

I added the libraries as git submodules in my project and I am building them from source. Therefore, I am adding them using add_subdirectory and include_directories.

I am relatively new to this and I don't know what I am doing wrong. Any help would be very much appreciated!

This is my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.21)

if (UNIX)
    enable_language(OBJCXX)
endif (UNIX)

project(my_app LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 20)

add_subdirectory(libs/SDL)
include_directories(libs/SDL/include)

add_subdirectory(libs/fftw3)
include_directories(libs/fftw3/api)

add_subdirectory(libs/wxWidgets)
include_directories(libs/wxWidgets/include)

add_executable(my_app WIN32 main.cpp ...)

target_link_libraries(my_app PRIVATE SDL2 fftw3 wx::net wx::core wx::base)
tomasxboda
  • 539
  • 3
  • 15
  • You say that they're not linked to the binary but they are? `target_link_libraries(my_app PRIVATE ... wx::net wx::core wx::base)`? `wx::*` are wxWidgets libraries right? So they _are_ linked to your binary. – Marc Dirven Apr 24 '23 at 21:30
  • @MarcDirven yes, I am linking them in the `CMakeLists.txt` but when I build the application (in VisualStudio), the application does not open and instead an error dialog is shown saying that the wxWidgets `*.dll` files couldn't be found. So they are not linking properly. In order for the app to start, I need to manually find these libraries in some subfolders and move them to the root folder where the `.exe` file is located. That's the thing I need to solve – tomasxboda Apr 29 '23 at 14:07
  • 1
    Then you will need to copy the `wx` `.dll`'s to the same location as your executable. You can find more information on about how to do that here: https://stackoverflow.com/questions/10671916/how-to-copy-dll-files-into-the-same-folder-as-the-executable-using-cmake – Marc Dirven Apr 30 '23 at 15:09
  • I was afraid I would have to do this, I was hoping there was a better solution. I am going to do it this way then, thank you! – tomasxboda May 03 '23 at 10:48

0 Answers0