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.
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.
what are the command line options used?
In general optimizations change over toolchain versions and the default language and semantics change. In this case the library could have been depending on gnu89 (i.e. non-standard GCC specific behavior) for the `__inline` non standard attribute. To restore that behavior with newer toolchains you can use -fgnu89-inline
I used the same option -std=c99 with both the toolchains. I tested -O2 optimization with 10.2.1 and the build is successful. -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer are the other options being used.