tpoechtrager / osxcross

Mac OS X cross toolchain for Linux, FreeBSD, OpenBSD and Android (Termux)
GNU General Public License v2.0
2.81k stars 320 forks source link

clang 14.0.0 fails to link when using wrapper #334

Closed ishmael1851 closed 2 years ago

ishmael1851 commented 2 years ago

Any ideas as to what might be going on? I'm not sure where the linker options (like -dynamic) are even coming from.

Simple test program.

$ more junk.c
int main(int argc, char *argv[]) {
  return 0;
}

Fails when using clang inside of osxcross wrapper

$ /usr/local/osxcross/bin/x86_64-apple-darwin21.1-clang junk.c -v
clang version 14.0.0
Target: x86_64-apple-darwin21.1
Thread model: posix
InstalledDir: /usr/local/bin
 "/usr/local/bin/clang-14" -cc1 -triple x86_64-apple-macosx10.9.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name junk.c -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -faligned-alloc-unavailable -target-sdk-version=12.0 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu core2 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 609 -v -fcoverage-compilation-dir=/local -resource-dir /usr/local/lib/clang/14.0.0 -isystem /usr/local/bin/../lib/clang/14.0.0/include -isysroot /usr/local/osxcross/bin/../SDK/MacOSX12.0.sdk -cxx-isystem /usr/local/osxcross/bin/../SDK/MacOSX12.0.sdk/usr/include/c++/v1 -internal-isystem /usr/local/osxcross/bin/../SDK/MacOSX12.0.sdk/usr/local/include -internal-isystem /usr/local/lib/clang/14.0.0/include -internal-externc-isystem /usr/local/osxcross/bin/../SDK/MacOSX12.0.sdk/usr/include -Wno-liblto -fdebug-compilation-dir=/local -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/junk-70f83c.o -x c junk.c
clang -cc1 version 14.0.0 based upon LLVM 14.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/usr/local/osxcross/bin/../SDK/MacOSX12.0.sdk/usr/local/include"
ignoring nonexistent directory "/usr/local/osxcross/bin/../SDK/MacOSX12.0.sdk/Library/Frameworks"
ignoring duplicate directory "/usr/local/bin/../lib/clang/14.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/bin/../lib/clang/14.0.0/include
 /usr/local/osxcross/bin/../SDK/MacOSX12.0.sdk/usr/include
 /usr/local/osxcross/bin/../SDK/MacOSX12.0.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/usr/bin/ld" -demangle -lto_library /usr/local/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 10.9.0 12.0 -syslibroot /usr/local/osxcross/bin/../SDK/MacOSX12.0.sdk -o a.out /tmp/junk-70f83c.o -lSystem
/usr/bin/ld: unrecognized option '-dynamic'
/usr/bin/ld: use the --help option for usage information
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

Works when using clang without wrapper.

$ /usr/local/bin/clang junk.c -v
clang version 14.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/local/bin/clang-14" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name junk.c -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/local -resource-dir /usr/local/lib/clang/14.0.0 -internal-isystem /usr/local/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/local -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/junk-9ddc4e.o -x c junk.c
clang -cc1 version 14.0.0 based upon LLVM 14.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/clang/14.0.0/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
 "/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /lib/x86_64-linux-gnu/crt1.o /lib/x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/10/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/10 -L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/usr/local/bin/../lib -L/lib -L/usr/lib /tmp/junk-9ddc4e.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/10/crtend.o /lib/x86_64-linux-gnu/crtn.o
tpoechtrager commented 2 years ago

Make sure /usr/local/osxcross/bin is in PATH.

ishmael1851 commented 2 years ago

That was it. Thank you!

vitamin-caig commented 1 year ago

Hello!

Apparently I have the same problem with clang-11 while building boost libraries:

environment is ok:

$ env | grep PATH
PATH=/build/toolchains/osxcross/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
0$ "/build/toolchains/osxcross/bin/x86_64-apple-darwin20.4-clang++"  -o "bin.v2/libs/locale/build/clang-linux-osxcross/release/link-static/target-os-darwin/threading-multi/visibility-hidden/has_external_iconv"    "bin.v2/libs/locale/build/clang-linux-osxcross/release/link-static/target-os-darwin/threading-multi/visibility-hidden/has_external_iconv_obj.o"     -liconv  -m64 -fvisibility=hidden -fvisibility-inlines-hidden --target=x86_64-apple-darwin -v
Debian clang version 11.0.1-2
Target: x86_64-apple-darwin
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/ld" -demangle -lto_library /usr/lib/llvm-11/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 10.9.0 11.3 -syslibroot /build/toolchains/osxcross/bin/../SDK/MacOSX11.3.sdk -o bin.v2/libs/locale/build/clang-linux-osxcross/release/link-static/target-os-darwin/threading-multi/visibility-hidden/has_external_iconv bin.v2/libs/locale/build/clang-linux-osxcross/release/link-static/target-os-darwin/threading-multi/visibility-hidden/has_external_iconv_obj.o -liconv -lc++ -lSystem
/usr/bin/ld: unrecognized option '-dynamic'
/usr/bin/ld: use the --help option for usage information
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have no idea why compiler invokes default ld binary instead of provided in osxcross.

Could you please help?

UPD: looks like --target=x86_64-apple-darwin key in final invocation breaks the thing.