Compile active file in VS Code

Sometimes I just want to compile a single file for an nRF Connect project with VS Code and the nRF Connect extension. This sometimes fails because an include file isn't found (for example <app_event_manager_priv.h> included from app_event_manager.h in my case). The file compiles fine when the whole project is built from the nRF Connect extension but not with the 'Compile Active File' function. In the terminal output I see that a lot of '-I<folder>' arguments is given to the 'arm-zephyr-eabi-gcc.exe' compiler but no path covers the <app_event_manager_priv.h> file.

I get the error when the file <app_event_manager.h> is included somewhere in my include hierarchy for a .c file.

Which file or setting do I need to edit to add include paths for the 'Compile Active File' function?

I have added includepaths to the c_cpp_properties.json which works when the whole project is built but these include paths does not seem to be used when running 'Compile Active File'.

The file app_event_manager_priv.h lives in ${workspaceFolder}/nrf/subsys/app_event_manager

Best regards /Ruben

Parents
  • Hi,

    Sometimes I just want to compile a single file for an nRF Connect project with VS Code and the nRF Connect extension.

    Could you provide information why you want to compile single file? Is this single file already a part of existing NCS project?

    This sometimes fails because an include file isn't found

    As it sometimes fails, I assume it sometimes succeeds. What do you do differently that could lead to these 2 completely different outcomes?

    Best regards,
    Dejan

  • Could you provide information why you want to compile single file? Is this single file already a part of existing NCS project?

    When I refactor a larger project containing many source files, and I haven't built the whole project for a while, there could be a lot of output in the terminal during the build if something is wrong (especially for simple typos in the macros in zephyr, e.g. LOG_INF and others) it is nice to simply just compile the single file I am currently working on.

    As it sometimes fails, I assume it sometimes succeeds. What do you do differently that could lead to these 2 completely different outcomes?

    It is not random but depending on the file being compiled. For any given file it always either succeeds or always fails. In my case it always fails if the file app_event_manager.h is included which leads to error: .../nrf/include/app_event_manager.h:27:10: fatal error: app_event_manager_priv.h: No such file or directory

    Which leads to my question: 

    Which file or setting do I need to edit to add include paths for the 'Compile Active File' function?

    Thanks /Ruben

  • Hi Ruben,

    MaxRuben said:
    It is not random but depending on the file being compiled. For any given file it always either succeeds or always fails. In my case it always fails if the file app_event_manager.h is included which leads to error: .../nrf/include/app_event_manager.h:27:10: fatal error: app_event_manager_priv.h: No such file or directory

    Could you show how you do this? Some screenshots with descriptions of both working and non-working case could be useful.

    Best regards,
    Dejan

  • Found the problem: Turns out I had missed setting CONFIG_APP_EVENT_MANAGER=y in a .conf file and after doing a pristine build it seems to work to also Compile Active File for files that include app_event_manager.h

    /Ruben

  • Hi Ruben, 

    Thank you for the update.

    Did you refer to "Run Active File" when you mentioned "Compile Active File"?

    Best regards,
    Dejan

  • No 'Compile Active File'.

    From the context menu when right clicking on the tab for the file in the editor or with the 'Compile Active File' action button for the active file in the editor.

    /Ruben

  • Hi Ruben,

    I do not see this "Compile Active File" command. I do not have the tab for the file in the editor nor does this command appear when right-clicking on the active file. I have asked internally, and it seems that we do not have "Compile Active File" command. It might be that this command came with some other extension which you installed on your system.

    Best regards,
    Dejan


Reply
  • Hi Ruben,

    I do not see this "Compile Active File" command. I do not have the tab for the file in the editor nor does this command appear when right-clicking on the active file. I have asked internally, and it seems that we do not have "Compile Active File" command. It might be that this command came with some other extension which you installed on your system.

    Best regards,
    Dejan


Children
  • Ah, I see. The Compile Active File is provided by the CMake Tools extension which I thought was working well together with the nRF Connect extension. But after some googling and searching in the Nordic Dev Zone I see that these two extensions might not work very well together.

    This is probably why the 'Compile Active File' action didn't work at my end to begin with.

    When I disable the CMake Tools extension, 'Compile Active File' is not available any more.

    This is probably also why 'Compile Active File' isn't working for me after some changes until I make a Pristine Build but then it really makes no sense to compile a single file anymore.

    As I said before, the original reason for me to want to compile just a single file was that for some simple errors or typos in the Zephyr macros, hundreds and hundreds of lines with warnings and errors is  produced in the terminal output and being able to compile one file at a time does sometimes help here.

    Sorry for wasting your (and my) time with this.

    Thanks /Ruben

  • Hi Ruben,

    There is no need to be sorry. Thank you for the update.

    Best regards,
    Dejan

Related