offsets.h No such file or directory

Hi, 

We have been using SDK version 2.1.1 and currently are in the process of migrating to SDK version 2.5.0.

Would be helpful to get some hint regarding what conditions can lead to the following error when building our application.

In file included from C:\ncs\v2.5.0\zephyr\include\zephyr\app_memory\app_memdomain.h:9,
from C:\ncs\v2.5.0\zephyr\include\zephyr\rtio\rtio.h:31,
from C:\ncs\v2.5.0\zephyr\include\zephyr\drivers\i2c.h:28,
from <our application.h>...
C:\ncs\v2.5.0\zephyr\include\zephyr\linker\linker-defs.h:26:10: fatal error: offsets.h: No such file or directory
26 | #include <offsets.h>
| ^~~~~~~~~~~

Thanks,

Mathi.

  • In which file do you have add_subdirectory?

    If you have a look at https://github.com/nrfconnect/ncs-example-application, you can see that add_subdirectory is used in the "top directory" and the driver/ directory, but not in the app/ directory.

    Maybe you have add_subdirectory in your app/ directory while you should instead use the same structure as the example application?

  • In my case, the add_directory is in the CMakeLists at the top level, which calls up add_directory in a drivers folder, and so on down the tree. The core source files themselves are included in the same top level CMakeLists using target_sources instead.

    I'm not sure the example is a useful structure in this case - it's specifically designed to demonstrate modules (which is what the top level CMakeLists is for), and requires the developer to specify the app directory explicitly when building the app. The app itself doesn't actually use add_directory as far as I can tell.

  • This one irritated me long enough to find a fix myself. Details over on Zephyr's GitHub, but basically:

    This is due to source files you add to the project via add_subdirectory not picking up the pre-build dependencies correctly. So ninja helpfully starts building everything at once, in parallel, intermittently bombing out when the pre-build output files haven't yet appeared. Only randomness comes to the rescue, eventually producing the output files before they're required for input.

    The solution is to add add_dependencies(LIBRARY_NAME, offsets_h) to your CMakeLists.txt file.

    The library name is generated by the CMakeLists.txt file that includes the source files, using zephy_library() and friends. The Zephyr naming convention is derived from the path, like drivers__input__input_gpio_keys. But for out-of-tree drivers you'll have to check what name has been given - you should be able to make it out from the build command above the "fatal error" message.

  • I think I solved both of my issues with a simple solution, and not having to refactor for using the structure demonstrated in the ncs-example-application, by simply adding following line in my root makefile:

    list(APPEND EXTRA_ZEPHYR_MODULES
      ${CMAKE_CURRENT_SOURCE_DIR}/custom_mp2731_driver
    )

    I previously had add_subdirectory() in that makefile.

    BR

  • Does this work  even if your driver is not a module, as such? If so, maybe that method should always be used instead of add_directory, for code with its own CMakeLists.txt that targets Zephyr?

Related