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

Meson fails to detect linker with llvm/clang #13894

Open
ClayCore opened this issue Nov 11, 2024 · 4 comments
Open

Meson fails to detect linker with llvm/clang #13894

ClayCore opened this issue Nov 11, 2024 · 4 comments

Comments

@ClayCore
Copy link

Describe the bug
Running meson setup build in a correctly set up project fails due to the linker being missing.
Linker's not missing though, but meson thinks it is. Before upgrading python and meson this wasn't causing any issues, however I don't remember the exact versions for either.

Error thats shown in the command line after executing meson setup build

The Meson build system
Version: 1.6.0
Source dir: S:\wplace\c\db_kv\trunk
Build dir: S:\wplace\c\db_kv\trunk\build
Build type: native build
Project name: db
Project version: 0.1.0

meson.build:1:0: ERROR: Unable to detect linker for compiler `clang -Wl,--version`
stdout:
stderr: clang: error: unable to execute command: program not executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The log meson is referring to:

meson-logs\meson-log.txt
Build started at 2024-11-11T11:38:52.908467
Main binary: S:\wplace\sdk\Python\Python312\python.exe
Build Options: 
Python system: Windows
The Meson build system
Version: 1.6.0
Source dir: S:\wplace\c\db_kv\trunk
Build dir: S:\wplace\c\db_kv\trunk\build
Build type: native build
Project name: db
Project version: 0.1.0
-----------
Detecting compiler via: `icl ""` -> [WinError 2] Nie można odnaleźć określonego pliku
-----------
Detecting compiler via: `cl /?` -> [WinError 2] Nie można odnaleźć określonego pliku
-----------
Detecting compiler via: `cc --version` -> [WinError 2] Nie można odnaleźć określonego pliku
-----------
Detecting compiler via: `gcc --version` -> [WinError 2] Nie można odnaleźć określonego pliku
-----------
Detecting compiler via: `clang --version` -> 0
stdout:
clang version 18.1.0rc
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: S:\wplace\sdk\compilers\clang\bin
-----------
Running command: -x c -E -dM -
-----
-----------
Detecting linker via: `clang -Wl,--version` -> 1
stderr:
clang: error: unable to execute command: program not executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-----------
-----------
Detecting Apple linker via: `clang -Wl,-v` -> 1
stderr:
clang: error: unable to execute command: program not executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-----------

meson.build:1:0: ERROR: Unable to detect linker for compiler `clang -Wl,--version`
stdout: 
stderr: clang: error: unable to execute command: program not executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)

To Reproduce
Here's the meson.build file

project(
    'db',
    ['c'],
    version: '0.1.0',
    default_options: [
        'c_std=c17',
        'buildtype=debug',
        'warning_level=3',
    ]
)

compiler = meson.get_compiler('c')
os = host_machine.system()

if os == 'windows'
  add_project_arguments('-DDB_W32', language: 'c')
else
  add_project_arguments('-DDB_UNIX', language: 'c')
endif

add_project_arguments('-Wno-dollar-in-identifier-extension', language: 'c')

include_dirs = [
    include_directories('src')
]

sources = [
    'src/main.c'
]

deps = []

libmath = compiler.find_library('m', required: false)
deps += libmath

executable(
    'db',
    sources,
    include_directories: include_dirs,
    dependencies: deps,
)

Expected behavior
I expected the linker to be found, since it's in the same directory as the compiler executable and clang is properly setup.

system parameters
This is not a cross compiled build.
Windows 10 1809
python 3.12.6
meson 1.6.0
clang 18.1.0rc

@subhacom
Copy link

subhacom commented Nov 19, 2024

I am encountering the same problem when trying to use meson via cibuildwheel on Windows.

The final error line is

Error: Command ['python', '-m', 'pip', 'wheel', 'C:\\Users\\raysu\\Documents\\src\\moose-core', '--wheel-dir=C:\\Users\\raysu\\AppData\\Local\\Temp\\cibw-run-zjafth6c\\cp39-win32\\built_wheel', '--no-deps'] failed with code 1.

However, it works if I directly run pip install . or pip -w dist-dir wheel . from the command line.

I have the same meson version: 1.6.0, I also have meson-python 0.17.1, vc14-runtime, and vs2015_runtime installed in the build environment.

Edit: On a double check, pip -w dist-dir wheel . does not work in this environment.

@dnicolodi
Copy link
Member

@subhacom What makes you think your problem is related to this issue? The error message you report does not say anything about what made the wheel building fail. Please enable verbose logging in pip and report the relevant part of the build log.

@subhacom
Copy link

@dnicolodi I actually got the exact same error earlier (though I only mentioned the final line): ERROR: Unable to detect linker for compiler 'clang -Wl,--version'.
However this went away in a fresh environment with clang installed from conda-forge. Not sure if the clang that came with LLVM was the culprit.

@ClayCore
Copy link
Author

Seemingly unrelated, however the clangd plugin in my VSCode install was also broken.
The issue is here: clangd/2218

In this issue we tackle some of the possible fixes, in the midst of it all there is a suggestion of launching VSCode from a vcvarsall.bat enabled shell, which helps clangd figure out where some system headers are and actually fixed the issue, at least for the time being.

In the same vein I tried launching meson with CC=clang, but from a vcvarsall enabled shell, and it successfully detected the linker, without this error.

It's worth pointing out that I also got meson to recognize clang and its linker by launching it from an MSYS2 Shell, where I installed the LLVM toolkit separately from the main windows binaries, and it also works there, so to me this detection issue is because clang, clangd, meson and alike are having some real troubles finding the appropriate includes scattered across various paths in the system.
No idea why it suddenly happened after upgrading some software, since I was able to run meson and such without this ritual before.

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

3 participants