rust-bindgen: Unable to open homebrew llvm's libclang shared library, missing symbol
Problem description
I’m using bindgen 0.53.2 and I installed llvm from homebrew, and pointed bindgen at it with the following, which has worked for me in the past.
let key = "LLVM_CONFIG_PATH";
env::set_var(key, env::var(key).unwrap_or("/usr/local/opt/llvm/bin/llvm-config".to_string()));
However, when I try and run cargo build (I’m using bindgen in build.rs), bindgen panics and complains that it cannot find the __ZTIN4llvm23MCAsmParserSemaCallbackE symbol in /usr/local/opt/llvm@10/lib/libclang.dylib, and that symbol is expected because of /Users/camdennarzt/.rustup/toolchains/stable-x86_64-apple-darwin/lib/libLLVM.dylib.
Input C Headers
I know that I’m not supposed to show a header with includes here, but I’m pretty sure that the header isn’t the problem (I don’t think bindgen gets that far).
/*
* Copyright (c) 2006, 2007, 2010 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _LIBPROC_H_
#define _LIBPROC_H_
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/resource.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/proc_info.h>
#include <Availability.h>
/*
* This header file contains private interfaces to obtain process information.
* These interfaces are subject to change in future releases.
*/
/*!
* @define PROC_LISTPIDSPATH_PATH_IS_VOLUME
* @discussion This flag indicates that all processes that hold open
* file references on the volume associated with the specified
* path should be returned.
*/
#define PROC_LISTPIDSPATH_PATH_IS_VOLUME 1
/*!
* @define PROC_LISTPIDSPATH_EXCLUDE_EVTONLY
* @discussion This flag indicates that file references that were opened
* with the O_EVTONLY flag should be excluded from the matching
* criteria.
*/
#define PROC_LISTPIDSPATH_EXCLUDE_EVTONLY 2
__BEGIN_DECLS
/*!
* @function proc_listpidspath
* @discussion A function which will search through the current
* processes looking for open file references which match
* a specified path or volume.
* @param type types of processes to be searched (see proc_listpids)
* @param typeinfo adjunct information for type
* @param path file or volume path
* @param pathflags flags to control which files should be considered
* during the process search.
* @param buffer a C array of int-sized values to be filled with
* process identifiers that hold an open file reference
* matching the specified path or volume. Pass NULL to
* obtain the minimum buffer size needed to hold the
* currently active processes.
* @param buffersize the size (in bytes) of the provided buffer.
* @result the number of bytes of data returned in the provided buffer;
* -1 if an error was encountered;
*/
int proc_listpidspath(uint32_t type,
uint32_t typeinfo,
const char *path,
uint32_t pathflags,
void *buffer,
int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
int proc_listpids(uint32_t type, uint32_t typeinfo, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
int proc_listallpids(void * buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_1);
int proc_listpgrppids(pid_t pgrpid, void * buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_1);
int proc_listchildpids(pid_t ppid, void * buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_1);
int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
int proc_pidfdinfo(int pid, int fd, int flavor, void * buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
int proc_pidfileportinfo(int pid, uint32_t fileport, int flavor, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
int proc_name(int pid, void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
int proc_regionfilename(int pid, uint64_t address, void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
int proc_kmsgbuf(void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
int proc_pidpath(int pid, void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
int proc_libversion(int *major, int * minor) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
/*
* Return resource usage information for the given pid, which can be a live process or a zombie.
*
* Returns 0 on success; or -1 on failure, with errno set to indicate the specific error.
*/
int proc_pid_rusage(int pid, int flavor, rusage_info_t *buffer) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
/*
* A process can use the following api to set its own process control
* state on resoure starvation. The argument can have one of the PROC_SETPC_XX values
*/
#define PROC_SETPC_NONE 0
#define PROC_SETPC_THROTTLEMEM 1
#define PROC_SETPC_SUSPEND 2
#define PROC_SETPC_TERMINATE 3
int proc_setpcontrol(const int control) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
int proc_setpcontrol(const int control);
int proc_track_dirty(pid_t pid, uint32_t flags);
int proc_set_dirty(pid_t pid, bool dirty);
int proc_get_dirty(pid_t pid, uint32_t *flags);
int proc_clear_dirty(pid_t pid, uint32_t flags);
int proc_terminate(pid_t pid, int *sig);
#ifdef PRIVATE
#include <sys/event.h>
/*
* Enumerate potential userspace pointers embedded in kernel data structures.
* Currently inspects kqueues only.
*
* NOTE: returned "pointers" are opaque user-supplied values and thus not
* guaranteed to address valid objects or be pointers at all.
*
* Returns the number of pointers found (which may exceed buffersize), or -1 on
* failure and errno set appropriately.
*/
int proc_list_uptrs(pid_t pid, uint64_t *buffer, uint32_t buffersize);
int proc_list_dynkqueueids(int pid, kqueue_id_t *buf, uint32_t bufsz);
int proc_piddynkqueueinfo(int pid, int flavor, kqueue_id_t kq_id, void *buffer,
int buffersize);
#endif /* PRIVATE */
int proc_udata_info(int pid, int flavor, void *buffer, int buffersize);
__END_DECLS
#endif /*_LIBPROC_H_ */
Bindgen Invocation
bindgen::Builder::default()
.header("/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libproc.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings")
.write_to_file(PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs"))
.expect("Couldn't write bindings!");
Actual Results
Compiling get_args v0.1.0 (/Users/camdennarzt/Developer/Rust/get_args)
error: failed to run custom build command for `get_args v0.1.0 (/Users/camdennarzt/Developer/Rust/get_args)`
Caused by:
process didn't exit successfully: `/Users/camdennarzt/Developer/Rust/get_args/target/debug/build/get_args-88d57d09dbf528de/build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-changed=wrapper.h
--- stderr
thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared library at /usr/local/opt/llvm@10/lib/libclang.dylib could not be opened: dlopen(/usr/local/opt/llvm@10/lib/libclang.dylib, 2): Symbol not found: __ZTIN4llvm23MCAsmParserSemaCallbackE\n Referenced from: /usr/local/opt/llvm@10/lib/libclang.dylib\n Expected in: /Users/camdennarzt/.rustup/toolchains/stable-x86_64-apple-darwin/lib/libLLVM.dylib\n in /usr/local/opt/llvm@10/lib/libclang.dylib"', /Users/camdennarzt/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.53.2/src/lib.rs:1956:13
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
1: backtrace::backtrace::trace_unsynchronized
at /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:78
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:59
4: core::fmt::write
at src/libcore/fmt/mod.rs:1063
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1426
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:204
9: std::panicking::default_hook
at src/libstd/panicking.rs:224
10: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:470
11: rust_begin_unwind
at src/libstd/panicking.rs:378
12: core::panicking::panic_fmt
at src/libcore/panicking.rs:85
13: core::option::expect_none_failed
at src/libcore/option.rs:1211
14: core::result::Result<T,E>::expect
at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550/src/libcore/result.rs:961
15: <bindgen::ensure_libclang_is_loaded::LIBCLANG as core::ops::deref::Deref>::deref::__static_ref_initialize
at /Users/camdennarzt/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.53.2/src/lib.rs:1956
16: core::ops::function::FnOnce::call_once
at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550/src/libcore/ops/function.rs:232
17: lazy_static::lazy::Lazy<T>::get::{{closure}}
at /Users/camdennarzt/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/inline_lazy.rs:31
18: std::sync::once::Once::call_once::{{closure}}
at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550/src/libstd/sync/once.rs:264
19: std::thread::local::fast::Key<T>::try_initialize
20: std::sync::once::Once::call_once
at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550/src/libstd/sync/once.rs:264
21: bindgen::CodegenConfig::contains
22: bindgen::ensure_libclang_is_loaded
23: bindgen::Bindings::generate
24: bindgen::args_are_cpp::{{closure}}
25: build_script_build::main
at ./build.rs:35
26: std::rt::lang_start::{{closure}}
at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550/src/libstd/rt.rs:67
27: std::rt::lang_start_internal::{{closure}}
at src/libstd/rt.rs:52
28: std::panicking::try::do_call
at src/libstd/panicking.rs:303
29: __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:86
30: std::panicking::try
at src/libstd/panicking.rs:281
31: std::panic::catch_unwind
at src/libstd/panic.rs:394
32: std::rt::lang_start_internal
at src/libstd/rt.rs:51
33: std::rt::lang_start
at /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550/src/libstd/rt.rs:67
34: build_script_build::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Expected Results
No panic.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 16 (6 by maintainers)
Installing
llvm@9and then runningexport LLVM_CONFIG_PATH=/usr/local/opt/llvm@9/bin/llvm-configbeforecargo buildworked for me after experiencing this problem withllvm@10(Homebrew’s default version).