我正在使用Ubuntu中的wxWidgets开发一个hello-world级程序。
代码用
编译g++ HelloWorld.cpp `wx-config --libs` `wx-config --cxxflags` -o HelloWorldApp -I../inc
maot@HP-Pavilion-dv7:~/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src$ which wx-config
/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/wx-config
maot@HP-Pavilion-dv7:~/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src$
...这是有道理的,因为我将路径放在PATH环境变量中的wx-config。我自己编译了wxWidgets。
现在我想使用cmake。我的CMakeLists.txt文件尝试:
cmake_minimum_required(VERSION 2.8.9)
project(WxWidgets_Learning_01)
set(CMAKE_CXX_COMPILER /usr/bin/g++)
message("CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG " -g3 ")
set(CMAKE_CXX_FLAGS_RELEASE "")
message("CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
include_directories(../inc)
include_directories(../api/IBJts/source/cppclient/client)
include_directories(../api/IBJts/source/cppclient)
# wxWidgets header files start
include_directories(/home/maot/Perforce/wxWidgets-3.1.0/include)
include_directories(/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib/wx/include/gtk2-unicode-3.1)
# wxWidgets header files end
# wxWidgets defines start
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__)
# wxWidgets defines finish
# Directories with wxWidget libs start
link_directories(/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib)
# Directories with wxWidget libs finish
SET(wxWidgets_ROOT_DIR /home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib)
SET(wxWidgets_CONFIGURATION mswud)
# https://cmake.org/cmake/help/v3.0/module/FindwxWidgets.html
# Note that for MinGW users the order of libs is important!
find_package(wxWidgets COMPONENTS net gl core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall -pthread -lm ")
file(GLOB sources "../src/*.cpp" )
file(GLOB headers "../inc/*.h" )
set(daytrading_sources ${sources} ${headers})
add_executable(WxWidgets_Learning_01 ${sources})
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
输出:
maot@HP-Pavilion-dv7:~/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src$ \rm -rf CMakeFiles/ ; cmake .
-- The C compiler identification is GNU 7.2.0
-- The CXX compiler identification is GNU 7.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMAKE_CXX_FLAGS_DEBUG = -g
CMAKE_CXX_FLAGS_RELEASE = -O3 -DNDEBUG
CMAKE_CXX_FLAGS_DEBUG = -g3
CMAKE_CXX_FLAGS_RELEASE =
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find wxWidgets (missing: wxWidgets_FOUND)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindwxWidgets.cmake:832 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:40 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/maot/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src/CMakeFiles/CMakeOutput.log".
maot@HP-Pavilion-dv7:~/Perforce/maot_HP_Pavilion_dv7_full_02/WxWidgets/Learning_01/src$
我认为find_package找不到wxWidgets,我不明白为什么。我不确定这个mswud的事情因为我找不到关于它的解释; ms听起来像比尔G.我已经为wxWidgets_ROOT_DIR尝试了一些值,但没有运气。欢迎任何帮助:wxWidgets_ROOT_DIR应该有什么价值,mswud有什么好处?
===编辑以下===
我使用--prefix = $(pwd)选项跟随https://wiki.wxwidgets.org/Compiling_and_getting_started。不需要make install,它就是sais。
如何将wx-config的结果放入CMakeLists.txt?
maot@HP-Pavilion-dv7:~$ wx-config --cxxflags
-I/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib/wx/include/gtk2-unicode-3.1 -I/home/maot/Perforce/wxWidgets-3.1.0/include -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread
maot@HP-Pavilion-dv7:~$
maot@HP-Pavilion-dv7:~$ wx-config --libs
-L/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib -pthread -Wl,-rpath,/home/maot/Perforce/wxWidgets-3.1.0/gtk-build/lib -lwx_gtk2u_xrc-3.1 -lwx_gtk2u_html-3.1 -lwx_gtk2u_qa-3.1 -lwx_gtk2u_adv-3.1 -lwx_gtk2u_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu_net-3.1 -lwx_baseu-3.1
maot@HP-Pavilion-dv7:~$
我使用下面的CMakeLists.txt文件编译并运行我的代码;我意识到这不是预期的方式。
cmake_minimum_required(VERSION 2.8.9)
project(WxWidgets_Learning_01)
set(CMAKE_CXX_COMPILER /usr/bin/g++)
message("CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG " -g3 ")
set(CMAKE_CXX_FLAGS_RELEASE "")
message("CMAKE_CXX_FLAGS_DEBUG = ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE = ${CMAKE_CXX_FLAGS_RELEASE}")
include_directories(../inc)
include_directories(../api/IBJts/source/cppclient/client)
include_directories(../api/IBJts/source/cppclient)
# wxWidgets header files start
include_directories(../../../../wxWidgets-3.1.0/include)
include_directories(../../../../wxWidgets-3.1.0/gtk-build/lib/wx/include/gtk2-unicode-3.1)
# wxWidgets header files end
# wxWidgets defines start
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__)
# wxWidgets defines finish
# Directories with wxWidget libs start
link_directories(../../../../wxWidgets-3.1.0/gtk-build/lib)
# Directories with wxWidget libs finish
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall -pthread -lm ")
file(GLOB sources "../src/*.cpp" )
file(GLOB headers "../inc/*.h" )
set(daytrading_sources ${sources} ${headers})
add_executable(WxWidgets_Learning_01 ${sources})
target_link_libraries(WxWidgets_Learning_01
libwx_baseu-3.1.so
libwx_gtk2u_adv-3.1.so
libwx_gtk2u_gl-3.1.so
libwx_gtk2u_qa-3.1.so
libwx_gtk2u_stc-3.1.so
libwx_baseu_net-3.1.so
libwx_gtk2u_aui-3.1.so
libwx_gtk2u_html-3.1.so
libwx_gtk2u_ribbon-3.1.so
libwx_gtk2u_xrc-3.1.so
libwx_baseu_xml-3.1.so
libwx_gtk2u_core-3.1.so
libwx_gtk2u_propgrid-3.1.so
libwx_gtk2u_richtext-3.1.so
)
# I have just added all .so files that I found after the build.
答案 0 :(得分:0)
如果你只需要为原型编译一个简单的例子就可以了。
但是,如果你需要编译一些大项目 - 你可以尝试设置Anjuta / CodeBlocks / CodeLite来提供帮助。从长远来看,它将使您受益(特别是CodeBlocks)。
就你的问题而言:mswud并不好,因为它(如名称所示)适用于Windows。
此外,对于include / lib目录,您应该使用wx-config相应的命令,就像您用于命令行编译一样。
您还可以尝试在trac.wxwidgets.org中查看TobiasT的CMake工作。