找不到“wxWidgets”提供的包配置文件

问题描述 投票:0回答:1

为了开始在 Ubuntu 23.10 中使用 wxWidgets,我使用 wx-config 编译并构建了

minimum
示例:https://github.com/wxWidgets/wxWidgets/blob/master/samples/minimal/

raphy@raohy:~/MyPrj$ g++ `wx-config --cxxflags` -o myprj ./src/*.cpp `wx-config --libs`
raphy@raohy:~/MyPrj$ ./myprj

现在我想将这个命令行编译和构建转换为 CMake

我使用了

samples
代码中提供的CMakeLists.txt文件:https://github.com/wxWidgets/wxWidgets/blob/master/samples/minimal/CMakeLists.txt,我在其中添加了这两行:
set(wxBUILD_SAMPLES ON)
 set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr/local/lib/wx)
:

cmake_minimum_required(VERSION 3.24)

if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
    # If no deployment target has been set default to the minimum supported
    # OS version (this has to be set before the first project() call)
    if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
        set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0 CACHE STRING "iOS Deployment Target")
    else()
        set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10 CACHE STRING "macOS Deployment Target")
    endif()
endif()

# Name the project
project(minimal)


set(CMAKE_CXX_STANDARD 11 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr/local/lib/wx)

set(wxBUILD_SAMPLES ON)



# Request the required wxWidgets libs
find_package(wxWidgets 3.3 COMPONENTS core base REQUIRED CONFIG)

# Include the wxWidgets use file to initialize various settings
if(wxWidgets_USE_FILE)
    include(${wxWidgets_USE_FILE})
endif()

# Define a variable containing a list of source files for the project
set(SRC_FILES
    src/minimal.cpp
    )

if(WIN32)
    # Include a RC file for windows
    list(APPEND SRC_FILES ./sample.rc)
elseif(APPLE)
    # Add an icon for the apple .app file
    list(APPEND SRC_FILES ./src/osx/carbon/wxmac.icns)
endif()

# Define the build target for the executable
add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${SRC_FILES})
# Link required libraries to the executable
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})

if(APPLE)
    set_target_properties(${PROJECT_NAME} PROPERTIES
        RESOURCE "./src/icons/wxmac.icns"
        MACOSX_BUNDLE_ICON_FILE wxmac.icns
        MACOSX_BUNDLE_COPYRIGHT "Copyright wxWidgets"
        MACOSX_BUNDLE_GUI_IDENTIFIER "org.wxwidgets.minimal"
        )
endif()

但我收到此错误:

raphy@raohy:~/MyPrj$ cmake -B builddir
-- The C compiler identification is GNU 12.3.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - 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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:48 (find_package):
  Could not find a package configuration file provided by "wxWidgets"
  (requested version 3.3) with any of the following names:

    wxWidgetsConfig.cmake
    wxwidgets-config.cmake

  Add the installation prefix of "wxWidgets" to CMAKE_PREFIX_PATH or set
  "wxWidgets_DIR" to a directory containing one of the above files.  If
  "wxWidgets" provides a separate development package or SDK, be sure it has
  been installed.


-- Configuring incomplete, errors occurred!

如何让它发挥作用?

c++ c cmake wxwidgets
1个回答
1
投票

我通过这种方式解决了修改

find_package
行的问题:

find_package(wxWidgets 3.3 REQUIRED COMPONENTS core base)
并设置 cxx_standard :
set(CMAKE_CXX_STANDARD 11)

-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /home/raphy/MyPrj/builddir
raphy@raohy:~/MyPrj$ cmake --build builddir
[ 50%] Building CXX object CMakeFiles/minimal.dir/src/minimal.cpp.o
[100%] Linking CXX executable minimal
[100%] Built target minimal
raphy@raohy:~/MyPrj$ ./builddir/
© www.soinside.com 2019 - 2024. All rights reserved.