Adding nom as a dependency to a proc-macro crate with tests results in link error
killercup opened this issue · 17 comments
Long debug session short:
- Having a proc-macro crate with tests works.
- Adding nom 5 as a dependency to a proc-macro crate works.
- Having nom 5 be a dependency in a proc-macro crate with tests does not work.
This might be a known problem; I couldn't find an open issue, though. Even so, error is not user friendly and that should at least be fixed.
cargo test --verbose
Fresh semver-parser v0.7.0
Fresh void v1.0.2
Fresh version_check v0.1.5
Fresh static_assertions v0.2.5
Fresh cfg-if v0.1.9
Fresh semver v0.9.0
Fresh rustc_version v0.2.3
Fresh unreachable v1.0.0
Fresh ryu v0.2.8
Fresh memchr v2.2.0
Fresh stackvector v1.0.6
Fresh lexical-core v0.4.2
Fresh nom v5.0.0
Compiling le-proc-macro v0.1.0 (/Users/pascal/Projekte/rust-proc-macro-test-linking-error/le-proc-macro)
Running `rustc --edition=2018 --crate-name le_proc_macro le-proc-macro/src/lib.rs --color always --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 -C metadata=88a723aab0e69935 -C extra-filename=-88a723aab0e69935 --out-dir /Users/pascal/.cargo/global-target/debug/deps -C incremental=/Users/pascal/.cargo/global-target/debug/incremental -L dependency=/Users/pascal/.cargo/global-target/debug/deps --extern nom=/Users/pascal/.cargo/global-target/debug/deps/libnom-1f917ff11a098652.rlib -Zsymbol-mangling-version=v0`
Running `rustc --edition=2018 --crate-name le_proc_macro le-proc-macro/src/lib.rs --color always --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 --test -C metadata=a6088ffbe5f8f402 -C extra-filename=-a6088ffbe5f8f402 --out-dir /Users/pascal/.cargo/global-target/debug/deps -C incremental=/Users/pascal/.cargo/global-target/debug/incremental -L dependency=/Users/pascal/.cargo/global-target/debug/deps --extern nom=/Users/pascal/.cargo/global-target/debug/deps/libnom-1f917ff11a098652.rlib -Zsymbol-mangling-version=v0`
warning: unused import: `nom::IResult`
--> le-proc-macro/src/lib.rs:4:5
|
4 | use nom::IResult;
| ^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
warning: unused import: `nom::IResult`
--> le-proc-macro/src/lib.rs:4:5
|
4 | use nom::IResult;
| ^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-m64" "-L" "/Users/pascal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402.15tcejuoevmooxrp.rcgu.o" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402.2t5ie6p57602b1hc.rcgu.o" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402.3k5tdhzyfh385jbb.rcgu.o" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402.40gtnqu5cs3dsn54.rcgu.o" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402.4qorxw028kxfrme3.rcgu.o" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402.52k0bg5o47l9e5g5.rcgu.o" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402.al00ie0yzyrbvcs.rcgu.o" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402.mt4xvaos1670dho.rcgu.o" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402.uo2b4vausxznfy0.rcgu.o" "-o" "/Users/pascal/.cargo/global-target/debug/deps/le_proc_macro-a6088ffbe5f8f402" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/pascal/.cargo/global-target/debug/deps" "-L" "/Users/pascal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/Users/pascal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-ltest-0d2e540bfeb389c9" "-L" "/Users/pascal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-lterm-9dc2d4db7993fbfd" "/Users/pascal/.cargo/global-target/debug/deps/libnom-1f917ff11a098652.rlib" "-L" "/Users/pascal/.cargo/global-target/debug/deps" "-llexical_core-d715db2534c4793d" "/Users/pascal/.cargo/global-target/debug/deps/libryu-aa307abc73a251bb.rlib" "/Users/pascal/.cargo/global-target/debug/deps/libstackvector-8faea803e8d71d93.rlib" "/Users/pascal/.cargo/global-target/debug/deps/libunreachable-5224a131bd9f1445.rlib" "/Users/pascal/.cargo/global-target/debug/deps/libvoid-196f5b851425c571.rlib" "/Users/pascal/.cargo/global-target/debug/deps/libstatic_assertions-633d173cf8830653.rlib" "/Users/pascal/.cargo/global-target/debug/deps/libcfg_if-3eb3c0e2c877bcb6.rlib" "/Users/pascal/.cargo/global-target/debug/deps/libmemchr-affb19acc32f58a0.rlib" "/Users/pascal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libproc_macro-027ee96af4731d93.rlib" "-L" "/Users/pascal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-lstd-a62aa059e97bb248" "/Users/pascal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-a62aa322f1655fc7.rlib" "-lSystem" "-lresolv" "-lc" "-lm"
= note: Undefined symbols for architecture x86_64:
"__RNvXsJ_NtCs6GOKu7pHlyt_4core3fmtRlNtB5_5Debug3fmtCs7N6e5JiROWN_12lexical_core", referenced from:
__RINvCsLl3UznTzjj_4test18assert_test_resultuECsfbY9ZosDsBF_13le_proc_macro in le_proc_macro-a6088ffbe5f8f402.al00ie0yzyrbvcs.rcgu.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: aborting due to previous error
error: Could not compile `le-proc-macro`.
Caused by:
process didn't exit successfully: `rustc --edition=2018 --crate-name le_proc_macro le-proc-macro/src/lib.rs --color always --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 --test -C metadata=a6088ffbe5f8f402 -C extra-filename=-a6088ffbe5f8f402 --out-dir /Users/pascal/.cargo/global-target/debug/deps -C incremental=/Users/pascal/.cargo/global-target/debug/incremental -L dependency=/Users/pascal/.cargo/global-target/debug/deps --extern nom=/Users/pascal/.cargo/global-target/debug/deps/libnom-1f917ff11a098652.rlib -Zsymbol-mangling-version=v0` (exit code: 1)
warning: build failed, waiting for other jobs to finish...
error: build failed
See these commits for a minimal repo: https://github.com/killercup/rust-proc-macro-test-linking-error/commits/master
Tested with rustc 1.37.0-nightly (7840a0b75 2019-05-31) and rustc 1.35.0 (3c235d560 2019-05-20).
cc @fry because we originally encountered this issue in https://github.com/fry/memory-offset-match
cc @Geal because he might have done something horrible in nom 5 or one of its dependencies :)
Interestingly, tests on the bad commit pass on windows-gnu and fails to link on windows-msvc.
windows-msvc
Compiling le-proc-macro v0.1.0 (D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\le-proc-macro)
Running `rustc --edition=2018 --crate-name le_proc_macro le-proc-macro\src\lib.rs --color never --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 -C metadata=79c80939141ae4ac -C extra-filename=-79c80939141ae4ac --out-dir D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps -C incremental=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\incremental -L dependency=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps --extern nom=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps\libnom-c94b7c84eb2825cd.rlib`
Running `rustc --edition=2018 --crate-name le_proc_macro le-proc-macro\src\lib.rs --color never --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 --test -C metadata=7bd3bb9f841cfff7 -C extra-filename=-7bd3bb9f841cfff7 --out-dir D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps -C incremental=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\incremental -L dependency=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps --extern nom=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps\libnom-c94b7c84eb2825cd.rlib`
error: linking with `link.exe` failed: exit code: 1120
|
= note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.1g0nlq9cs4pghkmy.rcgu.o" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.2zq0lgz10lh544dg.rcgu.o" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.3vphv4whkenx5uyc.rcgu.o" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.423daslz1834a6cl.rcgu.o" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.4f1glrg3bse6z664.rcgu.o" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.4wjf5uz2ryqnq3zw.rcgu.o" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.5dntnuq9q5dsobng.rcgu.o" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.5vrr76dttgz35ko.rcgu.o" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.eiqbwkic980ji4a.rcgu.o" "/OUT:D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\le_proc_macro-7bd3bb9f841cfff7.exe" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps" "/LIBPATH:D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/LIBPATH:D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "test-a4f6d8bebcc4a634.dll.lib" "/LIBPATH:D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "term-b5d0d8083a2dc6b6.dll.lib" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\libnom-c94b7c84eb2825cd.rlib" "/LIBPATH:D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps" "lexical_core-7f0416c2f53c1ea3.dll.lib" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\libryu-180662a1e54e289b.rlib" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\libstackvector-397c1e3495a8af16.rlib" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\libunreachable-0de66d9fa8096f40.rlib" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\libvoid-bd42d54b51e6fb3b.rlib" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\libstatic_assertions-e1a33ab607fbc814.rlib" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\libcfg_if-0effb27d46321e26.rlib" "D:\\usr\\Documents\\Code\\Rust\\rust-proc-macro-test-linking-error\\target\\debug\\deps\\libmemchr-764cfb4774939518.rlib" "D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libproc_macro-4d1f432750330cc0.rlib" "/LIBPATH:D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "std-f293fd7c6c200025.dll.lib" "D:\\usr\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-6e806524bc879616.rlib" "kernel32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
= note: le_proc_macro-7bd3bb9f841cfff7.5dntnuq9q5dsobng.rcgu.o : error LNK2019: unresolved external symbol _ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h2afd837e3afa95dfE referenced in function _ZN4test18assert_test_result17h4c0919ab0062322cE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.15.rcgu.o) : error LNK2019: unresolved external symbol _ZN44_$LT$$RF$T$u20$as$u20$core..fmt..Display$GT$3fmt17hf14e8c15e740b9fbE referenced in function _ZN44_$LT$$RF$T$u20$as$u20$core..fmt..Display$GT$3fmt17haab549e68c83ac1dE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.15.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core3fmt10ArgumentV13new17hc9a2b5195c3df041E referenced in function _ZN4core6result13unwrap_failed17h04085d1dcae3d677E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.3.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core3mem7size_of17h92a2f9b2285fe98bE referenced in function _ZN5alloc7raw_vec11alloc_guard17hbd50e116f525187dE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.6.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core3cmp3Ord3max17h23fc9564fa9d697fE referenced in function _ZN4core3cmp3max17hd0540b0469402e52E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.6.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core3ptr4null17hcd56d8e489039dbcE referenced in function _ZN4core3ptr33_$LT$impl$u20$$BP$const$u20$T$GT$7is_null17h8e5689cafc2eeb2bE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core3ptr4null17hcd56d8e489039dbcE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.6.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core3ptr33_$LT$impl$u20$$BP$const$u20$T$GT$12wrapping_add17h73cb510101ad8f41E referenced in function _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$4iter17h558ad527c14070e5E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core3ptr33_$LT$impl$u20$$BP$const$u20$T$GT$12wrapping_add17h73cb510101ad8f41E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.6.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$8is_empty17h292f2354d65f1217E referenced in function _ZN6memchr6memchr17h096a2154009159f5E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$8is_empty17h292f2354d65f1217E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.13.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$8is_empty17h292f2354d65f1217E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$10as_mut_ptr17h74c681e1ce352f74E referenced in function _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$15copy_from_slice17h7425f79218280e4bE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.5.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$10as_mut_ptr17h74c681e1ce352f74E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$4iter17h5de8a72d254d3c81E referenced in function _ZN4core5slice87_$LT$impl$u20$core..iter..traits..collect..IntoIterator$u20$for$u20$$RF$$u5b$T$u5d$$GT$9into_iter17hd669a6aba8572ef2E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.5.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$4iter17h5de8a72d254d3c81E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.7.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$4iter17h5de8a72d254d3c81E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.1.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$4iter17h5de8a72d254d3c81E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core3ptr33_$LT$impl$u20$$BP$const$u20$T$GT$15wrapping_offset17hb99f1d9c96b35408E referenced in function _ZN85_$LT$core..slice..Iter$LT$T$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h393cb63c7e21b432E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.9.rcgu.o) : error LNK2019: unresolved external symbol _ZN99_$LT$core..ops..range..Range$LT$usize$GT$$u20$as$u20$core..slice..SliceIndex$LT$$u5b$T$u5d$$GT$$GT$17get_unchecked_mut17h647d054b48c4ddd1E referenced in function _ZN101_$LT$core..ops..range..RangeTo$LT$usize$GT$$u20$as$u20$core..slice..SliceIndex$LT$$u5b$T$u5d$$GT$$GT$17get_unchecked_mut17h28223c993ae50ebcE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.5.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core5slice18from_raw_parts_mut17h98d385ee41841199E referenced in function _ZN71_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..deref..DerefMut$GT$9deref_mut17h4f0a111c1e19aaffE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.5.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core5slice74_$LT$impl$u20$core..ops..index..Index$LT$I$GT$$u20$for$u20$$u5b$T$u5d$$GT$5index17hb99a524821c5f831E referenced in function _ZN77_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..index..Index$LT$I$GT$$GT$5index17hf110361d6411889cE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.1.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core5slice74_$LT$impl$u20$core..ops..index..Index$LT$I$GT$$u20$for$u20$$u5b$T$u5d$$GT$5index17hb99a524821c5f831E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.7.rcgu.o) : error LNK2019: unresolved external symbol _ZN85_$LT$core..slice..Iter$LT$T$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17he6af94f7b2c0b0d1E referenced in function _ZN4core3str15next_code_point17hef324823ad4c0872E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.1.rcgu.o) : error LNK2001: unresolved external symbol _ZN85_$LT$core..slice..Iter$LT$T$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17he6af94f7b2c0b0d1E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.7.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$3get17hf115a764b37e96b7E referenced in function _ZN4core3str21_$LT$impl$u20$str$GT$16is_char_boundary17h3c5e7a7aa3d1f0c6E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.2.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core5slice29_$LT$impl$u20$$u5b$T$u5d$$GT$3get17hf115a764b37e96b7E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.2.rcgu.o) : error LNK2019: unresolved external symbol _ZN63_$LT$I$u20$as$u20$core..iter..traits..collect..IntoIterator$GT$9into_iter17hf1888569ab79dc27E referenced in function _ZN4core3str7pattern14TwoWaySearcher4next17h4f9555b17b537e73E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.2.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core4iter5range101_$LT$impl$u20$core..iter..traits..iterator..Iterator$u20$for$u20$core..ops..range..Range$LT$A$GT$$GT$4next17ha062de3a3a9e0250E referenced in function _ZN4core3str7pattern14TwoWaySearcher4next17h4f9555b17b537e73E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.2.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core3cmp5impls69_$LT$impl$u20$core..cmp..PartialEq$LT$$RF$B$GT$$u20$for$u20$$RF$A$GT$2eq17h311a204d80df372fE referenced in function _ZN81_$LT$core..str..pattern..CharSearcher$u20$as$u20$core..str..pattern..Searcher$GT$10next_match17hb6708e15064c8ea1E
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.1.rcgu.o) : error LNK2001: unresolved external symbol _ZN4core3cmp5impls69_$LT$impl$u20$core..cmp..PartialEq$LT$$RF$B$GT$$u20$for$u20$$RF$A$GT$2eq17h311a204d80df372fE
libnom-c94b7c84eb2825cd.rlib(nom-c94b7c84eb2825cd.nom.89kj9cb1-cgu.1.rcgu.o) : error LNK2019: unresolved external symbol _ZN63_$LT$I$u20$as$u20$core..iter..traits..collect..IntoIterator$GT$9into_iter17h1823be92c3d60beaE referenced in function _ZN71_$LT$$RF$$u5b$u8$u5d$$u20$as$u20$nom..traits..FindToken$LT$char$GT$$GT$10find_token17h1563db97eca1d634E
D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps\le_proc_macro-7bd3bb9f841cfff7.exe : fatal error LNK1120: 20 unresolved externals
windows-gnu
Compiling le-proc-macro v0.1.0 (D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\le-proc-macro)
Running `rustc --edition=2018 --crate-name le_proc_macro le-proc-macro\src\lib.rs --color never --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 -C metadata=c8b668c11ecd6d48 -C extra-filename=-c8b668c11ecd6d48 --out-dir D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps -C incremental=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\incremental -L dependency=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps --extern nom=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps\libnom-b1d68ca366aff2cb.rlib`
Running `rustc --edition=2018 --crate-name le_proc_macro le-proc-macro\src\lib.rs --color never --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 --test -C metadata=017bf7764872f271 -C extra-filename=-017bf7764872f271 --out-dir D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps -C incremental=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\incremental -L dependency=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps --extern nom=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps\libnom-b1d68ca366aff2cb.rlib`
Compiling le-lib-crate v0.1.0 (D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\le-main-crate)
Running `rustc --edition=2018 --crate-name le_lib_crate le-main-crate\src\main.rs --color never --emit=dep-info,link -C debuginfo=2 --test -C metadata=c57f79d95dd04475 -C extra-filename=-c57f79d95dd04475 --out-dir D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps -C incremental=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\incremental -L dependency=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps --extern le_proc_macro=D:\usr\Documents\Code\Rust\rust-proc-macro-test-linking-error\target\debug\deps\le_proc_macro-c8b668c11ecd6d48.dll`
Finished dev [unoptimized + debuginfo] target(s) in 2.22s
Encountered this today with Rust 1.36.0 on x86_64-unknown-linux-gnu when trying to upgrade a crate from Nom 4 to Nom 5.
I ran git bisect, which identified rust-bakery/nom@40f20aa as the first bad commit. The commit adds lexical-core as a new optional dependency behind the lexical feature, which is on by default.
Some observations:
- Changing
default = ["std", "lexical"]todefault = ["std"]in Nom'sCargo.tomlfixes the linking error. Adding the Nom dependency withEdit: I forgot to also specifynom = { version = "5.0", features = ["std"] }in theproc-macrocrate does not fix the linking error (am I doing this correctly?)default-features = false.- Adding a dependency to just
lexical-core(instead of Nom 5) in theproc-macrocrate does not trigger the linking error
So I went one step further and had a look at lexical-core (Alexhuszagh/rust-lexical@078fff3). Observations from modifying lexical-core and using this modified version in Nom's Cargo.toml:
- Removing "correct" from
lexical-coredefault features in itsCargo.tomlfixes theproc-macrocrate linking errors. lexical-corespecifiescrate-type = ["lib", "staticlib", "cdylib"]in itsCargo.toml. Removingcdylibfrom this also fixes theproc-macrocrate linking errors.
@Alexhuszagh any idea about this?
Thanks @fwalch and @Geal, removing correct from lexical-core may not be ideal, since that would invoke the lossy parser, which is a fast but lossy floating-point parser. Let me check if I can actually find the issues with this.
As far as "cdylib", my crate exports functions for C-FFI, but this can be easily removed and would just require users to designate the crate-type when building. Let me quickly check this on my end and try to ensure this is all working well.
Ok, I'm going to move the C-API to an external crate, which will solve half of this issue. I'll try debugging for the proc-macro issues with different features enabled, thanks for the heads up.
Visiting from compiler triage meeting. I cannot tell if this is a compiler bug. It sounds vaguely like one -- including cdylib doesn't seem like it should on its own cause a link error? But I'm not sure, perhaps there is a legit error that only comes up when doing a cdylib build? Not sure how to categorize this, so leaving as is for this week.
@nikomatsakis I've decided that it's likely best to separate the the C-API from the core crate, so this shouldn't be an issue. I'm more concerned about the correct feature not working, but I'll get there shortly.
@Alexhuszagh does that mean we should close this issue? I can also mark it as "P-medium" and people can re-nominate if/when it should be reconsidered.
I'll mark it as p-medium for now.
Well this is clearly still a bug in either rustc or maybe Cargo, even if you can work around it
After re-organizing lexical somewhat to separate the C API from the Rust API, I'm unable to find any error with proc-macros for the correct feature. That should be the last barrier to integrating Nom as a dependency in a proc-macro crate. I'll publish my changes, submit a PR to nom, and we should be good to go.
I'll see if later if I can create a minimal working example that fails for crate-type = ["cdylib"].
Ok, I've confirmed that the original example works for @killercup's example after the following patches, when previously it had a linking error. I'm using an unpublished branch, currently, and will publish it after review. This should fix the error, @Geal. I will publish the changes shortly, assuming this looks good to others.
Config
First, since I'm cross-compiling, my setup:
$ wine --version
wine-4.14 (Staging)
$ cargo --version
cargo 1.32.0 (8610973aa 2019-01-02)
$ x86_64-w64-mingw32-gcc --version
x86_64-w64-mingw32-gcc (GCC) 8.3.0 20190222 (Fedora MinGW 8.3.0-2.fc29)
$ x86_64-w64-mingw32-ar --version
GNU ar (GNU Binutils) 2.30Finally, the contents of ~/.cargo/config:
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-gcc-ar"
[target.i686-pc-windows-gnu]
linker = "i686-w64-mingw32-gcc"
ar = "i686-w64-mingw32-gcc-ar"Next, I cloned the master branch of nom and lexical into the project root of the test crate where nom is failing.
Next, I applied the following patch to nom, to ensure it used to latest version. There's been a necessary change to the API in order to separate the C API and the Rust API, so there resulting logic has been editing and simplifed:
diff --git a/Cargo.toml b/Cargo.toml
index b458e18..1c968e3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -46,7 +46,8 @@ version = "^2.0"
default-features = false
[dependencies.lexical-core]
-version = "^0.4.0"
+path = "../../rust-lexical/lexical-core"
+version = "^0.6.0"
optional = true
[dev-dependencies]
diff --git a/src/number/complete.rs b/src/number/complete.rs
index 28abfdc..51bcd06 100644
--- a/src/number/complete.rs
+++ b/src/number/complete.rs
@@ -832,16 +832,9 @@ pub fn float<T, E:ParseError<T>>(input: T) -> IResult<T, f32, E>
where
T: crate::traits::AsBytes + InputLength + Slice<RangeFrom<usize>>,
{
- let res = ::lexical_core::try_atof32_slice(input.as_bytes());
-
- match res.error.code {
- ::lexical_core::ErrorCode::Success => Ok((input.slice(input.input_len()..), res.value)),
- ::lexical_core::ErrorCode::InvalidDigit => if res.error.index == 0 {
- Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)))
- } else {
- Ok((input.slice(res.error.index..), res.value))
- },
- _ => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float))),
+ match ::lexical_core::parse_partial::<f32>(input.as_bytes()) {
+ Ok((v, i)) => Ok((input.slice(i..), v)),
+ Err(_) => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float))),
}
}
@@ -906,16 +899,9 @@ pub fn double<T, E:ParseError<T>>(input: T) -> IResult<T, f64, E>
where
T: crate::traits::AsBytes + InputLength + Slice<RangeFrom<usize>>,
{
- let res = ::lexical_core::try_atof64_slice(input.as_bytes());
-
- match res.error.code {
- ::lexical_core::ErrorCode::Success => Ok((input.slice(input.input_len()..), res.value)),
- ::lexical_core::ErrorCode::InvalidDigit => if res.error.index == 0 {
- Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)))
- } else {
- Ok((input.slice(res.error.index..), res.value))
- },
- _ => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float))),
+ match ::lexical_core::parse_partial::<f64>(input.as_bytes()) {
+ Ok((v, i)) => Ok((input.slice(i..), v)),
+ Err(_) => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float))),
}
}
diff --git a/src/number/streaming.rs b/src/number/streaming.rs
index 914578c..8e1c97c 100644
--- a/src/number/streaming.rs
+++ b/src/number/streaming.rs
@@ -829,18 +829,15 @@ pub fn float<T, E:ParseError<T>>(input: T) -> IResult<T, f32, E>
where
T: crate::traits::AsBytes + InputLength + Slice<RangeFrom<usize>>,
{
- let res = ::lexical_core::try_atof32_slice(input.as_bytes());
-
- match res.error.code {
- ::lexical_core::ErrorCode::Success => Err(Err::Incomplete(Needed::Unknown)),
- ::lexical_core::ErrorCode::InvalidDigit => {
- if res.error.index == 0 {
- Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)))
+ match ::lexical_core::parse_partial::<f32>(input.as_bytes()) {
+ Ok((v, i)) => {
+ if i == input.input_len() {
+ Err(Err::Incomplete(Needed::Unknown))
} else {
- Ok((input.slice(res.error.index..), res.value))
+ Ok((input.slice(i..), v))
}
},
- _ => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float))),
+ Err(_) => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float))),
}
}
@@ -905,18 +902,15 @@ pub fn double<T, E:ParseError<T>>(input: T) -> IResult<T, f64, E>
where
T: crate::traits::AsBytes + InputLength + Slice<RangeFrom<usize>>,
{
- let res = ::lexical_core::try_atof64_slice(input.as_bytes());
-
- match res.error.code {
- ::lexical_core::ErrorCode::Success => Err(Err::Incomplete(Needed::Unknown)),
- ::lexical_core::ErrorCode::InvalidDigit => {
- if res.error.index == 0 {
- Err(Err::Error(E::from_error_kind(input, ErrorKind::Float)))
+ match ::lexical_core::parse_partial::<f64>(input.as_bytes()) {
+ Ok((v, i)) => {
+ if i == input.input_len() {
+ Err(Err::Incomplete(Needed::Unknown))
} else {
- Ok((input.slice(res.error.index..), res.value))
+ Ok((input.slice(i..), v))
}
- }
- _ => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float))),
+ },
+ Err(_) => Err(Err::Error(E::from_error_kind(input, ErrorKind::Float))),
}
}Next, I made sure the repository was using the local nom version:
diff --git a/le-proc-macro/Cargo.toml b/le-proc-macro/Cargo.toml
index 5e905ab..bc6def3 100644
--- a/le-proc-macro/Cargo.toml
+++ b/le-proc-macro/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-nom = "5.0.0"
+nom = { path = "../nom", version = "5.0.0" }Results
Even on Linux, prior to submitting the patches, I get the following linker errors, suggesting the issue is more than just a platform-specific bug. All the following code samples were tested using:
x86_64-unknown-linux-gnu(host)x86_64-pc-windows-gnu(cross-compiled)
$ cargo test
...
= note: /usr/bin/ld: /home/ahuszagh/git/rust-proc-macro-test-linking-error/target/debug/deps/le_proc_macro-8dbd2ca2e9b83841.ltp2306el5q7003.rcgu.o: in function `test::assert_test_result':
/home/ahuszagh/git/rust-proc-macro-test-linking-error/<::core::macros::assert_eq macros>:(.text._ZN4test18assert_test_result17had0255f09aef5585E+0x113): undefined reference to `<&T as core::fmt::Debug>::fmt'
/usr/bin/ld: /home/ahuszagh/git/rust-proc-macro-test-linking-error/target/debug/deps/le_proc_macro-8dbd2ca2e9b83841.ltp2306el5q7003.rcgu.o: in function `test::assert_test_result':
/home/ahuszagh/git/rust-proc-macro-test-linking-error/<::std::macros::panic macros>:(.text._ZN4test18assert_test_result17had0255f09aef5585E+0x18e): undefined reference to `<&T as core::fmt::Debug>::fmt'
collect2: error: ld returned 1 exit statusOnly the release mode on x86_64-unknown-linux-gnuworked, while the debug mode failed. Forx86_64-pc-windows-gnu`, both debug and release failed, with different linker issues in each case.
After applying the patches, the code runs for both the host target (x86_64-unknown-linux-gnu) and the cross-compiled target (x86_64-pc-windows-gnu), in both debug and release mode.
Ok I've found the issue with building a proc-macro crate with a "cdylib" dependency. I'm not sure if this is relevant, @nikomatsakis, to the bug classification.
Merely removing #[derive(Debug)] from types that are not publicly exposed to the root, and those that store a slice of data (or implement Debug as a slice, like a vector), crate fixes the issues. The minimal diff to patch lexical-core was:
diff --git a/lexical-core/src/atof/algorithm/bigcomp.rs b/lexical-core/src/atof/algorithm/bigcomp.rs
index 388cec3..db19256 100644
--- a/lexical-core/src/atof/algorithm/bigcomp.rs
+++ b/lexical-core/src/atof/algorithm/bigcomp.rs
@@ -48,7 +48,8 @@ if #[cfg(limb_width_64)] {
}} // cfg_if
/// Storage for a big integer type.
-#[derive(Debug, Clone, Default, PartialEq, Eq)]
+//Debug,
+#[derive(Clone, Default, PartialEq, Eq)]
pub struct Bigint {
/// Internal storage for the Bigint, in little-endian order.
///
diff --git a/lexical-core/src/atof/algorithm/bigint.rs b/lexical-core/src/atof/algorithm/bigint.rs
index d3cbb05..47733da 100644
--- a/lexical-core/src/atof/algorithm/bigint.rs
+++ b/lexical-core/src/atof/algorithm/bigint.rs
@@ -35,7 +35,8 @@ if #[cfg(feature = "radix")] {
// BIGINT
/// Storage for a big integer type.
-#[derive(Debug, Clone, PartialEq, Eq)]
+//Debug,
+#[derive(Clone, PartialEq, Eq)]
pub(super) struct Bigint {
/// Internal storage for the Bigint, in little-endian order.
data: DataType,
diff --git a/lexical-core/src/atof/algorithm/correct.rs b/lexical-core/src/atof/algorithm/correct.rs
index e6b7802..1b0ae55 100644
--- a/lexical-core/src/atof/algorithm/correct.rs
+++ b/lexical-core/src/atof/algorithm/correct.rs
@@ -38,7 +38,7 @@ macro_rules! rtrim_0 {
// FLOAT SLICE
/// Substrings and information from parsing the float.
-#[derive(Debug)]
+//#[derive(Debug)]
pub(super) struct FloatSlice<'a> {
/// Substring for the integer component of the mantissa.
integer: &'a [u8],I wasn't able to get a minimum example up-and-running, but it seems pretty clear a symbol is failing to get exported.
OK, that definitely seems like a bug. I'm not sure who would be best to cc here -- I would guess @petrochenkov, as it is likely a bug in/around the privacy/reachability code. What do you think, @petrochenkov, about prioritization here?
@petrochenkov I'm also running into this issue. Do you have any clue? (If you don't have time to dig in, that would also be useful information!)
I'm still having similar issues. In the absence of @petrochenkov, could someone else take a look?
This is the first time I see this issue, sorry.
I can verify whether this is a privacy-reachability issue if there's a minimized self-contained reproduction. Otherwise I cannot spend much time on this, unfortunately.