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

cargo test throw undefined reference to 'napi_create_object' on Linux CI #1099

Closed
wre232114 opened this issue Mar 16, 2022 · 7 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@wre232114
Copy link

wre232114 commented Mar 16, 2022

When running cargo test on CI(Linux), following error occurs:

error: linking with `cc` failed: exit status: 1
= note: "cc" "-m64"  ....

...

...: undefined reference to `napi_create_object'

The same cargo test works fine on MacOS

@Brooooooklyn Brooooooklyn added the bug Something isn't working label Mar 16, 2022
@chenjun1011
Copy link

I met the same problem https://github.com/ice-lab/swc/runs/6876966157?check_suite_focus=true
Is there any progress on this issue?

@messense
Copy link
Contributor

@chenjun1011 Have you tried install Nodejs before running cargo test?

- uses: actions/setup-node@v3

@chenjun1011
Copy link

Still have the same problem, after setup node.

https://github.com/ice-lab/swc/runs/6877711481?check_suite_focus=true

@messense
Copy link
Contributor

I think the problem is that Nodejs does not provide a shared library (libnode.so) but only a node executable. And N-API extensions built with napi-rs cli are compiled to shared library which allows undefined external symbols on Linux, but cargo test builds executables so it needs a Nodejs shared library to find theses external symbols.

Unfortunately there isn't a embedding API for N-API right now, so I think the easiest way forward is making napi an on-by-default optional feature and feature-gate related code then run cargo test --no-default-features instead.

Cargo.toml:

[features]
default = ["napi"]

Or you can split your project into two crates, a Nodejs independent crate and a N-API extension crate.

@Brooooooklyn
Copy link
Sponsor Member

Fixed on ice-lab/swc#24 , /cc @wre232114

@chenjun1011
Copy link

@outkine
Copy link

outkine commented Dec 22, 2022

@messense Thank you for sharing that solution! It fixes the problem on Linux, but I'm still getting "undefined reference" errors on MacOS. Do you have any idea if that might be because MacOS doesn't allow undefined external symbols, and if there's any way to get around that problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants