Project

General

Profile

Bug #11507

clang-40 can't compile a simple C or C++ program: clang: error: linker command failed with exit code 1

Added by Vedran Miletić 22 days ago. Updated 17 days ago.

Status:
New
Priority:
Normal
Assignee:
Category:
OI-Userland
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
clang

Description

int main()
{
    return 0;
}

Trying to compile gives:

$ clang example.c
ld: fatal: file crtbegin.o: open failed: No such file or directory
ld: fatal: library -lgcc: not found
ld: fatal: file crtend.o: open failed: No such file or directory
ld: fatal: file processing errors. No output written to a.out
clang: error: linker command failed with exit code 1 (use -v to see invocation)

$ clang++ example.cpp
ld: fatal: file crtbegin.o: open failed: No such file or directory
ld: fatal: library -lgcc: not found
ld: fatal: file crtend.o: open failed: No such file or directory
ld: fatal: file processing errors. No output written to a.out
clang: error: linker command failed with exit code 1 (use -v to see invocation)

After adding -L:

$ clang -L/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4 example.c
ld: fatal: file crtbegin.o: open failed: No such file or directory
ld: fatal: file crtend.o: open failed: No such file or directory
ld: fatal: file processing errors. No output written to a.out
clang: error: linker command failed with exit code 1 (use -v to see invocation)

$ clang++ -L/usr/gcc/4.9/lib/gcc/i386-pc-solaris2.11/4.9.4 example.cpp
ld: fatal: file crtbegin.o: open failed: No such file or directory
ld: fatal: file crtend.o: open failed: No such file or directory
ld: fatal: file processing errors. No output written to a.out
clang: error: linker command failed with exit code 1 (use -v to see invocation)

History

#1

Updated by Rich Lowe 21 days ago

It's trying to use crtbegin.o and crtend.o without specifying a path. They're not looked for via the search paths.

Clang is doing:
"/usr/bin/ld" -C -e _start -Bdynamic --dynamic-linker /usr/lib/amd64/ld.so.1 -o break /usr/lib/amd64/crt1.o /usr/lib/amd64/crti.o /usr/lib/amd64/values-Xa.o crtbegin.o -L/usr/bin -L/usr/clang/4.0/bin -L/usr/clang/4.0/bin/../lib -L/usr/lib/amd64/ /var/tmp/break-b1ece0.o -lgcc_s -lc -lgcc -lm crtend.o /usr/lib/amd64/crtn.o

Which is clearly wrong in a number of ways..

#2

Updated by Rick V 21 days ago

Currently using a self-built Apple C++ 8.0, requires llvm, libunwind, and compiler-rt at a minimum, and can use existing libstdc++, lib[mtsk|gomp] for OpenMP, and polly. From compiler-rt you need builtins, and the [start|stop]_sancov_guards targets. Sanitisers are broken on Solaris 11 Express (which includes all illumos), triggers a static compile-time assertion indicating that glob_t isn't the same size (inexplicably, as a careful reading of documentation and headers on illumos vs Solaris 11.4 don't seem to indicate any size or layout difference)

upstream Apple libc++ is broken, and I've only seen patched in pkgsrc by Samsung

#4

Updated by Alexander Pyhalov 17 days ago

Clang 8.0.1 has been published to the repository. Clang 4.0.1 has been removed. Can you check if clang-80 works for you?

Also available in: Atom PDF