undefined reference to `dlopen' since ubuntu upgrade - c

i experience the undefined reference to `dlopen' problems since I have upgraded to ubuntu 13.10 and gcc 4.8.1.
The makefiles are working for years already. the particular call is
gcc -rdynamic -o ov_dbutil ov_dbutil.o libov.so -ldl
The errors are:
libov.so: undefined reference to `dlopen'
libov.so: undefined reference to `dlclose'
libov.so: undefined reference to `dlerror'
libov.so: undefined reference to `dlsym'
collect2: error: ld returned 1 exit status
make: *** [ov_dbutil] Error 1
is it a gcc problem?
ov_dbutil is compiled with the following lines
gcc -g -Wall -O0 -shared -std=c99 -fno-strict-aliasing -DPLT_SYSTEM_LINUX=1 -DPLT_USE_BUFFERED_STREAMS=1 -DPLT_SERVER_TRUNC_ONLY=1 -DNDEBUG -DOV_SYSTEM_LINUX=1 -I../../../plt/include/ -I../../../ks/include/ -I../../include/ -I../../model/ -I../../source/codegen/ -I../../source/builder/ -I../../source/example/ -I../../source/kshist/ -I../../source/dynov/ -I../../source/tasklib/ -I../../source/dbparse/ -I../../source/dbdump/ -I../../../../libml/ -I../../include/runtimeserver/ -I. -c ../../source/dbutil/ov_dbutil.c -o ov_dbutil.o
no errors or warnings

Add -Wl,--no-as-needed as linker arguments.

My issue was solved by adding -ldl in the lining line of the .so you want to link agains, it was called libov.so in the upper example.

Related

MonetDB test client application not linking

I tried to compile test application for MonetDB under Ubuntu 14.04 LTS Trusty Tahr. I followed the download instructions from official site, installation was successful, then I installed a bunch of other packages in order to copmpile it. Now when I try to compile and link test application I get the following errors:
libtool: compile: gcc -c -I/usr/include/monetdb test.c -fPIC -DPIC -o .libs/test.o
libtool: compile: gcc -c -I/usr/include/monetdb test.c -o test.o >/dev/null 2>&1
libtool: link: gcc -o test test.o -lmapi -lstream -lssl -lcrypto -lcurl -lz
test.o: In function `die':
test.c:(.text+0x1c): undefined reference to `mapi_explain_query'
test.c:(.text+0x27): undefined reference to `mapi_result_error'
test.c:(.text+0x3f): undefined reference to `mapi_explain_result'
test.c:(.text+0x4a): undefined reference to `mapi_next_result'
test.c:(.text+0x5a): undefined reference to `mapi_close_handle'
test.c:(.text+0x65): undefined reference to `mapi_destroy'
test.c:(.text+0x81): undefined reference to `mapi_explain'
test.c:(.text+0x8c): undefined reference to `mapi_destroy'
test.o: In function `query':
test.c:(.text+0xde): undefined reference to `mapi_query'
test.c:(.text+0xf2): undefined reference to `mapi_error'
test.o: In function `update':
test.c:(.text+0x133): undefined reference to `mapi_close_handle'
test.o: In function `main':
test.c:(.text+0x190): undefined reference to `mapi_connect'
test.c:(.text+0x1a0): undefined reference to `mapi_error'
test.c:(.text+0x222): undefined reference to `mapi_fetch_field'
test.c:(.text+0x23a): undefined reference to `mapi_fetch_field'
test.c:(.text+0x266): undefined reference to `mapi_fetch_row'
test.c:(.text+0x276): undefined reference to `mapi_close_handle'
test.c:(.text+0x282): undefined reference to `mapi_destroy'
collect2: error: ld returned 1 exit status
./t.sh: 11: ./t.sh: ./test: not found
What I'm doing wrong? What should I additionally install or change in compilation options for successful linking of test example?
I was able to compile the example on Ubuntu 14.04 with MonetDB installed from the Ubuntu binary packages after installing the (additional) package libmonetdb-client-dev with the following command:
gcc test.c -I /usr/include/monetdb -lmapi
Did you compile and install MonetDB from source? In this case, which prefix was used?
Here how it worked using ubuntu 18.04
gcc main.c -I /usr/include/monetdb -lmapi -lssl -lcrypto -lstream -lcurl -llzma -lbz2

Unable to make ethping program because of missing pcap definitions

