Tuesday, October 4, 2022

[SOLVED] Windows vs code wxWidgets's #include <wx/wx.h> not found

Issue

I use window10 and vs code to compile some source code. I can compile the code but when I run the .exe file. Nothing shows up. I got this error. rel="nofollow noreferrer">enter image description here

My cmakefile is as follows:

    cmake_minimum_required(VERSION 3.11.3)
    
    set(CMAKE_CXX_STANDARD 17)
    
    project(membot)
    set(wxWidgets_ROOT_DIR "C:/wxWidgets-3.1.4")
    set(wxWidgets_LIB_DIR "C:/wxWidgets-3.1.4/lib/gcc_dll"
        CACHE PATH "wxWidgets_LIB_DIR ")
    find_package(wxWidgets REQUIRED COMPONENTS core base)
    include(${wxWidgets_USE_FILE})
    
    file(GLOB project_SRCS src/*.cpp)
    
    add_executable(membot ${project_SRCS})
    target_link_libraries(membot ${wxWidgets_LIBRARIES})
    target_include_directories(membot PRIVATE ${wxWidgets_INCLUDE_DIRS})

I don't know how to solve it. I also tried to include the path in the c_cpp_properties.json, but still doesn't work.


Solution

I found my solution.

  1. In the cmakefile.txt, I use find_package(wxWidgets REQUIRED gl core base OPTIONAL_COMPONENTS net) instead of find_package(wxWidgets REQUIRED COMPONENTS core base)

My final cmakefile.txt is like this

cmake_minimum_required(VERSION 3.11.3)

set(CMAKE_CXX_STANDARD 17)

project(membot)

set(wxWidgets_ROOT_DIR "C:/wxWidgets-3.1.4")
set(wxWidgets_LIB_DIR "C:/wxWidgets-3.1.4/lib/gcc_dll")
find_package(wxWidgets REQUIRED gl core base OPTIONAL_COMPONENTS net)

include(${wxWidgets_USE_FILE})

file(GLOB project_SRCS src/*.cpp)

add_executable(membot ${project_SRCS})
target_link_libraries(membot ${wxWidgets_LIBRARIES})
target_include_directories(membot PRIVATE ${wxWidgets_INCLUDE_DIRS})
  1. Referring to this https://wiki.wxwidgets.org/Compiling_wxWidgets_with_MinGW to have a correct wxwidgets build. I use mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release clean to clean the dynamic libraries and use mingw32-make -f makefile.gcc SHARED=0 UNICODE=1 BUILD=release clean to clean the static libraries. Then I use this mingw32-make -j8 -f makefile.gcc BUILD=release SHARED=0 UNICODE=1 VENDOR=custom to build static libraries.
  2. Use cmake -G "MinGW Makefiles" .. and make to compile the source code. It succeeded.


Answered By - Youshikyou
Answer Checked By - Gilberto Lyons (WPSolving Admin)