How to compile program with gtk+-3.0? - c

I am using GTK+-3.0 in ubuntu 12.04. I am trying to compile program but every time fail
apple#ubuntu:~/Downloads$ gcc -Wall -g gtktest.c $(pkg-config --libs --cflags gtk+-3.0) -o gtktest
gtktest.c: In function ‘main’:
gtktest.c:21:3: warning: implicit declaration of function ‘gtk_signal_connect’ [-Wimplicit-function-declaration]
gtktest.c:21:3: warning: implicit declaration of function ‘GTK_OBJECT’ [-Wimplicit-function-declaration]
gtktest.c:21:3: warning: implicit declaration of function ‘GTK_SIGNAL_FUNC’ [-Wimplicit-function-declaration]
gtktest.c:22:3: warning: implicit declaration of function ‘gtk_container_border_width’ [-Wimplicit-function-declaration]
gtktest.c:28:3: warning: implicit declaration of function ‘gtk_signal_connect_object’ [-Wimplicit-function-declaration]
/tmp/ccH48jvQ.o: In function `main':
/home/apple/Downloads/gtktest.c:21: undefined reference to `GTK_SIGNAL_FUNC'
/home/apple/Downloads/gtktest.c:21: undefined reference to `GTK_OBJECT'
/home/apple/Downloads/gtktest.c:21: undefined reference to `gtk_signal_connect'
/home/apple/Downloads/gtktest.c:22: undefined reference to `gtk_container_border_width'
/home/apple/Downloads/gtktest.c:26: undefined reference to `GTK_SIGNAL_FUNC'
/home/apple/Downloads/gtktest.c:26: undefined reference to `GTK_OBJECT'
/home/apple/Downloads/gtktest.c:26: undefined reference to `gtk_signal_connect'
/home/apple/Downloads/gtktest.c:28: undefined reference to `GTK_OBJECT'
/home/apple/Downloads/gtktest.c:28: undefined reference to `GTK_SIGNAL_FUNC'
/home/apple/Downloads/gtktest.c:28: undefined reference to `GTK_OBJECT'
/home/apple/Downloads/gtktest.c:28: undefined reference to `gtk_signal_connect_object'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_lookup'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_insert'
/usr/local/lib/libcairo.so: undefined reference to `pixman_composite_glyphs'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_remove'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_get_mask_format'
/usr/local/lib/libcairo.so: undefined reference to `pixman_composite_glyphs_no_mask'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_thaw'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_freeze'
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_create'
collect2: ld returned 1 exit status
With another command.
apple#ubuntu:~/Downloads$ gcc -Wall -g gtktest.c $(pkg-config --libs --cflags glib-2.0) -o gtktest
In file included from /usr/include/gtk-3.0/gdk/gdkapplaunchcontext.h:30:0,
from /usr/include/gtk-3.0/gdk/gdk.h:32,
from /usr/local/include/gtk-3.0/gtk/gtk.h:32,
from gtktest.c:1:
/usr/include/gtk-3.0/gdk/gdktypes.h:37:19: fatal error: cairo.h: No such file or directory
compilation terminated.
Any one how to solve this problem i am trying to solve this problem for last 4 days. Please someone can give me proper solution?

