c++linuxwifiglib

Cannot include Libnm and Glib properly


I tried to use libnm for a small hobby-tool. (a cli tool e. g. for connecting via ssid with a network)

To my setup: I use fedora linux and installed NetworkManager-libnm-devel. (glib was already installed and up to date) I also can find the directories of the libraries in the /usr/include directory. Because of that, I can write e. . #include <libnm/NetworkManager.h> and #include <glib-2.0/glib.h>. So far so good.

Now I am getting error messages saying, that all includes in these files cannot be found. (Also when compiling with gcc main.cpp -o main.o)

This is a error message I get:

(glib)

#include errors detected based on information provided by the configurationProvider setting. Squiggles are disabled for this translation unit (/path/to/project/src/main.cpp).C/C++(1696)
cannot open source file "glib/galloca.h" (dependency of "glib-2.0/glib.h")

or (libnm)

cannot open source file "gio/gio.h" (dependency of "libnm/NetworkManager.h")

This is the only code I am using for now:

#include <iostream>

#include <glib-2.0/glib.h>
#include <libnm/NetworkManager.h>

int main(const int argc, const char **argv)
{
    std::cout << "Hello, World!" << std::endl;

    return EXIT_SUCCESS;
}

The only thing I could find whats to do, is here: https://developer-old.gnome.org/libnm/stable/usage.html

It's a bit sad, that there is no further explanation how to properly use this library. :( I hope that anyone can help me, thanks!


Solution

  • Including those files with a path relative to /usr/include, as in your example

    #include <glib-2.0/glib.h>
    #include <libnm/NetworkManager.h>
    

    is not how they are meant to be included, and will likely not work, because those headers include other dependent headers which won't be found relative to /usr/include.

    In the "How to use libnm" section of the page that you linked, it shows that you must include them as

    #include <glib.h>
    #include <NetworkManager.h>
    

    and use pkg-config to get the correct compiler flags. Add $(pkg-config --cflags --libs libnm) to your compiler command line.