I seem to be having an issue building the ethping executable. It cannot find any of the functions that are defined in pcap.h.
At first I thought it wasn't finding pcap.h, but I have checked the $PATH and /usr/include is there (the pcap.h there is a stub that then includes pcap/pcap.h, but that looks all good too).
I even tried -I /usr/include and -I /usr/include/pcap, but still no luck.
I have searched through tons of forum postings, but could not find a solution. So that's why I am here. Any ideas?
root:src# gcc -Wall -Werror -ggdb -g -O2 -lpcap -o ethping ethping.o ieee8021ag.o dot1ag_eth.o
ethping.o: In function `timeout_handler':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:65: undefined reference to `pcap_breakloop'
ethping.o: In function `main':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:183: undefined reference to `pcap_open_live'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:202: undefined reference to `pcap_compile'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:203: undefined reference to `pcap_setfilter'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:254: undefined reference to `pcap_next_ex'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:257: undefined reference to `pcap_perror'
collect2: error: ld returned 1 exit status
Similarly:
root:src# gcc -Wall -Werror -ggdb -g -O2 -lpcap -I /usr/include/pcap -o ethping ethping.o ieee8021ag.o dot1ag_eth.o
ethping.o: In function `timeout_handler':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:65: undefined reference to `pcap_breakloop'
ethping.o: In function `main':
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:183: undefined reference to `pcap_open_live'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:202: undefined reference to `pcap_compile'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:203: undefined reference to `pcap_setfilter'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:254: undefined reference to `pcap_next_ex'
/home/ubuntu/Downloads/dot1ag-utils-master/src/ethping.c:257: undefined reference to `pcap_perror'
collect2: error: ld returned 1 exit status
root:src#
Changing the compile line fixed it. Placing -lpcap at the far right got it going as suggested.
gcc -Wall -Werror -ggdb -g -O2 -o ethping ethping.o ieee8021ag.o dot1ag_eth.o -lpcap
Either you are invoking the linker without the arguments to include the libpcap library, or the libraries are not installed. See http://www.tcpdump.org/ to obtain the library. Or if you are on a well-supported distribution, use the applicable install command:
sudo apt-get install libpcap-dev
or
sudo yum install libpcap-dev

Compiling C code with Redis on linux

How to correct following error when I compiled test code written in C using credis API:
gcc -g -Wall -lcredis test_redis.c -o redisOUT
/tmp/ccetckOb.o: In function `main':
/home/faris/Downloads/credis-0.2.3/test_redis.c:12: undefined reference to `credis_connect'
/home/faris/Downloads/credis-0.2.3/test_redis.c:15: undefined reference to `credis_ping'
/home/faris/Downloads/credis-0.2.3/test_redis.c:18: undefined reference to `credis_set'
/home/faris/Downloads/credis-0.2.3/test_redis.c:21: undefined reference to `credis_get'
/home/faris/Downloads/credis-0.2.3/test_redis.c:25: undefined reference to `credis_close'
collect2: error: ld returned 1 exit status
Example on: http://code.google.com/p/credis/wiki/Examples
I'm busting my head for so long.
Thanks for solution.
Sam Iverish
Put the library after the source file that references it:
gcc -g -Wall test_redis.c -lcredis -o redisOUT

What causes this link failure (undefined reference)?

I just switched my dev machine from Gentoo to Arch Linux and, when I try to compile a fresh build of my project, linking fails:
clang -O0 -g -pipe -Wall -DDEBUG -o slug announce.o bitfield.o main.o metadata.o network.o parser.o peer.o piece.o scheduler.o torrent.o url.o util.o -I. -lssl -lm -lcurl -levent
/usr/bin/ld.gold: metadata.o: in function get_info_hash:metadata.c:186: error: undefined reference to 'SHA1_Init'
/usr/bin/ld.gold: metadata.o: in function get_info_hash:metadata.c:187: error: undefined reference to 'SHA1_Update'
/usr/bin/ld.gold: metadata.o: in function get_info_hash:metadata.c:188: error: undefined reference to 'SHA1_Final'
/usr/bin/ld.gold: piece.o: in function verify_piece:piece.c:40: error: undefined reference to 'SHA1_Init'
/usr/bin/ld.gold: piece.o: in function verify_piece:piece.c:41: error: undefined reference to 'SHA1_Update'
/usr/bin/ld.gold: piece.o: in function verify_piece:piece.c:42: error: undefined reference to 'SHA1_Final'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [slug] Error 1
The entire source is on GitHub: https://github.com/robertseaton/slug.
Looks like you're missing -lcrypto
From my experience, the location of -lssl or -lcrypto may be the source of the problem. Try to push -lcrypto option to the end of the gcc options, or before input object files.

GNU readline History feature

I'm using this code for the history features in my shell:
http://cc.byexamples.com/20080613/gnu-readline-how-to-keep-a-history-list-of-entered-command-lines/
but when I compile this using gcc, I got this error
$ gcc filename.c
/tmp/ccay2CgM.o: In function `main':
rl.c:(.text+0x9): undefined reference to `rl_abort'
rl.c:(.text+0x13): undefined reference to `rl_bind_key'
rl.c:(.text+0x1d): undefined reference to `readline'
rl.c:(.text+0x61): undefined reference to `add_history'
collect2: ld returned 1 exit status
$
The example compile line is
g++ -o simple_rl{,.cpp} -lreadline
Did you forget to add the -lreadline?
Compile with this:
gcc -lreadline -lncurses -o simple_rl{,.cpp}

Resources