Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Link errors when using rustc-serialize from a plugin? #26

Closed
ArtemGr opened this issue Jan 18, 2015 · 2 comments
Closed

Link errors when using rustc-serialize from a plugin? #26

ArtemGr opened this issue Jan 18, 2015 · 2 comments

Comments

@ArtemGr
Copy link
Contributor

ArtemGr commented Jan 18, 2015

Let's say I have a bare-bones plugin

#![crate_name="json_macros"]
#![feature(plugin_registrar, quote)]
#![allow(unstable)]

extern crate rustc;
extern crate syntax;
//extern crate "rustc-serialize" as rustc_serialize;

use syntax::ast::TokenTree;
use syntax::codemap::Span;
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult};
use rustc::plugin::Registry;

#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
    reg.register_macro("json", expand);
}

fn expand<'cx>(_: &'cx mut ExtCtxt, sp: Span,
               _: &[TokenTree]) -> Box<MacResult + 'cx> {
    return DummyResult::expr(sp);
}

used in my program. If I add an extern crate "rustc-serialize" as rustc_serialize; line to it I get a linking problem:

root@boot2docker(Docker):/tmp/test-case$ cargo build
   Compiling json_macros v0.1.2 (file:///tmp/test-case)
   Compiling err v0.0.1 (file:///tmp/test-case)
error: linking with `cc` failed: exit code: 1
note: cc '-Wl,--as-needed' '-m64' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' '/tmp/test-case/target/test' '/tmp/test-case/target/test.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive' '-Wl,--gc-sections' '-pie' '-nodefaultlibs' '-L' '/tmp/test-case/target/deps' '-ljson_macros-4df5f724b343b7dd' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lrustc-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lrustc_back-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lsyntax-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lfmt_macros-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lgraphviz-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lflate-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-larena-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lgetopts-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lterm-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lrbml-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lserialize-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-llog-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lregex-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lrustc_llvm-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lstd-4e7c5e5c' '-L' '/tmp/test-case/target' '-L' '/tmp/test-case/target/deps' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-L' '/tmp/test-case/.rust/lib/x86_64-unknown-linux-gnu' '-L' '/tmp/test-case/lib/x86_64-unknown-linux-gnu' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-lpthread' '-lrt' '-ldl' '-lm' '-ldl' '-lpthread' '-lrt' '-lgcc_s' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: /tmp/test-case/target/test.o: In function `test::main':
/tmp/test-case/test.rs:10: undefined reference to `json::Json::from_str::h04331c517e0d1e39hLg'
/tmp/test-case/target/test.o: In function `result::Result$LT$T$C$$u{20}E$GT$::unwrap::h14896951616154145496':
test.0.rs:(.text._ZN6result25Result$LT$T$C$$u{20}E$GT$6unwrap21h14896951616154145496E+0x1e4): undefined reference to `json::ParserError...std..fmt..Show::fmt::hd963556d3347d834qTe'
collect2: error: ld returned 1 exit status

error: aborting due to previous error
Could not compile `err`.

To learn more, run the command again with --verbose.

Not sure if it's a Rust issue or a package issue?
Rust version is rustc 1.0.0-nightly (f4f10dba2 2015-01-17 20:31:08 +0000).
Here's a test case https://gist.github.com/ArtemGr/96f45adaf2e16f3e16d4 which can be easily converted to a fully local one by replacing version = "*" with path = "json_macros" in Cargo.toml.

cf. tomjakubowski/json_macros#12

@alexcrichton
Copy link
Contributor

Reproduced locally, and I think all you need is #[no_link] on the extern crate json_macros (wouldn't want to link in a plugin!)

@ArtemGr
Copy link
Contributor Author

ArtemGr commented Jan 19, 2015

Oh, gosh! Didn't know that. Thanks!

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

No branches or pull requests

2 participants