Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing tests with CXX code causes linker issues #1318

Open
Jolyon-S opened this issue Feb 16, 2024 · 0 comments
Open

Writing tests with CXX code causes linker issues #1318

Jolyon-S opened this issue Feb 16, 2024 · 0 comments

Comments

@Jolyon-S
Copy link

Problem

I use CXX to define some bindings against an external C++ library (that I manage via Nix). This builds perfectly well locally, and perfectly well in CI. All good.

Then, I write an integration test in the same crate as the C++ bridge is defined. Builds fine locally, but breaks on a very strange linker error in CI:

error: linking with `cc` failed: exit status: 1

and the main error appearing below of the form:

<...> undefined reference to <...>

where these are calls to the external library from my C++ code.

build.rs for interest:

fn main() {
    let library = pkg_config::Config::new().probe("my-external-library").unwrap();
    cxx_build::bridge("src/foo.rs")
        .file("src/foo.cc")
        .flag("-std=c++14")
        .includes(library.include_paths)
        .compile("my-crate");

    println!("cargo:rerun-if-changed=src/foo.rs");
    println!("cargo:rerun-if-changed=src/foo.cc");
    println!("cargo:rerun-if-changed=include/foo.h");
}

Workaround

Disabling the test again (by commenting it out) makes the linking work again perfectly. Additionally, just moving the test to a different crate in the workspace makes it work perfectly - the test runs fine locally and in CI, and no linker issues appear.

Is this just a known issue, or is there some other thing I need to configure to make this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant