- Fixing the ‘Undefined Reference’ Errors for C/C++ Projects
- Cmake undefined reference to symbol ‘dlsym@@GLIBC_2.2.5 even though I link with -ldl
- 1 Answer 1
- Undefined Reference to Symbol ‘ ‘ . Error Adding Symbols: DSO Missing From Command Line (With CMake)
- Error building in Linux (undefined reference to symbol ‘XConvertSelection’) #500
- Comments
- cornedor commented Jul 23, 2014
- hokein commented Jul 27, 2014
- cornedor commented Jul 28, 2014
- aegypius commented Jul 28, 2014
- cornedor commented Jul 29, 2014
- aegypius commented Jul 29, 2014
- cornedor commented Jul 29, 2014
- aegypius commented Jul 29, 2014
- cornedor commented Jul 29, 2014
- cornedor commented Aug 5, 2014
- hokein commented Aug 5, 2014
- zcbenz commented Aug 5, 2014
- zcbenz commented Aug 12, 2014
- cornedor commented Aug 12, 2014
- nuivall commented Aug 31, 2014
- rprichard commented Nov 14, 2014
- anaisbetts commented Nov 14, 2014
- undefined reference to symbol ‘inflate’ #138
- Comments
- kowalcj0 commented May 23, 2016 •
- siccegge commented May 23, 2016
- kowalcj0 commented May 23, 2016 •
- arybczak commented May 23, 2016 •
- kowalcj0 commented May 23, 2016 •
- kowalcj0 commented May 23, 2016
- kowalcj0 commented May 23, 2016
- kowalcj0 commented May 23, 2016
- arybczak commented May 23, 2016
- arybczak commented May 23, 2016
- kowalcj0 commented May 24, 2016
- kowalcj0 commented May 24, 2016
- kowalcj0 commented May 24, 2016
- arybczak commented May 24, 2016
- kowalcj0 commented May 24, 2016 •
- Corin-EU commented Nov 5, 2016 •
- Corin-EU commented Nov 6, 2016
- Corin-EU commented Nov 6, 2016
- arybczak commented Nov 6, 2016
- Corin-EU commented Nov 6, 2016 •
- arybczak commented Nov 20, 2016
- Corin-EU commented Nov 21, 2016
Fixing the ‘Undefined Reference’ Errors for C/C++ Projects
This tutorial shows how to various problems related to missing symbols in C/C++ projects. We will create a basic project calling the png_create_read_struct() function from the libpng library and will go through common missing setup steps, explaining the errors that will arise.
Before you begin, install VisualGDB 5.4 or later.
- Start Visual Studio and locate the VisualGDB Linux Project Wizard:
- Pick a name and location for your project:
- Press “Create” to launch the VisualGDB-specific part of the wizard. On the first page, pick Create a new project -> Application -> MSBuild:
- In this tutorial we will use a cross-toolchain that runs on Windows and builds code for a Linux target and will demonstrate points of failure caused by this configuration. However, most of the steps shown below will work for projects built directly on Linux as well:
- Press “Finish” to generate the project. Now we will try calling a function from the libpng library and will go through most possible missing steps that could cause a build-time or run-time error. Add the following code to the main() function and try building the project:
Источник
Cmake undefined reference to symbol ‘dlsym@@GLIBC_2.2.5 even though I link with -ldl
I’m getting undefined reference to dlsym@@GLIBC_2.2.5 even after linking it before and after the libraries. However in the linking output it appears that it’s linking just before, but linking before all libraries should work, I guess.
This is how I’m linking it in CMake:
As you can see I’ve put dl before and after everything just to make sure.
If I understand correctly, .a libs do not have dependencies, they only have missing symbols and we have to fill them. Seems like I’m doing that by linking with -ldl
1 Answer 1
Would you inspect carefully the actual command line used for linking, you will find that after libsmoltcp_cpp_interface_rust.a , which has missed symbol, there is no -ldl parameter.
It seems that in your case smoltcp_cpp is an IMPORTED library target, which has libsmoltcp_cpp_interface_rust.a as a link dependency (not as IMPORTED_LOCATION property or so).
While CMake preserves order of the libraries, linked into a single binary (an or another library), order between dependencies of these libraries is not defined.
You need to add -ldl as a link dependency for the smoltcp_cpp target itself:
However, this will work only if libsmoltcp_cpp_interface_rust.a is a direct link dependency for smoltcp_cpp target, that is specified as
In case of indirect dependencies, like
you need to add -ldl as a dependency for that .
Ideally, every IMPORTED target should be self-contained, so you may safely link with that target without knowing its internals.
Источник
Undefined Reference to Symbol ‘ ‘ . Error Adding Symbols: DSO Missing From Command Line (With CMake)
Quick overview of the problem:
I am writing a project and was able to get the code I had written (so far) to compile, so I thought to myself I should start writing an example executable to make sure everything is working as I intended. I am a novice at C++ and even more of a novice at CMake (so forgive me if the code doesn’t look well). After creating the ground work for the executable file I decided to make it and I ended up getting the error:
From my understanding this is actually a CMake error and that I’m either failing to add a library or maybe I am failing to find a function in my C++ code I wrote(?):
(I am less inclined to believe the C++ code is what’s wrong, but honestly I have no idea at this point.) I have done some snooping around online and tried some things from other posts, i.e., moving the library around to make sure the libsconfigurator-libs library was being creating before adding the executable to CMake, checking to make sure I was actually including the libsconfigurator-libs library, changing things from PRIVATE to PUBLIC , etc.
The main src CMake file is written as:
The executable file is located down in the examples sub-directory, so I moved that add_subdirectory to the bottom of the file. That way, I could make sure to add all of the other libraries I created to the main cfucr library. The examples CMake file is written as:
Basically, to just create the executable and add the main library to it. The configurator library is super simple and is given as:
I have been trying to fix this for a bit now but nothing seems to work/I don’t fully understand how all of this works to really be able to fix the problem on my own. If anyone has any ideas on what I might be doing incorrectly I would love to hear it. Also, if I need to post anything else (any more CMake files or source files) to help make things clearer let me know and I will post them!
Источник
Error building in Linux (undefined reference to symbol ‘XConvertSelection’) #500
Comments
cornedor commented Jul 23, 2014
I’ve tried compiling it on Debian Jessie & Ubuntu 14.04 (clean install) and get the error on both systems.
The text was updated successfully, but these errors were encountered:
hokein commented Jul 27, 2014
Also faced the same issue on Ubuntu 14.04 LTS.
cornedor commented Jul 28, 2014
Doesn’t seem to be fixed in #524. But it does fail at a different symbol now.
aegypius commented Jul 28, 2014
Same kind of failure on Gentoo Linux missing libs are:
cornedor commented Jul 29, 2014
I’ve been able to compile atom-shell on Ubuntu 12.04 after installing libcap-dev libxtst-dev libnspr4-dev libmimelib1-dev libnss3-tools libnss3-dev. I’m not sure if I need all those packages but it worked. I suspect that libchromiumcontent.so is build with a version of clang that is not compatible with clang 3.4.2 (Ubuntu 12.04 uses clang 3.0).
aegypius commented Jul 29, 2014
@cornedor I am using clang-3.4.2 too on gentoo, I will check for these missing libraries
cornedor commented Jul 29, 2014
@aegypius I’ve tried installing those libs on debian, but I think those missing deps is a different issue.
aegypius commented Jul 29, 2014
@cornedor you might be right. I think I have actually all I need to get it compiled (symbols are defined) but linker command missing some lib flags.
cornedor commented Jul 29, 2014
When I get home I’ll try to compile https://github.com/brightray/libchromiumcontent using a more recent clang to see if that can fix the problem.
cornedor commented Aug 5, 2014
@zcbenz What system do you use to build the releases?
hokein commented Aug 5, 2014
I can build it on ubuntu 12.04 TLS.
zcbenz commented Aug 5, 2014
The releases and lbchromiumcontent’s prebuilt binaries were built on Ubuntu 12.04 with clang 3.0 (the default one).
I’m afraid the only solution is to provide prebuilt binaries of lbchromiumcontent for multiple distributions, which is tracked at #259 and I don’t have time to do recently.
I’m closing this as a duplicate of #259.
zcbenz commented Aug 12, 2014
From 72e8b28 the libchromiumcontent used by atom-shell has been compiled with clang 3.4, not sure if it fixed your problems but you can have a try.
cornedor commented Aug 12, 2014
Sadly not, I get still the same error, however is see that travis compiles using clang 3.4 with succes. My Debian installation has clang 3.4.2. I’m starting to doubt if clang really is the problem here.
nuivall commented Aug 31, 2014
I was able to build on ubuntu 14.04 by hacking out/[Release|Debug]/obj/atom.ninja files. You need to add «-lXrandr -lXext -lX11 -lgconf-2» to libs variable and «-rpath /opt/atom» to ldflags.
I don’t know root cause but I have a feeling that it may be solved by upgrade to chrome 37 because currently even libchromiumcontent build scripts doesn’t handle ubuntu 14.04 properly.
rprichard commented Nov 14, 2014
FWIW, I got atom-shell to build on Xubuntu 14.04 x86_64 by installing two extra packages:
And applying this patch to the gyp file:
anaisbetts commented Nov 14, 2014
@zcbenz We should think about creating a way to build everything from source on Linux — that’s generally the only sane way to work around a lot of these issues. Like, a flag we can pass to script/bootstrap that rigs stuff to build from source
Источник
undefined reference to symbol ‘inflate’ #138
Comments
kowalcj0 commented May 23, 2016 •
I can’t compile the latest version on ncmpcpp on rpi 3 running Ubuntu Mate 16.04 LTS kernel 4.4.11-v7+
The text was updated successfully, but these errors were encountered:
siccegge commented May 23, 2016
Looks like a bug in your libcurl
/usr/bin/ld: /usr/lib/arm-linux-gnueabihf/libcurl-gnutls.so: undefined reference to symbol ‘inflate’
kowalcj0 commented May 23, 2016 •
it’s the latest available version for the ARM cpus
Will compile the 7.49 from source or the simply build ncmpcpp without curl support
arybczak commented May 23, 2016 •
Symbol inflate is in zlib. What is the output of curl-config —libs ? It should contain -lz .
kowalcj0 commented May 23, 2016 •
it doesn’t contain -lz @arybczak
ps. omitting the —with-curl option when running ./configure.sh didn’t solve the issue
btw. here’s the configuration I’d like to have
./configure —with-curl —with-fftw —with-taglib —enable-outputs —enable-visualizer —enable-clock —enable-unicode
kowalcj0 commented May 23, 2016
ps. what happened to last 2 or 3 comments?
they just disappeared!
ps. when I run curl-config —libs on my laptop there’s also no -lz , but I’ve got no problems with building the project. Here’s the output on my laptop
and here’s from rpi 3:
kowalcj0 commented May 23, 2016
strange, all the comments are visible again.
kowalcj0 commented May 23, 2016
arybczak commented May 23, 2016
Github was having some issues earlier, I guess that’s the reason.
As for zlib, do you have it installed? Can you do LDFLAGS=»-lz» ./configure . and see if that fixes the problem?
arybczak commented May 23, 2016
If all fails, you can compile without curl by passing —without-curl to configure.
kowalcj0 commented May 24, 2016
Then I tried compiling it without the cURL and it failed as well but with slightly different error:
kowalcj0 commented May 24, 2016
I gave up and I’ve installed ncmpcpp 0.7 from the official repo.
kowalcj0 commented May 24, 2016
I just tried installing libghc-zlib-dev but that didn’t help.
arybczak commented May 24, 2016
What happens if you run LIBS=»-lz» ./configure . (LIBS instead of LDFLAGS)?
kowalcj0 commented May 24, 2016 •
Corin-EU commented Nov 5, 2016 •
The problem with missing libraries when linking, is not resolved just by appending the library to the list of libraries. Order DOES matter. The missing library (libz) which supplies the symbol (inflate) has to be positioned before the library (libcurl-gnutls) which uses the symbol, eg
-lz -L/usr/lib/arm-linux-gnueabihf /usr/lib/arm-linux-gnueabihf/libcurl-gnutls.so
The source of the problem appears to be that configure uses «curl-config» which does not include «-lz» in its output string for «curl-config —libs».
So one way get around this issue is to patch configure.ac to include «-lz» in the correct position.
See included patch — multiple backquotes in code prevent showing code in markdown styling mode.
configure.ac.patch.txt
Once that patch is applied, then «autoreconf -fiv» must be invoked to rebuild «configure» as well as «aclocal.m4». It only «autogen.sh» is run, then on systems running a different libtool version (eg 2.4.2 on Debian stable/jessie) to that used to create the autoconf files being distributed (2.4.6) the result is that linking aborts with a libtool version mismatch error complaining about LT_INIT being the incorrect version value.
Corin-EU commented Nov 6, 2016
OOPS. My comment above «The missing library (libz) which supplies the symbol (inflate) has to be positioned before the library (libcurl-gnutls) which uses the symbol» got the order the wrong way around.
According to the rules of linking order, libz must be placed after libcurl-gnutls ie request first, then supply.
On attempting the compilation on i386 Linux Mint 18 (based Ubuntu 16.04) with gcc 5.4.0, linking failed after applying the patch with the same error about missing inflate. On moving -lz to after -ltag, linking then works.
g++ -O3 -fno-strict-aliasing -march=native -std=c++0x -o ncmpcpp comparators.o html.o option_parser.o string.o type_conversions.o wide_string.o actions.o bindings.o browser.o charset.o clock.o configuration.o curl_handle.o display.o enums.o format.o global.o help.o helpers.o lastfm.o lastfm_service.o lyrics.o lyrics_fetcher.o macro_utilities.o media_library.o mpdpp.o mutable_song.o ncmpcpp.o outputs.o playlist.o playlist_editor.o screen.o screen_type.o scrollpad.o search_engine.o sel_items_adder.o server_info.o settings.o song.o song_info.o song_list.o sort_playlist.o status.o statusbar.o tag_editor.o tags.o tiny_tag_editor.o title.o visualizer.o window.o -lboost_filesystem -lboost_system -lboost_locale -lboost_program_options -lboost_regex -licuuc -licudata -lboost_thread -L/usr/local/lib /usr/local/lib/libmpdclient.so -lreadline -lpthread -lncursesw -ltinfo -lfftw3 -L/usr/lib/i386-linux-gnu /usr/lib/i386-linux-gnu/libcurl.so -ltag -lz -pthread -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/lib/i386-linux-gnu -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/lib/i386-linux-gnu
What I do not understand why the «-lz» before libcurl.so works on Debian Jessie with gcc 4.9. I cannot do a test on that system moving it to after, until tomorrow. (I thought I had tried it after before submitting my solution and if had not worked.)
Corin-EU commented Nov 6, 2016
Incidentally the ncmpcpp configure is using curl-config. I thought that use of *-config scripts was considered deprecated and that PACKAGE CONFIG .pc files should always be used when available.
`
prefix=/usr
exec_prefix=$
includedir=$
supported_protocols=»DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTMP RTSP SMB SMBS SMTP SMTPS TELNET TFTP»
supported_features=»SSL IPv6 UnixSockets libz AsynchDNS IDN GSS-API SPNEGO Kerberos NTLM NTLM_WB TLS-SRP»
Name: libcurl
URL: http://curl.haxx.se/
Description: Library to transfer files with ftp, http, etc.
Version: 7.47.0
Libs: -L$
Libs.private: -lidn -lrtmp -lssl -lcrypto -lssl -lcrypto -L/usr/lib/i386-linux-gnu/mit-krb5 -Wl,-Bsymbolic-functions -Wl,-z,relro -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -llber -llber -lldap -lz
Cflags: -I$
`
arybczak commented Nov 6, 2016
The source of the problem appears to be that configure uses «curl-config» which does not include «-lz» in its output string for «curl-config —libs».
Mine does — it appears it’s a bug in curl.
I thought that use of *-config scripts was considered deprecated
I don’t know anything about that.
Corin-EU commented Nov 6, 2016 •
I have now tested building ncmpcpp 0.7.7 on Debian Jessie 8.6 on armhf with the patch to add «-lz» after «ltags» (where it should be according to the rules) and it does build successfully with that.
`— configure.ac.orig 2016-10-31 12:24:35.000000000 +0100
+++ configure.ac 2016-10-31 12:24:35.000000000 +0100
@@ -342,5 +342,7 @@
fi
fi
+LIBS=»$LIBS -lz»
+
AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile])
AC_OUTPUT`
The reason why using the LIBS=»-lz» environmental variable does not work is because its contents are prepended to the lists of libraries to be linked against, which of course does not work.
So using this patch on both Linux Mint 18 (based on Ubunt 16.04) and Debian 8.6 Jessie results in no «missing inflate» symbol and a successful build.
Incidentally it is also necessary to also build one’s own copy of libtag (1.11.1 now available) (and the dependent libtag-extras if desired) because linking against the libtag supplied by Linux Mint 18 and Debian 8.6 Jessies results in numerous undefined errors mentioned in another issue.
As for «I don’t know anything about that.», if you read articles such as «Best practices with autotools» dated August 23, 2005, they mention the use of pkg-config (which consults the pc files) and most software distritbutions provided a pkg-config file now rather than a
For a HOWTO use guide on pkg-config see
arybczak commented Nov 20, 2016
configure.ac now uses pkgconfig for libcurl.
Corin-EU commented Nov 21, 2016
Thank you for updating configure.ac to now use pkgconfig for libcurl (and hopefully other
info -lfftw3 -lcurl -L/usr/local/lib -ltag libtool: link: g++ -O3 -fno-strict-aliasing -march=native -std=c++14 -o ncmpcpp comparators.o html.o option_parser.o string.o type_conversions.o wide_string.o actions.o bindings.o browser.o charset.o clock.o configuration.o curl_handle.o display.o enums.o format.o global.o help.o helpers.o lastfm.o lastfm_service.o lyrics.o lyrics_fetcher.o macro_utilities.o media_library.o mpdpp.o mutable_song.o ncmpcpp.o outputs.o playlist.o playlist_editor.o screen.o screen_type.o scrollpad.o search_engine.o sel_items_adder.o server_info.o settings.o song.o song_info.o song_list.o sort_playlist.o status.o statusbar.o tag_editor.o tags.o tiny_tag_editor.o title.o visualizer.o window.o -lz -lboost_filesystem -lboost_system -lboost_locale -lboost_program_options -lboost_regex -licuuc -licudata -L/usr/local/lib /usr/local/lib/libmpdclient.so -lreadline -lpthread -lncursesw -ltinfo -lfftw3 /usr/lib/i386-linux-gnu/libcurl.so -ltag -pthread -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/lib/i386-linux-gnu -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/lib/i386-linux-gnu /usr/bin/ld: /usr/lib/i386-linux-gnu/libcurl.so: undefined reference to symbol ‘inflate’ /usr/lib/i386-linux-gnu/libz.so: error adding symbols: DSO missing from command line
The patch supplied above
still needs to be applied for successful building
/bin/sh ../libtool —tag=CXX —mode=link g++ -O3 -fno-strict-aliasing -march=native -std=c++14 -o ncmpcpp comparators.o html.o option_parser.o string.o type_conversions.o wide_string.o actions.o bindings.o browser.o charset.o clock.o configuration.o curl_handle.o display.o enums.o format.o global.o help.o helpers.o lastfm.o lastfm_service.o lyrics.o lyrics_fetcher.o macro_utilities.o media_library.o mpdpp.o mutable_song.o ncmpcpp.o outputs.o playlist.o playlist_editor.o screen.o screen_type.o scrollpad.o search_engine.o sel_items_adder.o server_info.o settings.o song.o song_info.o song_list.o sort_playlist.o status.o statusbar.o tag_editor.o tags.o tiny_tag_editor.o title.o visualizer.o window.o -lz -lboost_filesystem -lboost_system -lboost_locale -lboost_program_options -lboost_regex -licuuc -licudata -L/usr/local/lib -lmpdclient -lreadline -lpthread -lncursesw -ltinfo -lfftw3 -lcurl -L/usr/local/lib -ltag -lz libtool: link: g++ -O3 -fno-strict-aliasing -march=native -std=c++14 -o ncmpcpp comparators.o html.o option_parser.o string.o type_conversions.o wide_string.o actions.o bindings.o browser.o charset.o clock.o configuration.o curl_handle.o display.o enums.o format.o global.o help.o helpers.o lastfm.o lastfm_service.o lyrics.o lyrics_fetcher.o macro_utilities.o media_library.o mpdpp.o mutable_song.o ncmpcpp.o outputs.o playlist.o playlist_editor.o screen.o screen_type.o scrollpad.o search_engine.o sel_items_adder.o server_info.o settings.o song.o song_info.o song_list.o sort_playlist.o status.o statusbar.o tag_editor.o tags.o tiny_tag_editor.o title.o visualizer.o window.o -lboost_filesystem -lboost_system -lboost_locale -lboost_program_options -lboost_regex -licuuc -licudata -L/usr/local/lib /usr/local/lib/libmpdclient.so -lreadline -lpthread -lncursesw -ltinfo -lfftw3 /usr/lib/i386-linux-gnu/libcurl.so -ltag -lz -pthread -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/lib/i386-linux-gnu -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/lib/i386-linux-gnu make[2]: Leaving directory ‘/srv/repository/git/ncmpcpp/src’
You no doubt want to keep this issue closed, but after nearly 5 months since the original post, you have actually applied a fix, unless you consider that the solution is people should switch from Debian Jessie and Linux Mint18/Ubuntu 16.04 to another distribution which has a properly built libcurl.
Источник