# Tests failing with undefined symbol: \_\_gmpn\_set\_str on Xenial

**URL:** <https://travis-ci.community/t/tests-failing-with-undefined-symbol-gmpn-set-str-on-xenial/3551>\
**Category:** Environments\
**Created:** [May 29, 2019, 3:35pm UTC](https://travis-ci.community/t/tests-failing-with-undefined-symbol-gmpn-set-str-on-xenial/3551 "2019-05-29T15:35:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![etscrivner](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/etscrivner/32/1881_2.png) [@etscrivner](https://travis-ci.community/u/etscrivner)\
**Post date:** [May 29, 2019, 3:35pm UTC](https://travis-ci.community/t/tests-failing-with-undefined-symbol-gmpn-set-str-on-xenial/3551/1 "2019-05-29T15:35:44Z")

</div>

I’ve asked this exact question before [here](https://travis-ci.community/t/undefined-symbol-error-when-compiling-in-travis-ci-only/1647) and for the same repository [etscrivner/rbsecp256k1](https://github.com/etscrivner/rbsecp256k1). However the old fix - use Xenial - no longer works.

You can find my pull request fixing builds [here](https://github.com/etscrivner/rbsecp256k1/pull/45)

My builds were succeeding unmodified for quite a long time and nothing significant has changed in the repository since last year. This leads me to suspect that something has instead changed on the Travis CI side. Would anyone have advice on what that might be and why this would have started failing?

I have both libgmp10 and libgmp-dev dependencies installed AFAICT.

---

<div class="post-metadata">

**Author:** ![etscrivner](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/etscrivner/32/1881_2.png) [@etscrivner](https://travis-ci.community/u/etscrivner)\
**Post date:** [May 30, 2019, 5:42pm UTC](https://travis-ci.community/t/tests-failing-with-undefined-symbol-gmpn-set-str-on-xenial/3551/2 "2019-05-30T17:42:16Z")

</div>

Have tried to reproduce this issue using the travisci/ubuntu:16.04 images on Dockerhub to no avail. This issue seems to be specifically related to how the travisci system is configured itself. Test Dockerfile is below:

```
FROM travisci/ubuntu-ruby:16.04

RUN apt-get update
RUN apt-get install -y build-essential automake pkg-config libtool \
  libffi-dev libssl-dev python-dev ruby ruby-dev ruby-build

ADD Gemfile Gemfile Rakefile Makefile rbsecp256k1.gemspec /app/
COPY ext /app/ext/
COPY lib /app/lib/
COPY spec /app/spec/

RUN \curl -sSL https://get.rvm.io | bash
RUN /bin/bash -l -c "rvm use 2.4 --install --binary --fuzzy"
RUN ruby --version
RUN gem update --system
# RUN export BUNDLE_GEMFILE=/app/Gemfile
RUN gem install bundler

WORKDIR /app
RUN bundle install --jobs=3 --retry=3
RUN make setup
RUN make build
RUN make test WITH_RECOVERY=1 WITH_ECDH=1
```

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [May 30, 2019, 10:05pm UTC](https://travis-ci.community/t/tests-failing-with-undefined-symbol-gmpn-set-str-on-xenial/3551/3 "2019-05-30T22:05:37Z")

</div>

Googling suggests that this happens if you don’t link against the right `.so` and suggests troubleshooting tools:

[gcc - Linux shared library that uses a shared library undefined symbol - Stack Overflow](https://stackoverflow.com/questions/2991572/linux-shared-library-that-uses-a-shared-library-undefined-symbol)  
[c++ - Easy check for unresolved symbols in shared libraries? - Stack Overflow](https://stackoverflow.com/questions/1617286/easy-check-for-unresolved-symbols-in-shared-libraries)

---

<div class="post-metadata">

**Author:** ![etscrivner](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/etscrivner/32/1881_2.png) [@etscrivner](https://travis-ci.community/u/etscrivner)\
**Post date:** [June 1, 2019, 2:27pm UTC](https://travis-ci.community/t/tests-failing-with-undefined-symbol-gmpn-set-str-on-xenial/3551/4 "2019-06-01T14:27:53Z")

</div>

Thanks for the feedback. I am unable to reproduce this error anywhere but within TravisCI itself. I have tried the following and all work:

- Building on a personal Linux machine.
- Building on a personal macOS machine.
- Building in Docker against the TravisCI Ubuntu 16.04 docker image from dockerhub.

All of these work and the library is linked correctly. I see in the output of the Makefile config that the library is found:

```
checking for -lgmp... yes
checking for secp256k1_recovery.h... no
checking for secp256k1_ecdh.h... no
creating Makefile

```

All of this is quite puzzling. Especially since this build worked for quite a long time and then started breaking all of a sudden. So my guess is something has changed specifically on TravisCI.

---

<div class="post-metadata">

**Author:** ![etscrivner](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/etscrivner/32/1881_2.png) [@etscrivner](https://travis-ci.community/u/etscrivner)\
**Post date:** [June 8, 2019, 4:36pm UTC](https://travis-ci.community/t/tests-failing-with-undefined-symbol-gmpn-set-str-on-xenial/3551/5 "2019-06-08T16:36:36Z")

</div>

I’ve figured out the issue here. GCC was compiling with the `-Wl,--as-needed` linker flag by default and this was causing libgmp - which was not needed by the library itself, but instead one of its dependencies, to register as missing.

By adding the `-Wl,--no-as-needed` flag I was able to fix this.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [June 8, 2019, 4:56pm UTC](https://travis-ci.community/t/tests-failing-with-undefined-symbol-gmpn-set-str-on-xenial/3551/6 "2019-06-08T16:56:33Z")

</div>

> [@etscrivner](#):
>
> which was not needed by the library itself, but instead one of its dependencies

This suggests that that “dependency” is not specifying that it depends on `libgmp` when it should.
