getting linker error message "multiple definition of `errno'"

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

getting linker error message "multiple definition of `errno'"

Jump to solution
7,311 Views
Garry_Hoberg
Contributor II

Hello.

I just installed MCUXpresso 11.4.1 and tried to compile a project. That failed with the linker complaining:

 

c:/nxp/mcuxpressoide_11.4.1_6260/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.4.0.202103011116/tools/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld.exe: c:/nxp/mcuxpressoide_11.4.1_6260/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.4.0.202103011116/tools/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libc_nano.a(lib_a-reent.o):(.bss.errno+0x0): multiple definition of `errno'; <added line break for readability>
./lpcxpresso54628/middleware/lwip/port/sys_arch.o:C:\Users\<user name>\<project path>\Debug/../lpcxpresso54628/middleware/lwip/port/sys_arch.c:64: first defined here

 

I tried the IDE C/C++ search function and the only file outside the SDK that defines errno is C:/nxp/MCUXpressoIDE_11.4.1_6260/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.4.0.202103011116/tools/arm-none-eabi/include/sys/errno.h - That's within the IDE install path... the IDE should be well aware of this and handle it.

While MCUXpresso 11.3.1 does find that definition in the errno.h in the 11.3.1 install path it manages to build the same project without complaints.

Has anyone come across this before?

Regards.

0 Kudos
1 Solution
7,286 Views
ErichStyger
Senior Contributor V

probably unrelated:

>>I created a new ANSI-C Hello World MinGW (non-LPC) project

I'm wondering why MinGW is involved here? Comparing MinGW projects with GNU ARM Embedded is something completely different (libraries, headers, etc).

 

Anyway, you have to check your project (and settings). In my lwip there is

#ifndef errno
int errno = 0;
#endif

So it really depends if errno is defined somewhere or not: this can be with many reasons, and can be with subtle library header changes or changed include orders. Keep in mind that every IDE comes with a different version of the GNU ARM Embedded Toolchain and version, so it could be that there is a change there.

 

Erich

View solution in original post

0 Kudos
5 Replies
7,287 Views
ErichStyger
Senior Contributor V

probably unrelated:

>>I created a new ANSI-C Hello World MinGW (non-LPC) project

I'm wondering why MinGW is involved here? Comparing MinGW projects with GNU ARM Embedded is something completely different (libraries, headers, etc).

 

Anyway, you have to check your project (and settings). In my lwip there is

#ifndef errno
int errno = 0;
#endif

So it really depends if errno is defined somewhere or not: this can be with many reasons, and can be with subtle library header changes or changed include orders. Keep in mind that every IDE comes with a different version of the GNU ARM Embedded Toolchain and version, so it could be that there is a change there.

 

Erich

0 Kudos
7,259 Views
Garry_Hoberg
Contributor II

>>probably unrelated:

Yes! I was confused.

Experimented a lot. Compared config files to a similar project that works with V. 11.4.1 (same controller, RTOS, same lwIP settings, several shared files). - As soon as I set #define configUSE_NEWLIB_REENTRANT to 0 (FreeRTOSConfig.h) it all compiled fine.

I had assumed that reentrant functions are the way to go when using an RTOS. But since LWIP_TCPIP_CORE_LOCKING is 1 as well as SYS_LIGHTWEIGHT_PROT and Threads all have unique jobs to do and hardly share any ressources besides CPU this may actually work. - Still feels somewhat counter-intuitive...

I'll mark this as solution since you pointed me to check the (lwIP) configuration.

0 Kudos
2,897 Views
lh_dan
Contributor III

I ran into this same issue and would like to add that another solution is to add the '-z muldefs' option to the linker setting to allow for multiple definitions. This allows use of #define configUSE_NEWLIB_REENTRANT 1.

0 Kudos
7,296 Views
ErichStyger
Senior Contributor V

The linker complains about multiple definitions. Multiple declarations in header files are ok.

So older linker might just have ignored it or put a warning for it.

In your case you have one definition in newlib-nano (which you won't be able to easily change, and anyway that's the one which counts), and another one in your lwip: I would check the later one and remove it if necessary (unless you have mis-configured lwip and it thinks it needs to add yet another errno).

 

I hope this helps,

Erich

0 Kudos
7,294 Views
Garry_Hoberg
Contributor II

I created a new ANSI-C Hello World MinGW (non-LPC) project and added a variable named errno. It compiles fine with MCUXpresso 11.3.1 but with 11.4.1 compilation fails with "error: expected declaration specifiers or '...' before '*' token". This most likely is because errno was defined as *__errno() in that errno.h before. Code:

/*
 ============================================================================
 Name        : bla.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

uint8_t errno = 17;

int main(void) {
	while (errno)
	{
		if (errno > 10)
			errno -=2;
		else
			errno--;
	}
	puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
	return EXIT_SUCCESS;
}

I uninstalled and repeated the process of creating and trying to build that tiny project: same compiler error.

I installed Version 1.4.0 and repeated: same compiler error.

So I think lwIP configuration is not the problem here. - But why hasn't anyone else stumbled across this?