undefined reference to _open when using libc with NCS 2.4.2 and above

Hello,

I am developing an application for a custom nrf52840 board. This application has been building and running without problems for nrf Connect SDK v 2.3.0

However, I recently tried to upgrade to NCS v2.5.0 and I get the below link-time error:

D:/ncs2/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp\libc.a(lib_a-openr.o): in function `_open_r':
openr.c:(.text._open_r+0x14): undefined reference to `_open'

Note that 

CONFIG_NEWLIB_LIBC=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
is set in my prj.conf. I also see these lines in autoconf.h: 
#define CONFIG_FULL_LIBC_SUPPORTED 1
#define CONFIG_MINIMAL_LIBC_SUPPORTED 1
#define CONFIG_NEWLIB_LIBC_SUPPORTED 1
#define CONFIG_PICOLIBC_SUPPORTED 1
#define CONFIG_NEWLIB_LIBC 1
#define CONFIG_HAS_NEWLIB_LIBC_NANO 1
I tried to downgrade to NCS 2.4.2, but it seems to have the same issue. However, no problems with NCS v2.3.0
Has something changed since NCS 2.4.2? Am I supposed to enable some other config flag as well, in order to use full newlib libc?
thanks
regards
pnc
  • Hello,

    following on from above query, I have tested the following setting also:

    CONFIG_NEWLIB_LIBC=y

    CONFIG_NEWLIB_LIBC_NANO=n

    However, there is no change in the situation.

    Further, I also tried 

    CONFIG_NEWLIB_LIBC=y

    CONFIG_NEWLIB_LIBC_NANO=y

    In this case, the build goes through, but I get run-time errors (divide by zero error somewhere in the Kernel code) at the startup , during Kernel boot. This might be because my application code requires the full LIBC, and not the Nano version. I am unable to debug, as the debugger also throws an exception.

    Just to repeat: this code works perfectly with NCS 2.3.0, so it is definitely some issue with 2.5.0 

    Appreciate any help, as I am badly stuck.

  • Hi, 

    CONFIG_NEWLIB_LIBC=y should not be broken in NCS 2.5.0 as far as I can see as long as all the dependencies are met. Have you also gone through the changelogs in between the releases as well as checked on the SDK main to see if there are any commits that changes this?

    I will look into this during the week, but here are at least some starting points

    Kind regards,
    Andreas

  • Hi Ahaug,

    any updates on this? I am still unable to use Newlib. The only way I can get my app to build is by setting 

    CONFIG_NEWLIB_LIBC=n

    CONFIG_NEWLIB_LIBC_NANO=n

    In this case, I presume the default Pico clib gets included. My app seems to be working. I had activated Newlib at one time for a specific reason, but probably that reason is no longer valid. But I would certainly like to have the option to use Newlib in future, and I am sure other users would too. So I request you to please look into this. Regarding the links sent by you, I had a look, but it appears impossible to figure out which change might or might not be responsible for this, there are so many of them, many of which I don't understand.

    thanks

    regards

    pnc2

  • Hi,

    Apologies for the long response time. I was out of office at the end of last week and before that I was waiting for a reply from you regarding my questions in my previous reply. 

    So to continue from here:

    1. There are changes in between NCS v2.5.0 and v2.3.0 w.r.t dependencies of this configuration. I assume you've already investigated this and checked if you have met all the dependencies?

    2. The error is also described in this Zephyr issue https://github.com/zephyrproject-rtos/zephyr/issues/41694. Have you had a look at the Zephyr forums to see if this report solves the issue?

    3. Could you provide me with the your prj.conf, the .conf from build/zephyr as well as the full build error log from the faulty compilation?

    Kind regards,
    Andreas

  • Hi AHaug,

    I checked out your references, they are all OK in my case (I have verified by looking into autoconf.h). 

    I have managed to reproduce the problem with a NORDIC board, instead of my custom board, with a tiny program. Please follow these steps to reproduce:

    clone the Hello world sample.

    Modify main.c like so:

    #include <stdio.h>
    int main(void)
    {
    printf("Hello World!\n");
    FILE *f = fopen("posix.txt","a");
    return 0;
    }

    modify prj.conf like so:

    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_NANO=n
    CONFIG_FILE_SYSTEM=y
    CONFIG_FILE_SYSTEM_LITTLEFS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_POSIX_API=y
    Create a build configuration for nrf52840dk_nrf52840
    Build, you will get this error:
    D:/ncs2/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v7e-m/nofp\libc.a(lib_a-openr.o): in function `_open_r':
    openr.c:(.text._open_r+0x14): undefined reference to `_open'
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    HOWEVER, set 
    CONFIG_NEWLIB_LIBC=n
    And it will build.
    Also, downgrade NCS to 2.3.0, and it will build.
    Hope you will be able to reproduce it now
    NOTE: the fopen is required, as that seems to be the source of the problem. In my code, I use posix calls for file IO. This is a technical requirement, in my case, I cannot avoid it. 
    regards
Related