GNU readline History feature - c

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}

Related

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

undefined reference to `dlopen' since ubuntu upgrade

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.

How to compile using libmosquitto

Iam trying to compile the code example available on the libmosquitto website (at the bottom):
http://mosquitto.org/man/libmosquitto-3.html
Iam using Ubuntu 12.04 and I've installed libmosquitto1 and libmosquitto1-dev packages. Before installing them I added the mosquitto repository:
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
Iam trying to compile the example as follows:
gcc -lmosquitto mosquito.c -o mosquito
But I get the following errors:
/tmp/cc6eU8kw.o: In function `my_connect_callback':
mosquito.c:(.text+0xf8): undefined reference to `mosquitto_subscribe'
/tmp/cc6eU8kw.o: In function `main':
mosquito.c:(.text+0x298): undefined reference to `mosquitto_lib_init'
mosquito.c:(.text+0x2b4): undefined reference to `mosquitto_new'
mosquito.c:(.text+0x310): undefined reference to `mosquitto_log_callback_set'
mosquito.c:(.text+0x324): undefined reference to `mosquitto_connect_callback_set'
mosquito.c:(.text+0x338): undefined reference to `mosquitto_message_callback_set'
mosquito.c:(.text+0x34c): undefined reference to `mosquitto_subscribe_callback_set'
mosquito.c:(.text+0x364): undefined reference to `mosquitto_connect'
mosquito.c:(.text+0x3b4): undefined reference to `mosquitto_loop'
mosquito.c:(.text+0x3c8): undefined reference to `mosquitto_destroy'
mosquito.c:(.text+0x3d0): undefined reference to `mosquitto_lib_cleanup'
collect2: ld returned 1 exit status
Can someone give me some tips on how to compile this simple example?
Thanks
You have to put the -lmosquitto at the end (after the source files).
gcc mosquito.c -lmosquitto -o mosquito
# or
gcc mosquito.c -o mosquito -lmosquitto
# or
gcc -o mosquito mosquito.c -lmosquitto
Or better:
gcc -Wall -Wextra -pedantic -o mosquito mosquito.c -lmosquitto

Errors Creating A Shared Library DLL for SWIG Simple Lua Example (Windows 7)

I use MinGW to create, and my lua version is 5.1.4 the followings are my steps:
swig -lua example.i
gcc -c example_wrap.c -I C:\Lua\5.1\include
gcc -c example.c -I C:\Lua\5.1\include
gcc -shared example_wrap.o example.o -o example.dll
errors ocurrs at last step, here are some part of the errors information
example_wrap.o:example_wrap.c:(.text+0x2aef): undefined reference to `lua_gettop'
example_wrap.o:example_wrap.c:(.text+0x2afe): undefined reference to `lua_gettop'
example_wrap.o:example_wrap.c:(.text+0x2b2d): undefined reference to `lua_pushfstring'
example_wrap.o:example_wrap.c:(.text+0x2b38): undefined reference to `lua_error'
example_wrap.o:example_wrap.c:(.text+0x2b67): undefined reference to `lua_pushnumber'
example_wrap.o:example_wrap.c:(.text+0x2ec0): undefined reference to `lua_pushvalue'
example_wrap.o:example_wrap.c:(.text+0x2ee3): undefined reference to `lua_pushstring'
example_wrap.o:example_wrap.c:(.text+0x2efe): undefined reference to `lua_pushcclosure'
example_wrap.o:example_wrap.c:(.text+0x2f11): undefined reference to `lua_rawset'
example_wrap.o:example_wrap.c:(.text+0x2f24): undefined reference to `lua_pushstring'
example_wrap.o:example_wrap.c:(.text+0x2f3f): undefined reference to `lua_pushcclosure'
example_wrap.o:example_wrap.c:(.text+0x2f52): undefined reference to `lua_rawset'
collect2: ld returned 1 exit status
it seems that I didn't include the lua header?
so I also try these commands but no use
gcc -shared example_wrap.o example.o -I C:\Lua\5.1\include -o example.dll
so any suggestions?
Try to link with this command:
gcc -LC:\Lua\5.1\bin -shared example_wrap.o example.o -llua51 -o example.dll
the path in the -LC:\Lua\5.1\bin part should point to the directory where you have your lua51.dll (I assumed bin, as in my system, but change it to suit your installation).

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

Resources