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

cross compile to x86_64-macos get error: "ld64.lld: error: Unable to find library for -liconv" #9725

Open
kemingy opened this issue Sep 10, 2021 · 5 comments
Labels
Milestone

Comments

@kemingy
Copy link

kemingy commented Sep 10, 2021

I'm currently using zig to cross compile a rust program to "x86_64-macos", but I got the error below:

❯ cargo build --release --target x86_64-apple-darwin                                                                                                         
   Compiling hyper v0.14.12
error: linking with `/home/admin/GitHub/hyper-test/./zig_cc_macos` failed: exit status: 1
  |
  = note: "/home/admin/GitHub/hyper-test/./zig_cc_macos" "-Wl,-exported_symbols_list,/tmp/rustcvcIcnl/list" "-m64" "-arch" "x86_64" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.0.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.1.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.10.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.11.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.12.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.13.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.14.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.15.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.2.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.3.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.4.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.5.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.6.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.7.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.8.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.hyper.087ec123-cgu.9.rcgu.o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/hyper-d09d0433dc14c30e.3e8nu6i8ao4tmcyg.rcgu.o" "-L" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps" "-L" "/home/admin/GitHub/hyper-test/target/release/deps" "-L" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libwant-c0078e8e58cb8c51.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libtry_lock-60a3b6c58ed09e5f.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libsocket2-7e539b19fcb4da6e.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libh2-d123ae5913fe5331.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libindexmap-d15ac2a35b44b355.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libhashbrown-45b994559d65d1e5.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libslab-d339af44f38326b0.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libtokio_util-86313b7b736396b8.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libfutures_sink-c3d02b526d7e18fb.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libhttparse-a6274e9dd4e57b72.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libtower_service-0867f8c5816972cf.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libfutures_channel-41fe3f32f754b93b.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libhttp_body-38e332c8b454dddc.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libfutures_util-804ae82da8621d1d.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libfutures_task-ae2df107b10cbf55.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libpin_utils-6d653a3761f7f7ec.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libfutures_core-90a3c3893743708a.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libtokio-98a29c89acf7b0d1.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libsignal_hook_registry-0c9c6e7333cb988e.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libnum_cpus-b1d360362a3f1557.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libmemchr-e6497e341e9aa325.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libonce_cell-82f2036e3f0a6f85.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libmio-d6b55ec580f7de9b.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/liblog-cee7ce2be585bfe5.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libparking_lot-8db377deed644e3c.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libparking_lot_core-a9cca2d8d2ea6fda.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/liblibc-f70457897d8642ba.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libsmallvec-81a1e0ab309aebfc.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/liblock_api-4ee58e65888ff606.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libscopeguard-c938af9413afcd02.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libinstant-11e8345134e952d0.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libhttpdate-d3b82ac3722addfc.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libhttp-c80947a020a31090.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libitoa-fbcde0ac0268e5a9.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libbytes-4635001c490a8547.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libfnv-5af274f499d973a6.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libtracing-cb5f4cbe9ef63cc6.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libpin_project_lite-4932dae7223228b6.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libtracing_core-0c80d4f35fcc3d6d.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/liblazy_static-16fbe9e96372137a.rlib" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libcfg_if-66ac3e9458fb53a7.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libstd-35b14ca5e62c7d66.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-329b6ae10a542427.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libobject-09e9356fd4907aa1.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-f077c0a492da74c3.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libgimli-01a2a2a1730ab072.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libstd_detect-736ff6c48d99c951.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-f6b7985fe24842c3.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-6ccb889196a16125.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-2bda93c117f030a0.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libunwind-bcbd09b25c64fcac.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-ef7e97011650176d.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/liblibc-104a032674bfeab8.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/liballoc-ba3aef5f5e0e8573.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-9ee1c33f7a829255.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libcore-20d0dacb579b8ca8.rlib" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-2fee5b6fdc3293e9.rlib" "-liconv" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/home/admin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/home/admin/GitHub/hyper-test/target/x86_64-apple-darwin/release/deps/libhyper-d09d0433dc14c30e.dylib" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs"
  = note: warning: unsupported linker arg: -exported_symbols_list
          warning: unsupported linker arg: /tmp/rustcvcIcnl/list
          warning: unsupported linker arg: -dead_strip
          warning: unsupported linker arg: -dylib
          ld64.lld: error: Unable to find library for -liconv
          error: FileNotFound
          

error: could not compile `hyper` due to previous error
  • zig version: 0.8.0
  • rustc version: 1.55.0
  • platform: Ubuntu 20.04
  • cargo config
[target.x86_64-apple-darwin]
linker = "./zig_cc_macos"
  • zig_cc_macos file:
#!/bin/sh
zig cc -target x86_64-macos $@
  • command: cargo build --release --target x86_64-apple-darwin
  • main.rs (copied from hyper.rs server code)
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
use std::convert::Infallible;
use std::net::SocketAddr;

async fn hello_world(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
    Ok(Response::new("Hello, World".into()))
}

#[tokio::main]
async fn main() {
    // We'll bind to 127.0.0.1:3000
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));

    // A `Service` is needed for every connection, so this
    // creates one from our `hello_world` function.
    let make_svc = make_service_fn(|_conn| async {
        // service_fn converts our function into a `Service`
        Ok::<_, Infallible>(service_fn(hello_world))
    });

    let server = Server::bind(&addr).serve(make_svc);

    // Run this server for... forever!
    if let Err(e) = server.await {
        eprintln!("server error: {}", e);
    }
}
@matu3ba
Copy link
Contributor

matu3ba commented Sep 16, 2021

@kemingy Does the error also occur on zig version 0.8.1 ?

@kemingy
Copy link
Author

kemingy commented Sep 17, 2021

@kemingy Does the error also occur on zig version 0.8.1 ?

Yes.

@andrewrk
Copy link
Member

how are you expecting the iconv dependency to be resolved?

@andrewrk andrewrk added this to the 0.10.0 milestone Nov 20, 2021
@zhaozg
Copy link
Contributor

zhaozg commented Nov 29, 2021

Failed in 0.9.0, x86_64-macos-gnu.

Maybe libiconv.tbd will help.

warning(link): library not found for '-liconv'
warning(link): Library search paths:
error(link): undefined reference to symbol '_iconv'
error(link):   first referenced in '/Users/zhaozg/work/build/luvit/x86_64-macos-gnu/luvi/CMakeFiles/luvi.dir/custom/luvi_custom.c.o'
error(link): undefined reference to symbol '_iconv_open'
error(link):   first referenced in '/Users/zhaozg/work/build/luvit/x86_64-macos-gnu/luvi/CMakeFiles/luvi.dir/custom/luvi_custom.c.o'
error(link): undefined reference to symbol '_iconv_close'
error(link):   first referenced in '/Users/zhaozg/work/build/luvit/x86_64-macos-gnu/luvi/CMakeFiles/luvi.dir/custom/luvi_custom.c.o'

@kubkon
Copy link
Member

kubkon commented Jan 14, 2022

Please see this comment for a solution to this issue with the latest nightly Zig.

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

No branches or pull requests

5 participants