Skip to content

wrong link_name for msvc #578

Closed
Closed
@Dushistov

Description

@Dushistov

Input C Header

extern void test(void);

Bindgen Invocation

    let mut bindings: Builder = bindgen::builder().header(c_file_path.to_str().unwrap());
    bindings = include_dirs.iter().fold(bindings, |acc, x| acc.clang_arg("-I".to_string() + x.as_ref().to_str().unwrap()));

    bindings = bindings
        .no_unstable_rust()
        .raw_line("#![allow(non_upper_case_globals, dead_code, non_camel_case_types, improper_ctypes)]")
        ;
    bindings = c_headers[1..].iter().fold(Ok(bindings), |acc: Result<Builder, String>, header| {
        let c_file_path = search_file_in_directory(include_dirs, header)
                               .map_err(|_| format!("Can not find {}", header))?;
        let c_file_str = c_file_path.to_str()
            .ok_or_else(|| format!("Invalid unicode in path to {}", header))?;
        Ok(acc.unwrap().clang_arg("-include").clang_arg(c_file_str))
    })?;
    
    let generated_bindings = bindings.generate().map_err(|_| "Failed to generate bindings".to_string())?;
    generated_bindings.write_to_file(output_rust).map_err(|err| err.to_string())?;

Actual Results

extern "C" {
    #[link_name = "_test"]
    pub fn test();
}
error LNK2019: unresolved external symbol __test

Expected Results

linking without any errors.

Hint the problem in two underscores instead of one,
looks like rustc (at least 1.16) smart enought to add "_" to names.
So if remove #[link_name = "_test"] all works fine,
but I can not find option to strip link_name from output.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions