Fatal error: dbus/dbus.h: No such file or directory

Hello,

I am trying to use dbus in my C++ program on the Apalis iMX8 on Ixora.
I am using VSCode with the Torizon early access extension.

I am getting the error
fatal error: dbus/dbus.h: No such file or directory
#include <dbus/dbus.h>

I have tried the following options.
For Torizon extension in volumes, I have added the following.
/usr/include/dbus-1
/usr/share/dbus-1/services
/var/run/dbus

Added libdbus-1-3 in extrapackages.

Added libdbus-1-dev:#%platform.debian-arch%# in devpackages.

In tasks.json, I have added the option “-ldbus-1”.

But in spite of adding these, I am still getting the above dbus error.

Hi @SJ_BHD ,

You don’t need to add these volumes for this issue in particular. You correctly added libdbus to devpackages and extrapackages, but looking at the Debian file list for the dev package shows us that the header files are not in the standard include path.

Try doing the following:

  • Add libdbus-1-3 in extrapackages;
  • Add libdbus-1-dev:#%platform.debian-arch%# in devpackages;
  • Rebuild the SDK container when prompted
    (you can also do so manually by pressing F1 then selecting Torizon: Rebuild SDK and reload in container);
  • Change .vscode/c_cpp_properties.json to have the following includePath:
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/dbus-1.0",
                "/usr/lib/aarch64-linux-gnu/dbus-1.0/include"
            ],
  • Add these options to .vscode/tasks.json:
                "-I/usr/include/dbus-1.0",
                "-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include",
                "-ldbus-1"

After doing the steps above, try building the program. Let me know if this helps you.

Best regards,
Lucas Akira

1 Like

Thanks Lucas.
This has resolved the error seen.

Glad I was able to help!

Best regards,
Lucas Akira

Hi.

I am facing the same issue. I have tried what you have proposed, to no avail.

The tasks.json I have tried is as follows:

{
    "version": "2.0.0",
    "options": {
        "env": {
            "TORIZON_PROP_ARG": "ARG SSHUSERNAME=#%application.username%#\n"
        }
    },
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "myfile.cpp",
                "-I/usr/include/dbus-1.0",
                "-I/usr/lib/aarch64-linux-gnu/dbus-1.0/include",
                "-ldbus-1"
            ]
        }
    ]
}

I have added appropriate packages in extrapackages and devpackages, included -ldbus-1 in target link libraries.

following is my current cmakelists:

cmake_minimum_required(VERSION 3.0.0)

# set the project name
project(AppTest17WinSide VERSION 1.0)

# add the executable
add_executable(AppTest17WinSide AppTest17WinSide.cpp)

# # include directories
# target_include_directories(AppTest17WinSide 
#     PUBLIC 
#         /usr/include/dbus-1.0 
#         /usr/lib/aarch64-linux-gnu/dbus-1.0/include
# )

target_link_libraries(${PROJECT_NAME}  -lserial -lpthread -lbluetooth -lsystemd -ldbus-1)
#-lpthread is for multithreading
#-lserial is for libserial
#-lbluetooth is for libbluetooth-dev
#-lsystemd is for sdbus bluetooth

# install (please be aware that changing the target folder may lead to issues during deployment and debugging)
install(TARGETS AppTest17WinSide DESTINATION bin)

c_cpp_properties:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/libserial",
                "${workspaceFolder}/easylogging/",
                "/usr/include/dbus-1.0",
                "/usr/lib/aarch64-linux-gnu/dbus-1.0/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/${env:CC}",
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "gcc-arm64",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}

Kindly help. I have been stuck on this issue for a few days now.

Best Regards,
Hassan.

So, after another day of tracking the issue down. I managed to build to the program for another library gio and glib2.0 which was having the same issues. The solution was to edit the cmakelists to the following:

cmake_minimum_required(VERSION 3.0.0)

# set the project name
project(AppTest17WinSide VERSION 1.0)

# add the executable
add_executable(AppTest17WinSide AppTest17WinSide.cpp)

# # include directories
# target_include_directories(apptest17winside 
#     public 
#         /usr/include/dbus-1.0 
#         /usr/lib/aarch64-linux-gnu/dbus-1.0/include
# )

find_package(PkgConfig REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0 gio-2.0)

target_link_libraries(${PROJECT_NAME}  -lserial -lpthread -lbluetooth -lsystemd -lglib-2.0 PkgConfig::deps)
#-lpthread is for multithreading
#-lserial is for libserial
#-lbluetooth is for libbluetooth-dev
#-lsystemd is for sdbus bluetooth

# install (please be aware that changing the target folder may lead to issues during deployment and debugging)
install(TARGETS AppTest17WinSide DESTINATION bin)

This helps the application build and deploy but in the vscode, it gives squiggly errors that it is unable to find the header files. So confused.

Hi @geopaxpvtltd ,

