使用 WxWidgets 和 Conan 的未定义符号

Undefined symbols using WxWidgets and Conan

我正在尝试采用 Conan C++ 包管理器。我跟着入门已经设法让它与大多数项目一起工作。但是我遇到了与 WxWidgets 的链接问题,我似乎无法修复。

链接器错误:

[ 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 - 项目根目录 -

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 -- 源文件夹 --

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})

柯南默认配置文件:

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

我不确定是否需要将 dep 包含到我的 conanfile 中,尽管我认为 Conan 会自动管理它?如果我删除错误中列出的违规部分,应用程序链接成功。

编辑: 您在 CONAN_LIBS 全球范围内是正确的。您的 CMake 结构看起来不错。您可以尝试从 src CMakeLists.txt.

调用 conan_basic_setup()

如果这不起作用,问题可能出在您的 conanfile.py 中。 https://github.com/bincrafters/conan-wxwidgets/commit/37b6669229ec0e68593065a700c360d23a914bac