Cargo fails to find static library built by build.rs in Linux

I`#[cfg(target_os = "linux")]
fn main() {
    println!("cargo:rerun-if-changed=src/c/lib.c");
    cc::Build::new()
                .files(vec!["src/c/lib.c"])
                .include("src/c/headers")
                .compile("XXXX");
}

#[cfg(not(target_os = "linux"))]
fn main() {
    println!("cargo:rerun-if-changed=src/c/lib.c");
    println!("cargo:rerun-if-changed=src/c/mach_excServer.c");
    println!("cargo:rerun-if-changed=src/c/headers/mach_exec.h");
    println!("cargo:rustc-link-arg=-undefined");
    println!("cargo:rustc-link-arg=dynamic_lookup");
    cc::Build::new()
                .files(vec!["src/c/mach_excServer.c","src/c/lib.c"])
                .include("src/c/headers")
                .compile("XXXX");
}`

These are the two functions of my build script. I am using rust/cargo 1.75. The containers have 1.73.

I have been using the bottom main function to build and debug flawlessly in OS X for quite some time. Now, the code is stable enough to move to containers.

The command "cargo build" fails with the message that the symbols under the link attribute can not be found The link attribute is:

#[link(name="XXXX", kind="static")]
extern  "C"{
           fn function1() -();
}

Is it possible that the output static lib is named differently between the two OS causing the link attribute to fail?

Thanks a lot in advance!

Sadly I don't know about the cc crate but I'd suggest you wrap your code in code blocks.

Do

 ```rust
 Your code here
 ```

For multilne code blocks and

`code here`

For inline code. it will provide a monospace font and syntax highlighting

Likely, change your main so the linux one is like on your mac.
We have no idea what your requiring from an independent library so you should be looking at its requirements.
"the symbols under the link attribute can not be found" suggests it was compiled and found; contradictory to topic title.

The error is not coming from CC crate. It is the rust linker throwing missing "function1" in rust source files.

If we got there, it means that build.rs succeeded.

Whatever the goal of the C code is irrelevant since the linker can not find the static library/symbols.that are produced by build.rs/cc in Linux.

The main function for Linux can not be the same as the one for OS X because Linux is not a Darwin/Mach OS and the exception handling is different

Your getting it the wrong way around.
When you write "#[link ...]extern "C" ..." you are declaring that those functions will match symbols in the library. (the #[link is somewhat optional and without they will be searched in any given library at link time.)

To look inside at what symbols the build.rs created, find the XXXX under target directory and run "readelf -W -s file"

XXXX is nowhere to be found. Hence the question: is the static library named differently?. Solved the issue.

Thanks