Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake uses incorrect linker #454

Open
rokas-kbit opened this issue Mar 13, 2025 · 0 comments
Open

cmake uses incorrect linker #454

rokas-kbit opened this issue Mar 13, 2025 · 0 comments

Comments

@rokas-kbit
Copy link

rokas-kbit commented Mar 13, 2025

When i try to configure my project i get this error:

[driver] Switching to configure preset: osx
[driver] Switching to build preset: osx-dbg
[driver] Switching to test preset: __defaultTestPreset__
[driver] Switching to package preset: __defaultPackagePreset__
[driver] Switching to workflow preset: __defaultWorkflowPreset__
[main] Configuring project: MyProject 
[proc] Executing command: /home/rokas/dev/osxcross_toolchain/bin/x86_64-apple-darwin23.4-cmake -DCMAKE_INSTALL_PREFIX:STRING=/home/rokas/dev/MyProject/3rdParty/cmake-build/osx/install -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE --no-warn-unused-cli -S/home/rokas/dev/MyProject -B/home/rokas/dev/MyProject/3rdParty/cmake-build/osx -G "Ninja Multi-Config"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Found OSXCROSS_HOST: x86_64-apple-darwin23.4
[cmake] -- Found OSXCROSS_TARGET_DIR: /home/rokas/dev/osxcross_toolchain/bin/..
[cmake] -- Found OSXCROSS_TARGET: darwin23.4
[cmake] -- Found OSXCROSS_SDK: /home/rokas/dev/osxcross_toolchain/bin/../SDK/MacOSX14.4.sdk
[cmake] -- The C compiler identification is Clang 18.1.3
[cmake] -- The CXX compiler identification is Clang 18.1.3
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - failed
[cmake] -- Check for working C compiler: /home/rokas/dev/osxcross_toolchain/bin/x86_64-apple-darwin23.4-clang
[cmake] -- Check for working C compiler: /home/rokas/dev/osxcross_toolchain/bin/x86_64-apple-darwin23.4-clang - broken
[cmake] CMake Error at /home/rokas/dev/deps-prefix/cmake/share/cmake-3.31/Modules/CMakeTestCCompiler.cmake:67 (message):
[cmake]   The C compiler
[cmake] 
[cmake]     "/home/rokas/dev/osxcross_toolchain/bin/x86_64-apple-darwin23.4-clang"
[cmake] 
[cmake]   is not able to compile a simple test program.
[cmake] 
[cmake]   It fails with the following output:
[cmake] 
[cmake]     Change Dir: '/home/rokas/dev/MyProject/3rdParty/cmake-build/osx/CMakeFiles/CMakeScratch/TryCompile-ibk01L'
[cmake]     
[cmake]     Run Build Command(s): /usr/bin/ninja -v cmTC_d1a8e
[cmake]     [1/2] /home/rokas/dev/osxcross_toolchain/bin/x86_64-apple-darwin23.4-clang -DCMAKE_INTDIR=\"Debug\"  -g -MD -MT CMakeFiles/cmTC_d1a8e.dir/Debug/testCCompiler.c.o -MF CMakeFiles/cmTC_d1a8e.dir/Debug/testCCompiler.c.o.d -o CMakeFiles/cmTC_d1a8e.dir/Debug/testCCompiler.c.o -c /home/rokas/dev/MyProject/3rdParty/cmake-build/osx/CMakeFiles/CMakeScratch/TryCompile-ibk01L/testCCompiler.c
[cmake]     [2/2] : && /home/rokas/dev/osxcross_toolchain/bin/x86_64-apple-darwin23.4-clang -g -Wl,-headerpad_max_install_names  CMakeFiles/cmTC_d1a8e.dir/Debug/testCCompiler.c.o -o Debug/cmTC_d1a8e   && :
[cmake]     FAILED: Debug/cmTC_d1a8e 
[cmake]     : && /home/rokas/dev/osxcross_toolchain/bin/x86_64-apple-darwin23.4-clang -g -Wl,-headerpad_max_install_names  CMakeFiles/cmTC_d1a8e.dir/Debug/testCCompiler.c.o -o Debug/cmTC_d1a8e   && :
[cmake]     /usr/bin/ld: unrecognised emulation mode: llvm
[cmake]     Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu i386pep i386pe
[cmake]     clang: error: linker command failed with exit code 1 (use -v to see invocation)
[cmake]     ninja: build stopped: subcommand failed.
[cmake]     
[cmake]     
[cmake] 
[cmake]   
[cmake] 
[cmake]   CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:2 (project)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[proc] The command: /home/rokas/dev/osxcross_toolchain/bin/x86_64-apple-darwin23.4-cmake -DCMAKE_INSTALL_PREFIX:STRING=/home/rokas/dev/MyProject/3rdParty/cmake-build/osx/install -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE --no-warn-unused-cli -S/home/rokas/dev/MyProject -B/home/rokas/dev/MyProject/3rdParty/cmake-build/osx -G "Ninja Multi-Config" exited with code: 1

cmake tries to use /usr/bin/ld for some reason. I could solve it by adding this to toolchain.cmake file:

set(CMAKE_LINKER "${OSXCROSS_TARGET_DIR}/bin/${OSXCROSS_HOST}-ld" CACHE FILEPATH "ld")
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=${CMAKE_LINKER}")
set(CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=${CMAKE_LINKER}")
set(CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=${CMAKE_LINKER}")

I was surprised that CMAKE_LINKER is not set in the toolchain. Why is that? How is linker supposed to be configured with osxcross?

Edit: this happens on Ubuntu 24.04.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant