Search code examples
c++wxwidgetsconan

Undefined symbols using WxWidgets and Conan


I am trying to adopt the Conan C++ package manager. I have followed along with the getting started have managed to get it working with most projects. However I am having linking issues with WxWidgets that I can't seem to fix.

linker error:

[ 23%] Linking CXX executable ../bin/wx_sample
Undefined symbols for architecture x86_64:
  "Frame::onMenuFileQuit(wxCommandEvent&)", referenced from:
      __GLOBAL__sub_I_frame.cpp in frame.cpp.o
  "Frame::onMenuFileSave(wxCommandEvent&)", referenced from:
      __GLOBAL__sub_I_frame.cpp in frame.cpp.o
  "Frame::onMenuFileAbout(wxCommandEvent&)", referenced from:
      __GLOBAL__sub_I_frame.cpp in frame.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/wx_sample] Error 1
make[1]: *** [src/CMakeFiles/wx_sample.dir/all] Error 2
make: *** [all] Error 2

conanfile.txt

[requires]
wxwidgets/3.1.4@bincrafters/stable

[generators]
cmake

CmakeFile.txt - project root -

cmake_minimum_required(VERSION 3.17)
project(wx_sample)

set(CMAKE_CXX_STANDARD 17)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

include_directories(src)

add_subdirectory(src)

CmakeFile.txt -- src folder --

set(BINARY ${CMAKE_PROJECT_NAME})
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.h *.cpp)
set(SOURCES ${SOURCES})

add_executable(${BINARY} ${SOURCES})
target_link_libraries(${BINARY} ${CONAN_LIBS})

conan default profile:

Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=12.0
os=Macos
os_build=Macos

I am not sure if I need to include deps into my conanfile, though I thought that Conan manages this automatically? If I remove the offending sections listed in the error, the application links successfully.


Solution

  • EDIT: You were right on the CONAN_LIBS global. Your CMake structure looks fine. You could try to call conan_basic_setup() from the src CMakeLists.txt.

    If that doesn't work the issue might be in your conanfile.py. https://github.com/bincrafters/conan-wxwidgets/commit/37b6669229ec0e68593065a700c360d23a914bac