Source Code
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(
test_wxwidgets
LANGUAGES CXX
VERSION 1.0
)
find_package(wxWidgets REQUIRED)
include(${wxWidgets_USE_FILE})
add_executable(${PROJECT_NAME} source/main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${wxWidgets_LIBRARIES})
source/main.cpp
#include <iostream>
#include <wx/wx.h>
int main()
{
wxString wxs(wxT("Hello"));
const wxScopedCharBuffer buf = wxs.ToUTF8 ();
std::string s(buf.data(), buf.length());
std::cout << s << std::endl;
return 0;
}
Build failed when using wxgtk3 from the official repo
$ cmake <folder_path_for_CMakeLists.txt> -DwxWidgets_CONFIG_EXECUTABLE=/usr/bin/wx-config-gtk3 -DCMAKE_BULD_TYPE=Debug
$ cmake --build .
..
[build] /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../lib/libwx_gtk3u_webview-3.0.so: undefined reference to `webkit_web_view_go_back'
[build] /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../lib/libwx_gtk3u_webview-3.0.so: undefined reference to `webkit_web_view_go_forward'
...
Build succeeded when using wxwidget that is built manually
$ cmake <folder_path_for_CMakeLists.txt> -DwxWidgets_CONFIG_EXECUTABLE=/opt/wxWidgets/bin/wx-config -DCMAKE_BULD_TYPE=Debug
$ cmake --build .