You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm attempting to link C code which calls a Rust library that allocates on the heap by running arc-elf32-gcc lib.o example.c but am getting an undefined reference to core[47ee6e850c258048]::fmt::Formatter>::debug_lower_hex
The rust code successfully compiles using rustc example.rs --emit=obj -o lib.o --crate-type=lib -O
If I instead compile with --crate-type=cdylib or dylib I get dropping unsupported crate type cdylib for target
If I compile with --crate-type=staticlib then I get
error: no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait
error: `#[panic_handler]` function required, but not found
After implementing a global memory allocator by following embedded-alloc and specifying a panic handler similar to global_alloc.rs, I still get an undefined reference to debug_lower_hex.
code
// example.rs which becomes lib.o#![no_std]externcrate alloc;use alloc::vec::Vec;#[no_mangle]pubextern"C"fnrust() -> i32{let y = 42;letmut vec = Vec::new();
vec.push(y);
vec.pop().unwrap()}
// example.c#include<stdint.h>#include<stdarg.h>int32_trust(void);
intmain()
{
printf("from rust get value %d", rust());
}
full error output
/opt/arc/lib/gcc/arc-elf32/10.2.0/../../../../arc-elf32/bin/ld: /opt/arc/lib/gcc/arc-elf32/10.2.0/../../../../arc-elf32/bin/ld: DWARF error: can't find .debug_ranges section.
src/lib.o: in function `_RNvXsP_NtCs6aT7ng1d0qi_4core3fmtRjNtB5_5Debug3fmtCsZt7r1wRFCo_4test':
fake.c:(.text._RNvXsP_NtCs6aT7ng1d0qi_4core3fmtRjNtB5_5Debug3fmtCsZt7r1wRFCo_4test+0xa): undefined reference to `_RNvMs5_NtCs6aT7ng1d0qi_4core3fmtNtB5_9Formatter15debug_lower_hex'
/opt/arc_tools_202009rel/lib/gcc/arc-elf32/10.2.0/../../../../arc-elf32/bin/ld: fake.c:(.text._RNvXsP_NtCs6aT7ng1d0qi_4core3fmtRjNtB5_5Debug3fmtCsZt7r1wRFCo_4test+0xa): undefined reference to `_RNvMs5_NtCs6aT7ng1d0qi_4core3fmtNtB5_9Formatter15debug_lower_hex'
/opt/arc_tools_202009rel/lib/gcc/arc-elf32/10.2.0/../../../../arc-elf32/bin/ld: GOT and PLT relocations cannot be fixed with a non dynamic linker
/opt/arc_tools_202009rel/lib/gcc/arc-elf32/10.2.0/../../../../arc-elf32/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
demangled
src/lib.o: in function `<&usize as core[47ee6e850c258048]::fmt::Debug>::fmt':
fake.c:(.text.<&usize as core[47ee6e850c258048]::fmt::Debug>::fmt+0xa): undefined reference to `<core[47ee6e850c258048]::fmt::Formatter>::debug_lower_hex'
/opt/arc_tools/lib/gcc/arc-elf32/10.2.0/../../../../arc-elf32/bin/ld: fake.c:(.text.<&usize as core[47ee6e850c258048]::fmt::Debug>::fmt+0xa): undefined reference to `<core[47ee6e850c258048]::fmt::Formatter>::debug_lower_hex'
The text was updated successfully, but these errors were encountered:
arc-elf32-gcc lib.o example.c
but am getting an undefined reference tocore[47ee6e850c258048]::fmt::Formatter>::debug_lower_hex
rustc example.rs --emit=obj -o lib.o --crate-type=lib -O
--crate-type=cdylib
ordylib
I getdropping unsupported crate type cdylib for target
--crate-type=staticlib
then I getdebug_lower_hex
.code
full error output
demangled
The text was updated successfully, but these errors were encountered: