Rust package of openwrt: error: linking with `cc` failed: exit status: 1

I'm trying to build package based on rust cargo project. So here is my Makefile for this:

include $(TOPDIR)/rules.mk

# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)
PKG_NAME:=rust-helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=1

# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below
SOURCE_DIR:=/home/repositories/virtual-lorawan-device

include $(INCLUDE_DIR)/package.mk

# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')
define Package/rust-helloworld
	SECTION:=examples
	CATEGORY:=Examples
	TITLE:=Hello, world from Rust package!
endef

# Package description; a more verbose description on what our package does
define Package/rust-helloworld/description
	A simple "Hello, world from Rust package!" -application.
endef

# Package preparation instructions; create the build directory and copy the source code. 
# The last command is necessary to ensure our preparation instructions remain compatible with the patching system.
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	cp -r $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
	$(Build/Patch)
endef

# Package build instructions; invoke the target-specific compiler to first compile the source file, and then to link the file into the final executable
define Build/Compile
	cargo build --target=mipsel-unknown-linux-musl --verbose --release --manifest-path $(PKG_BUILD_DIR)/Cargo.toml
endef 


# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder
define Package/rust-helloworld/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/rust-helloworld $(1)/usr/bin
endef

# This command is always the last, it uses the definitions and variables we give above in order to get the job done
$(eval $(call BuildPackage,rust-helloworld))

My .cargo/config file in root of rust project looks like:

[target.mipsel-unknown-linux-musl]
rustflags = ["-C", "linker=mipsel-openwrt-linux-musl-gcc"]
linker = "mipsel-openwrt-linux-musl-gcc"
ar = "mipsel-openwrt-linux-musl-ar"

[net]
git-fetch-with-cli = true

But I faced a problem of cc:

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.0.rcgu.o" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.1.rcgu.o" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.10.rcgu.o" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.11.rcgu.o" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.12.rcgu.o" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.13.rcgu.o" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.14.rcgu.o" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.15.rcgu.o" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.2.rcgu.o" "/home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358
...

/usr/bin/ld: /home/repositories/openwrt/build_dir/target-mipsel_24kc_musl/rust-helloworld-1.0/target/mipsel-unknown-linux-musl/release/deps/virtual_device-58358aa7564334bb.virtual_device.368cf6ca-cgu.0.rcgu.o: error adding symbols: file in wrong format
          collect2: error: ld returned 1 exit status

Please, help :slight_smile: How can I fix it?

P.S.: building release binary works fine for my project by applying command cargo build --target=mipsel-unknown-linux-musl --release

can you publish your code