1

I've been trying to compile an open-source C++ project Typesense, which has this list of dependencies:

  • Snappy
  • zlib
  • OpenSSL (>=1.0.2)
  • curl
  • ICU
  • brpc
  • braft

Host and target OS is Debian Linux. Compilation is handled via cmake->make sequence of commands. I was able to install some of dependencies through a package manager (I believe they reside in /usr/lib then), the last two I had to compile on my own, I put them in /usr/local/lib.

All the dependencies were successfully compiled, and the target project compiled too.

When it comes to linking stage, I get numerous errors like

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-easy.o): in function `global_init':
(.text+0x94): undefined reference to `libssh2_init'

...

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-http2.o): in function `on_header':
(.text+0x6c): undefined reference to `nghttp2_session_get_stream_user_data'

...

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-socks_gssapi.o): in function `check_gss_err.part.0':
(.text+0x57): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0x77): undefined reference to `gss_display_status'
/usr/bin/ld: (.text+0x9b): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0xcf): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0xef): undefined reference to `gss_display_status'
/usr/bin/ld: (.text+0x112): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0x17e): undefined reference to `gss_release_buffer'

...

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-curl_rtmp.o): in function `rtmp_connect':
(.text+0xd4): undefined reference to `RTMP_Connect1'

...

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-openldap.o): in function `ldap_connecting':
(.text+0x111): undefined reference to `ldap_result'

There is at least a hundred of such errors. I'm not at all proficient with Linux and complex building of projects. How do I possibly fix linking errors for libraries that I just downloaded through a package manager?

EDIT: Libraries, that cmake seems to link against at the end:

braft;
brpc;
/usr/lib/x86_64-linux-gnu/libleveldb.a;
glog;
h2o-evloop;
iconv;
/usr/lib/x86_64-linux-gnu/libcurl.a;
for;
/usr/lib/x86_64-linux-gnu/libicui18n.a;
/usr/lib/x86_64-linux-gnu/libicuuc.a;
/usr/lib/x86_64-linux-gnu/libicudata.a;
rocksdb;
/usr/lib/x86_64-linux-gnu/libsnappy.a;
/usr/lib/x86_64-linux-gnu/libz.a;
rt;
/usr/lib/x86_64-linux-gnu/libssl.a;
/usr/lib/x86_64-linux-gnu/libcrypto.a;
pthread;
dl;
-static-libgcc;
-static-libstdc++;
gflags_shared;
/usr/lib/x86_64-linux-gnu/libprotobuf.a;
-lpthread
Alexey Larionov
  • 3,049
  • 1
  • 12
  • 27
  • Do you install devel pckages of library? – Farhad Sarvari Aug 09 '20 at 12:02
  • Please show your link command. – n. 'pronouns' m. Aug 09 '20 at 12:04
  • @n.'pronouns'm. I don't have a link command per se. `CMakeLists.txt` has among the lines `FIND_PACKAGE(CURL REQUIRED)`, `include_directories(${CURL_INCLUDE_DIR})`, but then there is a section with `link_directories(...)`, which doesn't mention `curl`, and finally `target_link_libraries(typesense-server ${CORE_LIBS})` where `CORE_LIBS` doesn't contains the following (see the question edit): – Alexey Larionov Aug 09 '20 at 12:21
  • @FarhadSarvari I have `libcurl4-openssl-dev is already the newest version (7.64.0-4+deb10u1)` report from `apt-get`, not sure how to track all the dependencies of `curl` though, and whether I have to install their `dev` versions – Alexey Larionov Aug 09 '20 at 12:26

1 Answers1

1

Your dependency list is incomplete. It only includes immediate dependencies.

Your version of libcurl is built with ssh, gssapi, nghttp2, ldap, rtmp and possibly other goodies, none of which you are linking against. You are using static linking, and static libraries do not have a built in concept of dependencies. This means you have to manually include all the non-immediate dependencies in your build command. You can get the impression of how many more libraries you need to include by executing this command

ldd /path/to/your/libcurl.so

and observing the list of dependencies your libcurl has.

The same thing may be true about other libraries you use.

One way to resolve the issue is to use dynamic linking. This way you just link to immediate dependencies, and they know their dependencies.

n. 'pronouns' m.
  • 95,181
  • 13
  • 111
  • 206
  • I'll mark the answer as accepted, since it turned me onto closer way to solution. The problem was with `FIND_PACKAGE(CURL REQUIRED)`, it tried to grab somewhat wrong version of the library. Had to use [this question](https://stackoverflow.com/questions/26704629/setting-up-curl-library-path-in-cmake) to solve it by adding `SET(CURL_LIBRARY "-lcurl")` – Alexey Larionov Aug 13 '20 at 22:16