michaeleisel / zld

A faster version of Apple's linker
MIT License
1.19k stars 50 forks source link

Cannot build from source #84

Closed lechuckcaptain closed 3 years ago

lechuckcaptain commented 3 years ago

I'm trying to build from source the project following the instructions in the README file but I have several issues.

Building from source
Install Xcode 12.2+ and run sudo xcode-select -s <path to Xcode>
Install cmake
Checkout the latest release of zld from master
Run make clean && make

I attached in the following gist the log files. It seems that running the command make clean && make the compilation fails for some missing dependency library. If I run make again without cleaning the compilation makes some steps again but fails without finding corecrypto dependencies (that gets deleted on the clean, is it correct?).

https://gist.github.com/lechuckcaptain/aafdc3877caa2fb8a7f10454af4f4336

I also tried to reset the repo, and run only the make command without any clean. I gets at first the same error of missing some dependency library, but on the second make I get a different error this time. Please find some info in this second gist:

https://gist.github.com/lechuckcaptain/49624151b8974f88576b6e661c873418

Do you have any idea what could be the issue?

michaeleisel commented 3 years ago

what macos version are you on?

lechuckcaptain commented 3 years ago

Sorry for that, I forgot to write those details. I'm running macOS Big Sur 11.2.3 and selected Xcode 12.4.0

image

/Applications/Xcode-12.4.0.app/Contents/Developer

michaeleisel commented 3 years ago

i see now, fixed in https://github.com/michaeleisel/zld/commit/788f44971b0634114453df14a2848512758e3f52

lechuckcaptain commented 3 years ago

I confirm that 788f449 does fixes the issue related to missing corecrypto dependency. Still not able to compile for the same error reported above. On the first make I get the following error:

ar rcs libtbb.a concurrent_hash_map.o concurrent_queue.o concurrent_vector.o dynamic_link.o itt_notify.o cache_aligned_allocator.o pipeline.o queuing_mutex.o queuing_rw_mutex.o reader_writer_lock.o spin_rw_mutex.o x86_rtm_rw_mutex.o spin_mutex.o critical_section.o mutex.o recursive_mutex.o condition_variable.o tbb_thread.o concurrent_monitor.o semaphore.o private_server.o rml_tbb.o tbb_misc.o tbb_misc_ex.o task.o task_group_context.o governor.o market.o arena.o scheduler.o observer_proxy.o tbb_statistics.o tbb_main.o concurrent_vector_v2.o concurrent_queue_v2.o spin_rw_mutex_v2.o task_v2.o     -L/usr/local/opt/openssl@1.1/lib
ar: -L/usr/local/opt/openssl@1.1/lib: No such file or directory
make[2]: *** [libtbb.a] Error 1
make[2]: *** Deleting file `libtbb.a'
make[1]: *** [tbb] Error 2
make: *** [tbb_staticlib] Error 2

If I try to re run the make I get a different error, but probably related to the first one that's failed.

Ld /Users/marco.pagliari/git/zld/build/Build/Intermediates.noindex/zld.build/Release/zld.build/Objects-normal/x86_64/Binary/zld normal x86_64 (in target 'zld' from project 'zld')
    cd /Users/marco.pagliari/git/zld/ld
    /Applications/Xcode-12.4.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos10.14 -isysroot /Applications/Xcode-12.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -L/Users/marco.pagliari/git/zld/build/Build/Products/Release -L/Users/marco.pagliari/git/zld/ld -L/Applications/Xcode-12.4.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/usr/lib/system -F/Users/marco.pagliari/git/zld/build/Build/Products/Release -filelist /Users/marco.pagliari/git/zld/build/Build/Intermediates.noindex/zld.build/Release/zld.build/Objects-normal/x86_64/zld.LinkFileList -Xlinker -rpath -Xlinker @executable_path -Xlinker -rpath -Xlinker /var/db/xcode_select_link/Toolchains/XcodeDefault.xctoolchain/usr/lib -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib -Xlinker -rpath -Xlinker /usr/local/lib -dead_strip -Xlinker -object_path_lto -Xlinker /Users/marco.pagliari/git/zld/build/Build/Intermediates.noindex/zld.build/Release/zld.build/Objects-normal/x86_64/zld_lto.o -stdlib\=libc++ -fobjc-link-runtime -Wl,-U,_malloc_default_purgeable_zone -Wl,-t -Wl,-U,_fnd_get_demangled_name -Wl,-client_name,ld -Wl,-alias,_zldVersionString,_ldVersionString -Wl,-all_load -Wl,/Users/marco.pagliari/git/zld/ld/../abseil-cpp-20200225/build/libabsl.a -stdlib\=libc++ -lxar -Wl,-lazy_library,/Applications/Xcode-12.4.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -Wl,-exported_symbol,__mh_execute_header -L/Applications/Xcode-12.4.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib -ltapi -Wl,-stack_size,0x01000000 -lLTO -ltbb -lswiftDemangle -Xlinker -dependency_info -Xlinker /Users/marco.pagliari/git/zld/build/Build/Intermediates.noindex/zld.build/Release/zld.build/Objects-normal/x86_64/zld_dependency_info.dat -o /Users/marco.pagliari/git/zld/build/Build/Intermediates.noindex/zld.build/Release/zld.build/Objects-normal/x86_64/Binary/zld
ld: warning: directory not found for option '-L/Users/marco.pagliari/git/zld/build/Build/Products/Release'
ld: warning: directory not found for option '-F/Users/marco.pagliari/git/zld/build/Build/Products/Release'
ld: warning: -lazy_library is deprecated, changing to regular link
ld: library not found for -ltbb
clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **

The following build commands failed:
    Ld /Users/marco.pagliari/git/zld/build/Build/Intermediates.noindex/zld.build/Release/zld.build/Objects-normal/x86_64/Binary/zld normal x86_64
(1 failure)
make: *** [build] Error 65
michaeleisel commented 3 years ago

That -L/usr/local/opt/openssl@1.1/lib is odd, I'm not sure where that's coming from. When I grep through the repo, even post-build, I don't see openssl outside of the misc/ dir. Are you doing a git clean -dfx before trying? And how is this openssl term being inserted?

Also, what is your use-case for building rather than downloading a pre-built binary?

lechuckcaptain commented 3 years ago

It was related to a homebrew suggestion after the install of openssl library. Adding the following environment variables made the build fail in some way.

LDFLAGS=-L/usr/local/opt/openssl@1.1/lib
CPPFLAGS=-I/usr/local/opt/openssl@1.1/include
PKG_CONFIG_PATH=/usr/local/opt/openssl@1.1/lib/pkgconfig

Anyway thanks to your answer I managed to try to remove them and the build worked flawlessly.

To answer your second question, the issue of the pre-built binary is that it cannot be easily installed on CI setup without having super user rights, in order to circumvent Apple Gatekeeper and quarantine (but maybe there is a better solution also to that).

That's the script I was running locally at the moment, that is requiring super user rights:

rm -rf /tmp/zld; mkdir /tmp/zld; cd /tmp/zld
wget -c https://github.com/michaeleisel/zld/releases/download/1.3.0/zld.tar.gz
tar -xzvf zld.tar.gz
cp zld /usr/local/bin
sudo spctl --add --label "zld" /usr/local/bin/zld
sudo spctl --enable --label "zld"
xattr -r -d com.apple.quarantine /usr/local/bin/zld 
rm -rf /tmp/zld