gtktest.c:21:3: warning: implicit declaration of function ‘gtk_signal_connect’
The code you are compiling was made for a very old version of GTK+. You will have to modify the code if you want it to compile, let alone work, with GTK+3. Compiling with GTK+2 will almost certainly be easier to start with.
/usr/local/lib/libcairo.so: undefined reference to `pixman_glyph_cache_lookup'
I'm guessing your version of cairo expects a newer pixman than what you are linking with: e.g. pixman_glyph_cache_lookup() was added in pixman 0.27.2.
The last example tries to compile GTK code without GTK include flags: that's just not going to work.

Use
-lcairo or $(pkg-config --libs --cflags cairo)
and -lpixman or -lpixman-1

Related

Gcc error when using ncurses library in a C program [duplicate]

This question already has answers here:
Statically link ncurses to program
(3 answers)
Closed 1 year ago.
I'm trying ncurses C library for the first time in a little test program and every time I try to output the executable file using gcc it gives me an error.
Here is the test program:
#include <ncurses.h>
int main() {
initscr();
printw("--------\n| test |\n--------\n\n");
refresh();
printw("\npress any key to exit...");
refresh();
getch();
endwin();
return 0;
}
Here are the gcc commands and their output:
$ gcc -Wall -lncurses -c tests.c
$ gcc tests.o -o tests
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.o: warning: relocation against `stdscr' in read-only section `.text'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.o: in function `main':
tests.c:(.text+0x5): undefined reference to `initscr'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x16): undefined reference to `printw'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x1d): undefined reference to `stdscr'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x25): undefined reference to `wrefresh'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x36): undefined reference to `printw'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x3d): undefined reference to `stdscr'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x45): undefined reference to `wrefresh'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x4c): undefined reference to `stdscr'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x54): undefined reference to `wgetch'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: tests.c:(.text+0x59): undefined reference to `endwin'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
I tried to find a solution but didn't find any, so any help is appreciated.
Note: Does the fact that I'm using Wayland display server with no X client has something to do with the error ?
The libraries have to be added at the end of the command line as they are searched for symbols only one-time and the linking is done in the order specified.
gcc tests.o -o tests -lncurses

Issue with makefile on Ubuntu

I am trying to install a program that consist of a folder with some C files. I run the makefile but i get the following error:
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1128: undefined reference to `tgoto'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1129: undefined reference to `tputs'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1138: undefined reference to `tputs'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1145: undefined reference to `tputs'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1154: undefined reference to `tputs'
readline/libreadline.a(display.o): In function `delete_chars':
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1182: undefined reference to `tgoto'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1183: undefined reference to `tputs'
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/display.c:1189: undefined reference to `tputs'
readline/libreadline.a(signals.o): In function `cr':
/home/silviu/Desktop/tipsy-2.2.3d/code/readline/signals.c:301: undefined reference to `tputs'
collect2: error: ld returned 1 exit status
Do you know how can I solve it? (on Ubuntu)
You have used tputs in c program so you must have use #include <curses.h> and #include <term.h>. Undefined reference is linker error. In Makefile while compiling c program you should link -lcurses or -lncurses. Add similar line to your Makefile. compile with appropriate linking library.
For example
gcc file.c -o output_file -lcurses -ltermcap
or
gcc file.c -o output_file -lcurses -ltermcap

I used Zbar on Raspberry to san qrcode but there are some problems

I have installed zbar library and gtk library on Raspberry,but when I compile the example zbargtk.c that provided by the zbar,it can't be compiled.
The command I used is gcc -o testgtk testgtk.c pkg-config --libs --cflags gtk+-2.0 zbar.
I have spent three days to deal this problem,but I can't solve it.
Here are the errors i get:
pi#raspberrypi ~/Desktop $ gcc -o testgtk testgtk.c `pkg-config --libs --cflags gtk+-2.0 zbar`
testgtk.c: In function ‘main’:
testgtk.c:149:5: warning: ‘g_thread_init’ is deprecated (declared at /usr/include/glib-2.0/glib/deprecated/gthread.h:261) [-Wdeprecated-declarations]
/tmp/ccF6LqbT.o: In function `video_enabled':
testgtk.c:(.text+0x12c): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x148): undefined reference to `zbar_gtk_get_video_enabled'
testgtk.c:(.text+0x154): undefined reference to `zbar_gtk_get_video_opened'
/tmp/ccF6LqbT.o: In function `video_opened':
testgtk.c:(.text+0x1dc): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x1f8): undefined reference to `zbar_gtk_get_video_opened'
testgtk.c:(.text+0x204): undefined reference to `zbar_gtk_get_video_enabled'
/tmp/ccF6LqbT.o: In function `video_changed':
testgtk.c:(.text+0x2b8): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x300): undefined reference to `zbar_gtk_set_video_device'
/tmp/ccF6LqbT.o: In function `status_button_toggled':
testgtk.c:(.text+0x320): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x33c): undefined reference to `zbar_gtk_get_video_opened'
testgtk.c:(.text+0x348): undefined reference to `zbar_gtk_get_video_enabled'
testgtk.c:(.text+0x378): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x398): undefined reference to `zbar_gtk_set_video_enabled'
/tmp/ccF6LqbT.o: In function `open_button_clicked':
testgtk.c:(.text+0x55c): undefined reference to `zbar_gtk_get_type'
testgtk.c:(.text+0x57c): undefined reference to `zbar_gtk_scan_image'
/tmp/ccF6LqbT.o: In function `main':
testgtk.c:(.text+0x620): undefined reference to `g_thread_init'
testgtk.c:(.text+0x708): undefined reference to `zbar_gtk_new'
testgtk.c:(.text+0x920): undefined reference to `scan_video'
collect2: ld returned 1 exit status