It looks like you’re using V1 of the extension (Toradex Torizon Support), and you’re trying to add dbus to a CMake project, is this correct?

I was able to build and debug a basic CMake test project with dbus by doing the following:

  • Adding libdbus-1-3 in extrapackages;
  • Adding libdbus-1-dev:#%platform.debian-arch%# in devpackages;
  • Rebuilding the SDK container when prompted;
  • Adding target_include_directories and target_link_libraries to CMakeLists.txt like this:
cmake_minimum_required(VERSION 3.0.0)

# set the project name
project(dbus_test_cmake VERSION 1.0)

# add the executable
add_executable(dbus_test_cmake dbus_test_cmake.cpp)

target_include_directories(dbus_test_cmake PRIVATE /usr/include/dbus-1.0 /usr/lib/aarch64-linux-gnu/dbus-1.0/include)

target_link_libraries(dbus_test_cmake dbus-1)

# install (please be aware that changing the target folder may lead to issues during deployment and debugging)
install(TARGETS dbus_test_cmake DESTINATION bin)

For this project I didn’t alter .vscode/c_cpp_properties.json nor .vscode/tasks.json. Changing CMakeLists.txt should be enough.

I didn’t test adding all your other libraries, but you should be able to just add them to devpackages, extrapackages and include them in target_link_libraries.

See if this helps you.

Best regards,
Lucas Akira

1 Like

Hello @lucas_a.tx !

That is correct. I am using the early access version.

Thank you for your reply. I can now build and debug the project using the following changes in the cmakelists. I was also encountering similar issues with gdbus library as well. My solution was as follows:

cmake_minimum_required(VERSION 3.0.0)

# set the project name
project(AppTest17WinSide VERSION 1.0)

# add the executable
add_executable(AppTest17WinSide AppTest17WinSide.cpp)

# # include directories
# target_include_directories(apptest17winside 
#     public 
#         /usr/include/dbus-1.0 
#         /usr/lib/aarch64-linux-gnu/dbus-1.0/include
# )

find_package(PkgConfig REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0 gio-2.0)

# Add these lines for Qt5 and Qt5Bluetooth
pkg_check_modules(qtcore REQUIRED IMPORTED_TARGET Qt5Core)
pkg_check_modules(qtbluetooth REQUIRED IMPORTED_TARGET Qt5Bluetooth)
# Add these lines for libserial
pkg_check_modules(libserial REQUIRED IMPORTED_TARGET libserial)

target_link_libraries(
 ${PROJECT_NAME}  
 PkgConfig::libserial
 -lpthread 
 -lbluetooth 
 -lsystemd
 PkgConfig::deps
 PkgConfig::qtbluetooth
 PkgConfig::qtcore
 )
#-lpthread is for multithreading
#-lserial is for libserial
#-lbluetooth is for libbluetooth-dev
#-lsystemd is for sdbus bluetooth

# install (please be aware that changing the target folder may lead to issues during deployment and debugging)
install(TARGETS AppTest17WinSide DESTINATION bin)

This resolves the issue of building and debugging the project but I can not use suggestions/autocomplete features of vscode. I can not even peek definitions of functions in these libraries. It is a temporary solution. Can you suggest a solution for autocomplete/squiggles errors?

Hi @geopaxpvtltd ,

Glad you were able to build and debug your project!

This resolves the issue of building and debugging the project but I can not use suggestions/autocomplete features of vscode. I can not even peek definitions of functions in these libraries. It is a temporary solution. Can you suggest a solution for autocomplete/squiggles errors?

I was able to reproduce this behavior and I suspect this could be related to the fact that the libraries/packages were installed inside the SDK container and not on the host machine, possibly meaning that VSCode can’t see those libraries installed, so it can’t do autocomplete/suggestions.

I have passed this problem to the extension team for further discussion and investigation.

Best regards,
Lucas Akira

1 Like

Okay. Thanks for the update!

Hi @geopaxpvtltd ,

Just letting you know that the team is now prioritizing development for the IDE Extension V2.

As for your question on suggestions/autocomplete features not working, that’s because you need to specify all include paths related to your project on c_cpp_properties.json, which is a file related to VSCode in general, not limited to our extension.

For instance, you need to add these paths in the includePath key for the dbus header files:

  • /usr/lib/**
  • /usr/include/**

So your c_cpp_properties.json will be similar to the example below:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/lib/**",
                "/usr/include/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/${env:CC}",
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "gcc-arm64"
        }
    ],
    "version": 4
}

Note that this should also work for our IDE Extension V2 and any other external C/C++ VSCode project. For more details about c_cpp_properties.json please refer to the official VSCode documentation:

Best regards,
Lucas Akira

1 Like

Thank you @lucas_a.tx. I have also shifted to the V2 extension. I appreciate you for still keeping an eye on this.

1 Like