I know there are several related posts on this topic but after going though it for the better part of all day, I am posting this question.
I am building and compiling a C ELF application (NOT C++) with clang. Everything compiles fine, but linking fails with a ton of undefined symbols starting with a underscore. These symbols are all defined in glibc at /lib/libc-2.27.so without the underscore but LLVM keeps putting the underscore in my object files. I strongly suspect I should be linking against a different libc, however, the stellar documentation has left me with no idea what this isn't working.
libtool: link: clang -I../include -I../libstuff -g -O2 -I/usr/lib64/llvm/6/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -target x86_64-pc-linux-gnu -std=c99 -stdlib=libc -I/usr/include -isystem/mnt/apple-sdk/4.6/4.6.2/SDKs/MacOSX10.7.sdk/usr/include --no-system-header-prefix=/usr/include --no-system-header-prefix=/mnt/apple-sdk/4.6/4.6.2/SDKs/MacOSX10.7.sdk/usr/include -o ar ar-append.o ar-ar.o ar-archive.o ar-contents.o ar-delete.o ar-extract.o ar-misc.o ar-move.o ar-print.o ar-replace.o -L/usr/lib64/llvm/6/lib64 ../libstuff/.libs/libstuff.a -lLLVMSymbolize -lLLVMDemangle -lLLVMSupport -lLLVMMC -lc
ar-append.o: In function `append':
/home/kwhat/NetBeansProjects/binutils-apple_new/ar/append.c:103: undefined reference to `_open'
/home/kwhat/NetBeansProjects/binutils-apple_new/ar/append.c:113: undefined reference to `_close'
Update and Solution
After reading the GCC documentation for -I, -isystem and adjusting the include ordering in my CFLAGS I was able to work around this problem. The issue ended up being that one file from the OS X include folder needed to come before /usr/include and the rest after. Examining the Plo files offered useful insight into where the includes where coming from and which ones were unexpected. In case anyone is wondering what the hell I am doing, I am refactoring an old port of cctools & ld64 for Linux to OS X cross compiling. The project currently works, but includes a lot of header hacks and unneeded patching I am trying to resolve. More info: https://github.com/kwhat/binutils-apple