Compiling an allegro5 program using make

I have a program called zone.c that uses the allegro5 library.
I have a makefile that consists of just these two lines.
zone: zone.c
gcc zone.c -o zone $(pkg-config --cflags --libs allegro-5.0 allegro_primitives-5.0)
when I type "make" I get these errors:
/tmp/ccyCx3Hy.o: In function main':
zone.c:(.text+0x14): undefined reference toal_install_system'
zone.c:(.text+0x23): undefined reference to al_create_display'
zone.c:(.text+0x3b): undefined reference toal_map_rgb'
zone.c:(.text+0x70): undefined reference to al_clear_to_color'
zone.c:(.text+0x84): undefined reference toal_map_rgb'
zone.c:(.text+0xd1): undefined reference to al_draw_filled_circle'
zone.c:(.text+0xe5): undefined reference toal_map_rgb'
zone.c:(.text+0x132): undefined reference to al_draw_filled_circle'
zone.c:(.text+0x137): undefined reference toal_flip_display'
zone.c:(.text+0x14f): undefined reference to al_rest'
zone.c:(.text+0x15b): undefined reference toal_destroy_display'
collect2: error: ld returned 1 exit status
make: * [zone] Error 1
But if I just copy out the line "gcc zone.c -o zone $(pkg-config --cflags --libs allegro-5.0 allegro_primitives-5.0)" and run it manually, it compiles fine and the program works.
If I use similar makefiles to compile programmes that don't use allegro5, then make works.
Does anybody have a clue what's going on?
If you want a literal $ in your rule, you have to escape it from make by writing $$ instead:
zone: zone.c
gcc zone.c -o zone $$(pkg-config --cflags --libs allegro-5.0 allegro_primitives-5.0)

Statically link ncurses to program

