Search code examples
rusttravis-cicross-compilingccrust-crates

Linker cc not found when cross-compiling simple crate on Travis CI


As part of one of my projects, I have to cross-compile a Rust crate from x86_64 to i686 on Linux. I'm currently using Travis CI for this, with a simple Hello World crate (the default binary crate). My Travis CI configuration for the relevant matrix entry is:

# ...

matrix:
  include:
    # ...
    - os: linux
      rust: 1.30.0
      before_script:
        - sudo apt-get update
        - sudo apt-get install -y libc6-dev:i386
      env: TARGET=i686-unknown-linux-gnu
  # ...

script:
  - rustup target install $TARGET
  - cargo build --release --target=$TARGET

Unfortunately, when I push this configuration to Travis CI, I get a build error:

$ cargo build --release --target=$TARGET
   Compiling test-rust-deploy-releases v0.1.0 (/home/travis/build/arnavb/test-rust-deploy-releases)
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: Could not compile `test-rust-deploy-releases`.
To learn more, run the command again with --verbose.
The command "cargo build --release --target=$TARGET" exited with 101.

How do I fix this?


Solution

  • Well, after experimenting and more googling, I changed my apt install command to:

    sudo apt-get install -y gcc-4.8 cpp-4.8 gcc-multilib
    

    (The first two are unmet dependencies of the third, which had to be manually installed).

    Now the build runs properly.