conflicting declaration of C function 'sleep'

09 Nov 2015

My dear fellows,

I've just begun developing for Ublox' C027 board (with a Cortex-M3 based NXP LPC1768) and, for that purpose, have successfully set up Eclipse Luna 4.4.2 on Windows 7x64 with the recent GNU ARM Eclipse plugins and toolchain as kindly provided by Liviu Ionescu.

I can create and compile a 'Hello World ARM Cortex-M C/C++ Project' without problems, but as soon as I add the mbed libraries, compilation fails with the following error message:

error message

conflicting declaration of C function 'unsigned int sleep(unsigned int)':
line 188, external location: c:\program files (x86)\gnu tools arm embedded\4.9 2015q3\arm-none-eabi\include\sys\unistd.h	

previous declaration 'void sleep()'	sleep_api.h	/mbed/libraries/mbed/hal	line 41

unistd.h is included via the file /system/include/diag/trace.h from Eclipse's template. The mentioned functions headers:

sys/unistd.h sleep

unsigned _EXFUN(sleep, (unsigned int __seconds ));

mbed/hal/sleep_api.h

void sleep(void);

Do you have a hint how to solve that issue, or maybe how to work around it? I'd be glad about any suggestion - thank you in advance!

09 Nov 2015

Did you use the mbed export option to export an mbed project to your environment?

09 Nov 2015

Hi Erik,

thank you for your immediate response. I didn't - I set up a project based on Eclipse's 'Hello World ARM Cortex-M C/C++ Project' template from scratch and tried two different ways to add the mbed libraries:

  • Copy the mbed folder from an exported object to the project, and add it to the include path(s).
  • Clone the mbed git repo to a separate Eclipse project, and add it to the include path(s).

Both of them have the same build problem: unistd.h and sleep_api.h define a function named 'sleep'.

Following your presumed suggestion, I have included unistd.h to a project freshly exported from mbed, which used to work without it: there is the same build problem as soon as both mbed.h and unistd.h are included.

09 Nov 2015

Do you need include/diag/trace.h ?

The mbed HAL functions does not use any prefix, neither some functions from mbed common like error(), thus there might be conflicts with external libraries

09 Nov 2015

Hi Martin,

honestly, I'm not yet sure if I need trace.h. It has been added by Eclipse's project creation wizard to support printing of messages via the debug port. I have found some older tutorials which describe how to add debugging capabilities to a project manually, so maybe I'll give that a try in order to get working here somehow. However, that does not look like a permanent solution to me: Can I be sure unistd.h is not going to be used anywhere in the future? It seems to be pretty common...

09 Nov 2015

Common in unix, true. It'sunix standard file, which declares posix functions. More info for example here: https://developer.mbed.org/questions/4345/unistdh-missing/.

By the way, mbed provides retargeting, there's write/read defined and HAL target implementation used, thus printf() works.

10 Nov 2015

Martin, thanks for the info. That sounds as if I didn't need unistd.h indeed. As mentioned, it was used in Eclipse's project template for Cortex M3, which now seems a little strange to me. I'm trying to set up a new Eclipse project now which does not use redundant headers...