This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

undefined inline functions while using arm gnu gcc toolchain 10.2.1

I was using arm gnu gcc toolchain 6.3.1 earlier and the following piece of code compiles without any errors.

__inline unsigned int add(unsigned int i, unsigned int j)
{
        // some random sample code for example
        int ans = 0;
        for (int a = 0; a < j; a++) {
                ans = ans + 2;
        }
        for (int a = 0; a < i; a++) {
                ans = ans + 2;
        }
        for (int a = 0; a < j; a++) {
                ans = ans - 1;
        }
        for (int a = 0; a < i; a++) {
                ans = ans - 1;
        }
        return ans;
}

unsigned int add1(unsigned int i, unsigned int j)
{
    return add(i, j);
}

unsigned int add2(unsigned int i, unsigned int j)
{
    return add(i, j);
}

unsigned int add3(unsigned int i, unsigned int j)
{
    return add(i, j);
}

unsigned int add4(unsigned int i, unsigned int j)
{
    return add(i, j);
}

When when I updated the toolchain to 10.2.1 I was getting the inline function as undefined

arm-none-eabi-ld: libapps.a(hello_main.o): in function `add1':
hello/hello_main.c:84: undefined reference to `add'
arm-none-eabi-ld: libapps.a(hello_main.o): in function `add2':
hello/hello_main.c:89: undefined reference to `add'
arm-none-eabi-ld: libapps.a(hello_main.o): in function `add3':
hello/hello_main.c:94: undefined reference to `add'
arm-none-eabi-ld: libapps.a(hello_main.o): in function `add4':
hello/hello_main.c:99: undefined reference to `add'

As far as I understand, the compilers are backward compatible so I shouldn't be getting any errors for using a new toolchain version. Is there any way to fix the undefined inline functions error if possible without making any modifications to the existing code.

Parents
  • Thanks for the reply. I have thought of the same and I have disabled -Os optimization and checked, but the issue is still present. Using always inline attribute or declaring the function as static is fixing the compiler issue. I am using an open-source library that declares inline functions in the above manner and as a result, I want to avoid code modification as far as possible. Also, I want to understand what caused the issue as the only thing that was changed was the toolchain version.

Reply
  • Thanks for the reply. I have thought of the same and I have disabled -Os optimization and checked, but the issue is still present. Using always inline attribute or declaring the function as static is fixing the compiler issue. I am using an open-source library that declares inline functions in the above manner and as a result, I want to avoid code modification as far as possible. Also, I want to understand what caused the issue as the only thing that was changed was the toolchain version.

Children