Fatal error: nuttx/config.h: No such file or directory

I am trying to add a library testlib, and a module testmod into the px4 environment. The CMakeLists.txt of testlib looks like

cmake_minimum_required(VERSION 3.1)
project(testlib CXX)
add_library(testlib
    src/testlib.cpp
    include/testlib.h
)
target_include_directories(testlib PUBLIC include)

and CMakeListst.txt does

cmake_minimum_required(VERSION 3.1)
px4_add_module(
    MODULE testmod
    MAIN testmod
    SRCS testmod.cpp
    DEPENDS testlib
)

But while building

$ make px4_fmu-v5_default

I’ve got the error message

[1/1219] Building CXX object src/lib/testlib/CMakeFiles/testlib.dir/src/testlib.cpp.obj
FAILED: src/lib/testlib/CMakeFiles/testlib.dir/src/testlib.cpp.obj 
...
In file included from ../../src/include/visibility.h:85:0,
                 from <command-line>:0:
NuttX/nuttx/include/time.h:43:10: fatal error: nuttx/config.h: No such file or directory
 #include <nuttx/config.h>
          ^~~~~~~~~~~~~~~~
compilation terminated.
[10/1219] Generating uORB topic headers
ninja: build stopped: subcommand failed.
Makefile:193: recipe for target 'px4_fmu-v5_default' failed
make: *** [px4_fmu-v5_default] Error 1

All the files testmod.cpp, testlib.cpp, testlib.h contain minimum of code
testlib.h:

#pragma once
int func();

testlib.cpp

#include "testlib.h"
int func() { return 0; }

What is the problem?

2 Likes

This appears to be solved from v1.11.0 on.

PX4 uses it’s own px4_add_library CMake function instead of “add_library”, for it’s dependency:

If you change that in the CMakeLists.txt, that should resolve the compile error!