Skip to content

Instantly share code, notes, and snippets.

@kimuraw
Created August 8, 2012 14:29
Show Gist options
  • Save kimuraw/3295469 to your computer and use it in GitHub Desktop.
Save kimuraw/3295469 to your computer and use it in GitHub Desktop.
clang-3.1 or later (trunk) cannot generate an execute file

On Mac OS X 10.8 Mountain Lion, clang-3.1 does not work.

clang-3.1 (MacPorts)

% cat a.c
int main() {
return 0;
}
% clang-mp-3.1 --version     # MacPorts port:clang-3.1
clang version 3.1 (branches/release_31)
Target: x86_64-apple-darwin12.0.0
Thread model: posix
% clang-mp-3.1 a.c
Undefined symbols for architecture x86_64:
  "start", referenced from:
 -u command line option
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
% clang-mp-3.1 -lcrt1.o a.c
% # it looks to be missing "start" in crt1.o.

clang-3.0 (MacPorts)

% clang-mp-3.0 --version     # MacPorts port:clang-3.0
clang version 3.0 (tags/RELEASE_30/final)
Target: x86_64-apple-darwin12.0.0
Thread model: posix
% clang-mp-3.0 a.c
% # compile succeed

clang-3.1 (Apple Xcode-4.4.1)

% /usr/bin/clang --version   # Xcode 4.4.1
Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.0.0
Thread model: posix
% /usr/bin/clang a.c
% # compile succeed

I guess the change of lib/Drivers/Tools.cpp at r152137( https://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?r1=152137&r2=152136&pathrev=152137 ) caused this problem.

@@ -4025,7 +4032,7 @@
	     CmdArgs.push_back("-lcrt1.o");
	   else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
	     CmdArgs.push_back("-lcrt1.10.5.o");
-              else
+              else if (getDarwinToolChain().isMacosxVersionLT(10, 8))
	     CmdArgs.push_back("-lcrt1.10.6.o");
 
	   // darwin_crt2 spec is empty.

I think this change should be reverted.

@msmhrt
Copy link

msmhrt commented Aug 9, 2012

$ /usr/bin/clang -c a.c -o a.o
$ /usr/bin/ld a.o -o a.out
ld: warning: -macosx_version_min not specified, assuming 10.7
Undefined symbols for architecture x86_64:
  "start", referenced from:
     -u command line option
ld: symbol(s) not found for inferred architecture x86_64
$ # failed
$ /usr/bin/clang a.o -o a.out
$ # succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment