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

Recommended way of adding additional libraries to link against #35

Closed
shaunmulligan opened this issue Jan 4, 2017 · 5 comments
Closed

Comments

@shaunmulligan
Copy link

@japaric thanks for this awesome project!!
I was just wondering how some one should go about adding additional libraries that need to be linked against. Some projects like https://github.com/plietar/librespot require additional dependencies such as portaudio19-dev and maybe some others. I was just wondering what is the appropriate method for adding these into cross so that the project builds correctly.

@japaric
Copy link
Contributor

japaric commented Jan 4, 2017

Simplest way: build the library as a static library in a build script and link to that.

If you want to link to a shared library and you are using the pkg-config crate, then you basically can't cross compile because that crate doesn't support cross compilation scenarios (AFAIK).

If you want to link to a cross compiled shared library provided by ubuntu, e.g. libfoo-dev:i386, or against a shared library that you intent to build manually, you'll have to override the docker and the only way to do that is to create a local image named, for example, japaric/i686-unknown-linux-gnu:v0.1.3 because that's what cross expects it to be called.

I suggest you base that local image on the ones cross uses by default. So you could use something like this for the Dockerfile:

FROM japaric/i686-unknown-linux-gnu:v0.1.3

# Or build it yourself
RUN dpkg --add-architecture i386 && \
    apt-get update && \
    apt-get install --no-install-recommends -y libfoo-dev:i386

@iav
Copy link

iav commented Sep 27, 2019

This method, and code from main page, not work.
Because Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/universe/binary-armhf/Packages, same for

FROM rustembedded/cross:aarch64-unknown-linux-gnu-0.1.16

RUN dpkg --add-architecture arm64 && \
    apt-get update && \
    apt-get install libfoo:arm64

Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/binary-arm64/Packages 404 Not Found
Because trusty have only amd64 and i386 architectures in repos.

@gdesmott
Copy link
Contributor

gdesmott commented Apr 7, 2020

I'd suggest to close this as a dup of #149 as that's basically the same issue and this ticket contains extra information about how to make this work.

@rvolgers
Copy link
Contributor

If I understand correctly, this is precisely what was fixed in 3b07a08

bors bot added a commit that referenced this issue Sep 8, 2020
454: Bump README custom-container cross version to incorporate fixes r=therealprof a=theunkn0wn1

The custom dockerfile example in the README targets cross version 0.1.16, [and is known to not actually work as-is](3b07a08).
The fix for this particular issue was released with cross 0.2, thus this PR bumps the cross version.

This became an issue in my use case as I wanted to cross-compile to a raspberry Pi, and needed to install some external libraries not included in the base images, and ran into issues such as #149 and #35 while attempting to follow the recommendation in the readme.

Bumping the cross version to 0.2.x resolved the above issues for me, and this PR is to help other users that may find themselves running into the same issues when following the readme closely.

Co-authored-by: joshua salzedo <[email protected]>
@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Jul 2, 2022

We've documented this now extensively on the wiki, including the following examples:

We've also included complete projects using examples both with pre-build hooks and custom Docker images for this purpose.

We've also made it a lot simpler, since we've added CROSS_DEB_ARCH when using pre-build hooks, so the following can be done:

[build]
pre-build = [
    "dpkg --add-architecture $CROSS_DEB_ARCH",
    "apt-get update && apt-get install --assume-yes libssl-dev:$CROSS_DEB_ARCH"
]

So this code could will actually work for nearly every target (at least those targeting Linux GNU targets with architectures supported by Debian repositories), making this quite a versatile approach.

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

No branches or pull requests

7 participants