【问题标题】:CMake WxWidgets project successfully built on linux but not on windowsCMake WxWidgets项目在linux上成功构建但在windows上没有
【发布时间】:2020-10-24 22:27:07
【问题描述】:

我已经设法在 Ubuntu 19.10 上基于 CMake 构建了一个 WxWidgets,但在 Windows 10 上失败了,说它找不到 WxWidgets,尽管我已经成功构建了它(静态、发布并支持 unicode)。

WxWidgets 路径为C:\wxWidgets-3.1.3,构建目录为C:\wxWidgets-3.1.3\msw-release

makefile 是

cmake_minimum_required(VERSION 3.0)

project(ChessPgnReviser VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

ADD_DEFINITIONS(-Wall -Wno-sign-compare -O2)

set(SRCS
    src/main.cpp
)

set (HEADERS
)

message( "--Root--" ${wxWidgets_ROOT_DIR} )
message( "--Lib dir--" ${wxWidgets_LIB_DIR} )

add_executable(ChessPgnReviser ${SRCS} ${HEADERS})

find_package(wxWidgets COMPONENTS net gl core base)
if(wxWidgets_FOUND)
  include(${wxWidgets_USE_FILE})
  target_link_libraries(ChessPgnReviser ${wxWidgets_LIBRARIES})
else()
    message(FATAL_ERROR "Failed to find WxWidgets library")
endif()

我正在使用 Msys 64 位来编译项目。在其子文件夹 etc/profile 的底部,我添加了

PATH=$PATH:/c/dev/cmake/bin
wxWidgets_ROOT_DIR=/c/wxWidgets-3.1.3
wxWidgets_LIBRARIES=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_LIB_DIR=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_INCLUDE_DIRS=$wxWidgets_ROOT_DIR/include

所以我试过了

$ mkdir build && cd build
$ cmake .. -G "MinGW Makefiles"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--
--Lib dir--
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
  Failed to find WxWidgets library


-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".

另外,感谢@squareskittles,我也试过了:

$ cmake .. -G "MinGW Makefiles" -DwxWidgets_ROOT_DIR="C:\wxWidgets-3.1.3" -DwxWidgets_LIB_DIR="C:\wxWidgets-3.1.3\msw-release\lib"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--C:\wxWidgets-3.1.3
--Lib dir--C:\wxWidgets-3.1.3\msw-release\lib
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
  Failed to find WxWidgets library


-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".

您可以找到 msw-release 文件夹的内容:there

还有:

$ ls /c/wxWidgets-3.1.3/msw-release/lib/
libwx_baseu_net-3.1.a  libwx_baseu-3.1.a     libwx_mswu_aui-3.1.a   libwx_mswu_gl-3.1.a    libwx_mswu_media-3.1.a     libwx_mswu_qa-3.1.a      libwx_mswu_richtext-3.1.a  libwx_mswu_webview-3.1.a  libwxregexu-3.1.a     wx
libwx_baseu_xml-3.1.a  libwx_mswu_adv-3.1.a  libwx_mswu_core-3.1.a  libwx_mswu_html-3.1.a  libwx_mswu_propgrid-3.1.a  libwx_mswu_ribbon-3.1.a  libwx_mswu_stc-3.1.a       libwx_mswu_xrc-3.1.a      libwxscintilla-3.1.a

那我是不是忘记了什么?

【问题讨论】:

  • 如何在命令行中调用cmake 命令?我问是因为 CMake 日志文件使用 Windows 格式放在路径 C:/Users... 上,但您的 wxWidgets_* 变量使用路径 /c/ 并使用 Unix 样式格式。这让我认为变量对 CMake 不可见,您是否验证它们是可见的?您是否尝试过将 wxWidget 路径设置为 CMake 命令行参数? cmake .. -G "MinGW Makefiles" -DwxWidgets_ROOT_DIR=C:/wxWidgets-3.1.3
  • 谢谢。不幸的是,它没有用。请看我编辑的帖子。我还设法拨打了ls $wxWidgets_ROOT_DIR之类的电话。
  • 我记得在构建 wxWidgets 时遇到了同样的问题,您需要 构建两次 才能克服一些错误,也许这个线程 (github.com/rhiestan/Regard3D/issues/17) 可以在构建时帮助您两次不起作用。
  • 如果检测使用了wx-config,您可以尝试安装github.com/kowey/wx-config-win。要告诉它你的 wxWidgets 在哪里,你需要将环境变量 WXWIN 设置为 C:/wxWidgets-3.1.3WXCFG 设置为 msw\gcc_mswu 之类的东西。
  • 嗨@BrechtSanders。事实上,我需要我已经安装的 wx-config,因为 cmake 函数 FindWxWidgets 是基于 wx-config 的。但是,我仍在尝试使其与我的 cmake 脚本一起使用,以便构建能够成功。我已经设置了 WXWIN 和 WXCFG 变量。

标签: c++ windows cmake wxwidgets mingw-w64


【解决方案1】:

要正确检测 wxWidgets,您需要 wx-config

存在wx-config 的 Windows 版本,可从以下位置下载:https://github.com/kowey/wx-config-win

要让wx-config知道你的wxWidgets在哪里,你需要设置以下环境变量:

  • WXWIN(你的情况是C:/wxWidgets-3.1.3
  • WXCFG(在你的情况下是like msw/gcc_mswu)。

【讨论】:

  • 谢谢。我还必须重新编译 wxWidgets,以便在子文件夹 msw/gcc_mswu 中设置静态库。为此,我进入文件夹 msw 并使用 mingw32-make.exe 进行编译,而不是自己创建 msw-release 文件夹。这样,将 wx-config 设置为路径,它就起作用了。
  • @loloof64 我构建了没有共享 dll 的 wxWidgets,包括调试和发布。我没有要为 WXCFG 变量指定的 msw/gcc_mswu 文件夹。这是必须的吗? \bin 文件夹:有 wx-config.exe , wxrc.exe。 \lib 有 *mswu*.a 文件
  • @VaisakMohan 检查 lib/gcc_lib(或 lib/gcc_dll 用于共享构建)。通常你应该在那里找到像msw/build.cfg / mswd/build.cfg / mswu/build.cfg / mswud/build.cfg 这样的东西。这就是您应该在WXCFG 中指定的内容。
  • wxWidgets 安装文件夹中没有名为 build.cfg 的文件。(这是我的文件夹树:paste.ubuntu.com/p/jvy9zzVTzC)。当我在 Windows 终端中键入“wx-config --libs --cflags”时,它会给出错误:wx-config Error: wxWidgets has not been found installed at 'X:\SYSTEM\wxWidgets'。
  • @VaisakMohan 那棵树实际上是 wxWidgets 的 Windows 版本吗?通常安装文件夹将包含 build.cfg...
猜你喜欢
  • 2020-05-23
  • 1970-01-01
  • 2022-08-14
  • 2018-12-23
  • 1970-01-01
  • 2021-01-16
  • 2012-01-28
  • 2019-11-28
  • 2014-04-30
相关资源
最近更新 更多