3

Hey I am trying to compile c code that uses functions from the c11 standard library on OS X with clang.

The compiler option -std=c11 allows me to use c11 language features. But when I am using new functions like at_quick_exit I get the following warning implicit declaration of function 'at_quick_exit' is invalid in C99.

The source code has the following line #include <stdlib.h> The clang option -stdlib does not help.

My Systems:

OS X Yosemite 10.10.3

$ clang -v
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix

Ubuntu 14.04 LTS

$ clang -v
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu 
Thread model: posix

To be more explicit. How can I get on OS X a c11 standard library?

Thanks for any kind of help.

aiq
  • 51
  • 4
  • does the source code that is calling the at_quick_exit function also have the line: #include ? – user3629249 May 23 '15 at 21:49
  • Other stackoverflow questions have answers that indicate 'quick_exit()' is not implemented in OSX. My system, ubuntu 14.04, does not have 'quick_exit()' nor 'at_quick_exit()'! Both of these would be system level functions. Suggest using 'exit()' and 'atexit()' to achieve the same functionality. – user3629249 May 23 '15 at 22:09

1 Answers1

1

Typically a self-hosted system compiler alone does not provide the full Standard C environment including runtime libraries. Typically the underlying system provides most, if not all, of the libraries (and headers), while the compiler just compiles.

So, if you need some specific functions that are not provided on a given system then you will have to write them yourself, or source them from some portable library that is compatible with your target system.

In this particular case you will also probably find that quick_exit() itself is not provided by the system's libc, and so it should be easy enough to write both functions on your own.

Greg A. Woods
  • 2,663
  • 29
  • 26
  • 1
    If `foo` is the name of a standardized function, it is undefined behavior to write your own function named `foo`, so I would advise against calling the two functions with the standard names. – Pascal Cuoq May 26 '15 at 09:36
  • That's a specious argument. There's no magic in the standard that can cause any real world problems -- if it works, it works, and if it makes code compatible with future environments, even better. Ideally of course the replacement will be in a separate compilation unit, and will be selected by the build system only if the target does not already have a "standard" implementation. – Greg A. Woods May 26 '15 at 16:00