0

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.

xcepti0n
  • 41
  • 1
  • 1
  • 4
  • Your link provided deals with some adobe software. It has **nothing** to do with rust or unix exit codes. So please don't pay attention to that ;) – hellow Dec 19 '19 at 12:45

1 Answers1

2

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).

hellow
  • 12,430
  • 7
  • 56
  • 79
  • After adding return 0 and i32 return type as you mentioned, it is not returning error. But is still not executing tests. – xcepti0n Dec 20 '19 at 06:42
  • "Running `/Users/xcepti0n/workplace/GitTestRepos/crazy_test/target/debug/deps/crazy-`" after it exits without printing anything. – xcepti0n Dec 20 '19 at 06:46