I'm having some problems statically linking ncurses to one of my programs
Here's a really simple sample program:
#include<ncurses.h>
int main(){
initscr();
printw("Hello world\n");
refresh();
getch();
endwin();
return 0;
}
When I compile it with
gcc -static -lncurses hello_curses.c -o curses
I get these errors:
/tmp/ccwHJ6o1.o: In function `main':
curses_hello.c:(.text+0x5): undefined reference to `initscr'
curses_hello.c:(.text+0x14): undefined reference to `printw'
curses_hello.c:(.text+0x1b): undefined reference to `stdscr'
curses_hello.c:(.text+0x20): undefined reference to `wrefresh'
curses_hello.c:(.text+0x27): undefined reference to `stdscr'
curses_hello.c:(.text+0x2c): undefined reference to `wgetch'
curses_hello.c:(.text+0x31): undefined reference to `endwin'
collect2: ld returned 1 exit status
I'm a little confused why this isn't working. What am I missing here?
You need to pass -l options at the end of the command line:
gcc -static hello_curses.c -o curses -lncurses
When the compiler encounters -lfoo, it links in all the symbols from foo that have been requested by a previous file. If you put -lfoo at the beginning, no symbol has been requested yet, so no symbol gets linked.
Edit:
I think the real problem is that you need to specify your -l option at the end of the command. I just tried it the way you had it and reproduced your error. If I put -l:libncurses.a at the end of the line then it works. All without the -static option BTW.
I think what is happening is that you have a dynamic library for ncurses but you have used the -static option which means to not use any dynamic libraries. I suspect you do not actually have a static version of the ncurses library i.e. one ending with a .a suffix.
If you want to link with the static version (.a) of ncurses rather than the dynamic version (.so) then temporarily remove the symlink for libncurses.so so that the linker picks up the .a file instead. Alternatively copy the .a file somewhere else and add that to an earlier search path.
Alternatively if your linker supports it (eg. ld) then you could specify -l:libncurses.a instead of -lncurses.
I just spent a few hours on an ARM processor, trying to get it to work, as the accepted answer didn't work for me.
Here are my findings:
Apparently
gcc -static hello_curses.c -o curses -lncurses
works on an x64 processor, but not on an ARM processor.
When I tried with the above line, I still got all the "undefined reference errors" (and a lot more) of the OP.
You need to also link against libtinfo.a, and note that sequence matters.
This is the correct command line that works:
gcc -static hello_curses.c -o curses -lncurses -ltinfo
If you mix up the sequence, then it won't work...
gcc -static hello_curses.c -o curses -ltinfo -lncurses
undefined reference to `unctrl'
Of course this also works if you use the :lib syntax
This compiles
gcc -static hello_curses.c -o curses -l:libncursesw.a -l:libtinfo.a
This does not compile
gcc -static hello_curses.c -o curses -l:libtinfo.a -l:libncursesw.a
Oh how I like gcc...
This program should never have been allowed to graduate from kindergarden
(.text+0x2a8): undefined reference to cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_pair': (.text+0x2ac): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_pair': (.text+0x50a): undefined reference to tparm'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_pair': (.text+0x518): undefined reference to
_nc_putp'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_color': (.text+0x552): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_color': (.text+0x556): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_color': (.text+0x5e4): undefined reference to
tparm'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioninit_color': (.text+0x5f2): undefined reference to
_nc_putp'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioncan_change_color': (.text+0x740): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioncan_change_color': (.text+0x744): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functionhas_colors': (.text+0x768): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functionhas_colors': (.text+0x76c): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In functioncolor_content': (.text+0x7c2): undefined reference to
cur_term'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):(.text+0x7c6):
more undefined references tocur_term' follow
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function _nc_do_color': (.text+0x8de): undefined reference to
tparm'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function _nc_do_color': (.text+0x8e6): undefined reference to
tputs'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function _nc_do_color': (.text+0x958): undefined reference to
tputs'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function set_foreground_color': (.text+0x62): undefined reference
totputs'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_color.o):
In function set_background_color': (.text+0xa2): undefined reference
totputs'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_hline.o):
In function whline': (.text+0xec): undefined reference toacs_map'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_hline.o):
In function whline': (.text+0xf0): undefined reference toacs_map'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_add_wch.o):
In function wadd_wch': (.text+0x4fe): undefined reference to
TABSIZE'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_add_wch.o):
In function wadd_wch': (.text+0x502): undefined reference to
TABSIZE'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_add_wch.o):
In function wecho_wchar': (.text+0x6d8): undefined reference to
TABSIZE'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_add_wch.o):
In function wecho_wchar': (.text+0x6dc): undefined reference to
TABSIZE'
/usr/lib/gcc/arm-linux-gnueabihf/4.8/../../../arm-linux-gnueabihf/libncursesw.a(lib_wunctrl.o):
In function wunctrl': (.text+0x30): undefined reference tounctrl'
collect2: error: ld returned 1 exit status

Resources