Search code examples
c++visual-studio-codewxwidgets

VS Code and wxWidgets: fatal error: wx/wx.h: No such file or directory


I built wxWidgets without any errors with make and did make install and now I have the installation in /usr/local/include/wx-3.1/. Both wx/wx.h and wx/setup.h are present in that folder. I'm using the latest VS Code with the latest Ubuntu 20.04.

c_cpp_properties.json file:

"configurations": [
    {
        "name": "Linux",
        "includePath": [
            "/usr/local/include/wx-3.1/",
            "${default}"
        ],
        "defines": [],
        "compilerPath": "/usr/bin/gcc",
        "cStandard": "gnu18",
        "cppStandard": "gnu++14",
        "intelliSenseMode": "gcc-x64"
    }
],
"version": 4
}

main.cpp:

#include "wx/wx.h"

int main(){}

Compiling gives the following error:

g++ -std=c++17 -Wall -Wextra -g   -c -o src/main.o src/main.cpp
src/main.cpp:1:10: fatal error: wx/wx.h: No such file or directory
    1 | #include "wx/wx.h"
      |          ^~~~~~~~~
compilation terminated.

The weird thing is that VS Code Intellisense detects that wx is included and there is no error or red underline (removing the include folder from includePath makes VS Code display an error).

What's the problem here? Everything seems to be correctly included.


Solution

  • in addition you will need to point the linker to the libraries to use with the -L option and use -l (lowercase L) with every library you will need.

    Example:

    -L/usr/local/lib -lwxcore-3.1 -lwxbase-3.1

    Check the library names there and use them without lib prefix.

    Better yet - try to run wx-config --libs and use the output for the linker options in your IDE.

    Also, for complete set of options to the compiler use the output of wx-config --cxxflags