-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Description
Using git meson from 1e8ae58
After #15125, I ran into another problem trying to use Rust mixed-in with C code. It looks like, when compiling and linking multiple Rust sources in with a C executable, only the first Rust file is being used.
[6/10] Compiling Rust source ../hello3.rs
FAILED: mixed-structured-multi-rs
rustc -C linker=gcc --color=always -C debug-assertions=yes -C overflow-checks=no --crate-type bin -g --crate-name mixed_structured_multi_rs --emit dep-info=mixed-structured-multi-rs.p/mixed-structured-multi-rs.d --emit link=mixed-structured-multi-rs -C metadata=mixed-structured-multi-rs@exe -Clink-arg=mixed-structured-multi-rs.p/main2.cc.o -Clink-arg=-L/usr/lib/gcc/x86_64-redhat-linux/15 -Clink-arg=-L/usr/lib64 -Clink-arg=-L/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64 -Clink-arg=-L/lib/../lib64 -Clink-arg=-L/usr/lib/../lib64 -Clink-arg=-L/usr/lib -Clink-arg=-L/usr/lib/gcc/x86_64-redhat-linux/15/../../.. -Clink-arg=-L/lib -Clink-arg=-lstdc++ ../hello3.rs
error: linking with `gcc` failed: exit status: 1
|
= note: "gcc" "-m64" "/tmp/rustc24CzLT/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustc24CzLT/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "mixed-structured-multi-rs" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "mixed-structured-multi-rs.p/main2.cc.o" "-L<sysroot>/lib/gcc/x86_64-redhat-linux/15" "-L<sysroot>/lib64" "-L<sysroot>/lib/gcc/x86_64-redhat-linux/15/../../../../lib64" "-L/lib/../lib64" "-L<sysroot>/lib/../lib64" "-L<sysroot>/lib" "-L<sysroot>/lib/gcc/x86_64-redhat-linux/15/../../.." "-L/lib" "-lstdc++"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: /usr/bin/ld: mixed-structured-multi-rs.p/main2.cc.o: in function `main':
/home/hadess/Projects/jhbuild/meson/test cases/rust/28 mixed/_builddir/../main2.cc:6:(.text+0x1e): undefined reference to `hello_rust'
collect2: error: ld returned 1 exit status
= note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
error: aborting due to 1 previous error
I managed to reproduce it with this test case, modified from an existing one in the same directory:
diff --git a/test cases/rust/28 mixed/hello3.rs b/test cases/rust/28 mixed/hello3.rs
new file mode 100644
index 000000000000..e990d97b20b6
--- /dev/null
+++ b/test cases/rust/28 mixed/hello3.rs
@@ -0,0 +1,6 @@
+#![no_main]
+
+#[no_mangle]
+pub extern "C" fn hello3_rust() {
+ println!("hello world again");
+}
diff --git a/test cases/rust/28 mixed/main2.cc b/test cases/rust/28 mixed/main2.cc
new file mode 100644
index 000000000000..62fb467dcedb
--- /dev/null
+++ b/test cases/rust/28 mixed/main2.cc
@@ -0,0 +1,6 @@
+#include <iostream>
+
+extern "C" void hello_rust(void);
+extern "C" void hello3_rust(void);
+
+int main() { std::cout << "This is C++!\n"; hello_rust(); hello3_rust(); }
diff --git a/test cases/rust/28 mixed/meson.build b/test cases/rust/28 mixed/meson.build
index fac3d466fadf..96a81f8510e8 100644
--- a/test cases/rust/28 mixed/meson.build
+++ b/test cases/rust/28 mixed/meson.build
@@ -7,6 +7,9 @@ e2 = executable('mixed-structured', structured_sources('hello.rs'), 'main.cc')
hello2 = import('fs').copyfile('hello.rs', 'hello2.rs')
e3 = executable('mixed-structured-gen', structured_sources(hello2), 'main.cc')
+e4 = executable('mixed-structured-multi-rs', structured_sources(['hello3.rs', 'hello.rs']), 'main2.cc')
+
test('mixed', e1)
test('mixed-structured', e2)
test('mixed-structured-gen', e3)
+test('mixed-structured-multi-rs', e4)