【发布时间】:2021-06-18 13:15:34
【问题描述】:
我想将 fetch_content 与 wxWidgets 一起使用。到目前为止,我有这个并且它“有效”。但我不确定我应该在 target_link_libraries 中链接什么。
main.cpp 是一个 hello world 示例,它无法编译,因为它找不到 #include
编辑1 我设法通过手动添加库来运行 cmake 脚本。问题仍然是它到目前为止没有在 Windows 上链接,并且只在 arch linux 上工作过一次。 编辑2 这个 cmake 在 windows 和 linux 上工作和构建。
include(FetchContent)
if (MSVC)
add_executable(_TARGET_
WIN32
src/main.cpp
)
else()
add_executable(_TARGET_
src/main.cpp
)
endif()
# ------------------ wxWidgets ------------------
set(wxBUILD_SHARED OFF CACHE BOOL "Build wx libraries as shared libs")
set(wxBUILD_PRECOMP OFF CACHE BOOL "Use precompiled headers")
set(wxBUILD_MONOLITHIC OFF CACHE BOOL "Build a single library")
FetchContent_Declare(
wxWidgets
GIT_REPOSITORY https://github.com/wxWidgets/wxWidgets.git
GIT_TAG v3.1.4
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(wxWidgets)
FetchContent_MakeAvailable(wxWidgets)
target_link_libraries(foo
wxbase
wxcore
wxnet
)
【问题讨论】:
-
您收到的具体错误信息是什么?你能编译 wxWidgets 提供的
minimal示例吗?您尝试在哪个操作系统/编译器上运行它? -
你能找到 wx/wx.h 或 wx/wxprec.h 吗?我在 Windows 上遇到了编译问题。