我正在尝试使用静态链接的wxWidgets构建一个项目(我只想指出它与共享库编译和链接就好了)。这是我CMakeLists.txt
的相关部分:
set(wxWidgets_USE_STATIC ON)
find_package(wxWidgets REQUIRED)
这是我得到的错误:
$ make
-- Boost version: 1.64.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- program_options
CMake Error at C:/Dev/msys64/mingw64/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES)
Call Stack (most recent call first):
C:/Dev/msys64/mingw64/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
C:/Dev/msys64/mingw64/share/cmake-3.9/Modules/FindwxWidgets.cmake:953 (find_package_handle_standard_args)
CMakeLists.txt:16 (find_package)
-- Configuring incomplete, errors occurred!
但安装了静态库
$ ls -l /mingw64/lib | grep libwx
-rw-r--r-- 1 tv185035 Domain Users 668K Sep 13 20:16 libwx_baseu_net-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 453K Sep 13 20:14 libwx_baseu_net-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 84K Sep 13 20:16 libwx_baseu_xml-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 68K Sep 13 20:14 libwx_baseu_xml-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 5.9M Sep 13 20:16 libwx_baseu-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 4.6M Sep 13 20:14 libwx_baseu-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 6.8M Sep 13 20:16 libwx_mswu_adv-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 3.2M Sep 13 20:14 libwx_mswu_adv-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 1.8M Sep 13 20:16 libwx_mswu_aui-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 1.1M Sep 13 20:14 libwx_mswu_aui-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 28M Sep 13 20:16 libwx_mswu_core-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 12M Sep 13 20:14 libwx_mswu_core-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 278K Sep 13 20:16 libwx_mswu_gl-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 175K Sep 13 20:14 libwx_mswu_gl-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 2.6M Sep 13 20:16 libwx_mswu_html-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 1.4M Sep 13 20:14 libwx_mswu_html-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 2.2M Sep 13 20:16 libwx_mswu_propgrid-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 1.6M Sep 13 20:14 libwx_mswu_propgrid-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 331K Sep 13 20:16 libwx_mswu_qa-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 193K Sep 13 20:14 libwx_mswu_qa-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 1.6M Sep 13 20:16 libwx_mswu_ribbon-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 646K Sep 13 20:14 libwx_mswu_ribbon-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 3.6M Sep 13 20:16 libwx_mswu_richtext-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 2.4M Sep 13 20:14 libwx_mswu_richtext-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 849K Sep 13 20:16 libwx_mswu_stc-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 2.1M Sep 13 20:14 libwx_mswu_stc-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 404K Sep 13 20:16 libwx_mswu_webview-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 634K Sep 13 20:14 libwx_mswu_webview-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 4.4M Sep 13 20:16 libwx_mswu_xrc-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 1.1M Sep 13 20:14 libwx_mswu_xrc-3.0.dll.a
-rw-r--r-- 1 tv185035 Domain Users 90K Sep 13 20:16 libwxregexu-3.0.a
-rw-r--r-- 1 tv185035 Domain Users 2.7M Sep 13 20:16 libwxscintilla-3.0.a
我不知道它拒绝工作的原因。有人请帮忙吗?
答案 0 :(得分:1)
我做到了,
set(wxWidgets_USE_LIBS ON) <-- add this before find_package
find_package(wxWidgets REQUIRED)
并在cmake中明确指定wxWidgets_LIB_DIR,例如
wxWidgets_LIB_DIR=W:/wxWidgets-3.0.4/lib/vc_x64_lib
答案 1 :(得分:0)
嗯,所以我没有让它与wxWidgets_USE_STATIC
一起使用,但是后续工作(并在发布版本中生成静态可执行文件)
cmake_minimum_required(VERSION 3.9)
set(PROJECT_NAME "jibril")
project(${PROJECT_NAME})
set(BUILD_SHARED_LIBS OFF)
set(BUILD_STATIC_LIBS ON)
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
if(NOT build_type_lower MATCHES debug)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
find_package(
Boost REQUIRED
system
filesystem
program_options
)
find_package(wxWidgets REQUIRED)
string(
REPLACE
";-Wl,--subsystem,windows;-mwindows"
""
wxWidgets_LIBRARIES
"${wxWidgets_LIBRARIES}"
)
add_executable(
${PROJECT_NAME}
src/main.cpp
)
target_include_directories(
${PROJECT_NAME}
PUBLIC ${Boost_INCLUDE_DIRS}
PUBLIC ${wxWidgets_INCLUDE_DIRS}
)
target_compile_options(
${PROJECT_NAME}
PRIVATE -Wall
PRIVATE -Wextra
PRIVATE -Werror
PRIVATE -Wduplicated-cond
PRIVATE -Wduplicated-branches
PRIVATE -Wlogical-op
PRIVATE -Wrestrict
PRIVATE -Wnull-dereference
#PRIVATE -Wold-style-cast
#PRIVATE -Wuseless-cast
#PRIVATE -Wdouble-promotion
PRIVATE -Wshadow
#PRIVATE -Wformat=2
)
target_link_libraries(
${PROJECT_NAME}
${Boost_LIBRARIES}
${wxWidgets_LIBRARIES}
optimized -static
optimized -luuid
optimized -lcomctl32
optimized -loleacc
optimized -lpng
optimized -lz
optimized -s
)