cargo test with no_std fails with error code 176, 160

367 views Asked by At

Using the below code in main.rs, when I run cargo test it returns error code 176, when I add a test or `any statement in main function. It starts returning error code 160.

#![no_std]
#![no_main]

#[cfg(test)]
#[macro_use]
extern crate std;
#[cfg(not(test))]
extern crate panic_halt;

#[no_mangle]
pub unsafe extern "C" fn main() {

}

From this link I found out, that

Exit code 176 means "Unable to install on a network drive. Select another install location in your preferences and retry installing."

When I tried to find back trace through lldb it returned

error: invalid thread

I couldn't find any thread which mentions similar error, so asking it here. Any help is appreciated.

Using nightly (nightly-x86_64-apple-darwin) Thanks.

1

There are 1 answers

2
hellow On

The problem is your main function, which has an invalid signature for unix platforms. It must return an i32 (or better c_int, but for simplicity we suppose they are idential). The 176 is just some random value in the rax register when leaving the main function.

So change your main signature to:

pub unsafe extern "C" fn main() -> i32

and return a return code (e.g. 0 which means success)

or

pub unsafe extern "C" fn main() -> !

and use the exit syscall on linux (or an infinite loop on embedded systems).