GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 24, 2014 9:21 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Compiling a GTK program, that uses libraries MySql (gcc)
PostPosted: Thu Apr 12, 2012 10:53 am 
Offline
Familiar Face

Joined: Thu Apr 12, 2012 10:34 am
Posts: 8
Compiling a GTK program, that uses libraries MySql (gcc complier)

Hi all, I wanted to submit a problem that happened to me recently when I use the GTK libraries.

My intention was to create a GUI in C (using GTK) to interact with a MySQL database (using the libraries provided by mysql.com).

We place now that I typed the command on Linux shell (Ubuntu 11.40):
Code:
gcc -Wall -g main.c -o main `mysql_config --cflags --libs` `pkg-config --cflags --libs gtk+-2.0`

Unfortunately known that the compiler can not link the MySQL libraries, thus giving me these errors:
Code:
main.c: 14:1: error: unknown type name 'MYSQL'
main.c: 16:3: error: unknown type name 'MYSQL'
main.c: 16:3: warning: implicit declaration of function 'mysql_init' [-Wimplicit-function-declaration]
main.c: 16:29: warning: initialization Makes pointer from integer without a cast [enabled by default]
main.c: 19:5: warning: implicit declaration of function 'mysql_real_connect' [-Wimplicit-function-declaration]
main.c: 21:7: warning: implicit declaration of function 'mysql_close' [-Wimplicit-function-declaration]
main.c: 25:5: warning: implicit declaration of function 'mysql_select_db' [-Wimplicit-function-declaration]

Honestly, are not very experienced in using the GCC compiler, so if any of you could help me out, I would be very grateful! :)

PS: safe place for you also what the compiler in verbose mode printed on the screen:
Code:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6.1/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
COLLECT_GCC_OPTIONS='-Wall' '-g' '-v' '-I' '/usr/include/mysql' '-D' 'BIG_JOINS=1' '-fno-strict-aliasing' '-D' 'UNIV_LINUX' '-D' 'UNIV_LINUX' '-rdynamic' '-L/usr/lib/mysql' '-pthread' '-I' '/usr/include/gtk-2.0' '-I' '/usr/lib/i386-linux-gnu/gtk-2.0/include' '-I' '/usr/include/atk-1.0' '-I' '/usr/include/cairo' '-I' '/usr/include/gdk-pixbuf-2.0' '-I' '/usr/include/pango-1.0' '-I' '/usr/include/gio-unix-2.0/' '-I' '/usr/include/glib-2.0' '-I' '/usr/lib/i386-linux-gnu/glib-2.0/include' '-I' '/usr/include/pixman-1' '-I' '/usr/include/freetype2' '-I' '/usr/include/libpng12' '-pthread' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-linux-gnu/4.6.1/cc1 -quiet -v -I /usr/include/mysql -I /usr/include/gtk-2.0 -I /usr/lib/i386-linux-gnu/gtk-2.0/include -I /usr/include/atk-1.0 -I /usr/include/cairo -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/pango-1.0 -I /usr/include/gio-unix-2.0/ -I /usr/include/glib-2.0 -I /usr/lib/i386-linux-gnu/glib-2.0/include -I /usr/include/pixman-1 -I /usr/include/freetype2 -I /usr/include/libpng12 -imultilib . -imultiarch i386-linux-gnu -D_REENTRANT -D BIG_JOINS=1 -D UNIV_LINUX -D UNIV_LINUX main.c -quiet -dumpbase main.c -mtune=generic -march=i686 -auxbase main -g -Wall -version -fno-strict-aliasing -fstack-protector -o /tmp/ccBDxZjT.s
GNU C (Ubuntu/Linaro 4.6.1-9ubuntu3) version 4.6.1 (i686-linux-gnu)
   compiled by GNU C version 4.6.1, GMP version 5.0.1, MPFR version 3.0.1-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=83 --param ggc-min-heapsize=99869
ignoring nonexistent directory "/usr/local/include/i386-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../i686-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/mysql
/usr/include/gtk-2.0
/usr/lib/i386-linux-gnu/gtk-2.0/include
/usr/include/atk-1.0
/usr/include/cairo
/usr/include/gdk-pixbuf-2.0
/usr/include/pango-1.0
/usr/include/gio-unix-2.0/
/usr/include/glib-2.0
/usr/lib/i386-linux-gnu/glib-2.0/include
/usr/include/pixman-1
/usr/include/freetype2
/usr/include/libpng12
/usr/lib/gcc/i686-linux-gnu/4.6.1/include
/usr/local/include
/usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed
/usr/include/i386-linux-gnu
/usr/include
End of search list.
GNU C (Ubuntu/Linaro 4.6.1-9ubuntu3) version 4.6.1 (i686-linux-gnu)
   compiled by GNU C version 4.6.1, GMP version 5.0.1, MPFR version 3.0.1-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=83 --param ggc-min-heapsize=99869
Compiler executable checksum: 4563c158c7f73de3aa3de4c02c58d3f9


Top
 Profile  
 
 Post subject: Re: Compiling a GTK program, that uses libraries MySql (gcc)
PostPosted: Thu Apr 12, 2012 5:41 pm 
Offline
Familiar Face

Joined: Tue Feb 09, 2010 12:33 am
Posts: 32
Hello clarkent91,

Have a look at using libgda, http://www.gnome-db.org/

Patrick


Top
 Profile  
 
 Post subject: Re: Compiling a GTK program, that uses libraries MySql (gcc)
PostPosted: Thu Apr 12, 2012 8:44 pm 
Offline
Familiar Face

Joined: Thu Apr 12, 2012 10:34 am
Posts: 8
Thank you good advice Patrick, I'll keep it in mind for future projects! ;)

But what I was looking for is there a way to use the GCC compiler to compile a program that exploits the graphical interface provided by GTK.

The problem is that, whether you use lidgda that the API of MySQL, I do not know how to instruct the compiler to compile my application.


Top
 Profile  
 
 Post subject: Re: Compiling a GTK program, that uses libraries MySql (gcc)
PostPosted: Thu Apr 12, 2012 10:32 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
You are already familiar with compiling and linking in gtk to your c program; mysql is no different. Simply put it or the relevant library names next to gtk+-2.0 in the string you send to pkg-config and pkg-config will do the rest of it for you (to check you have the name right look in your prefix/lib/pkg-config directory). Make sure you have the -dev headers installed.


Top
 Profile  
 
 Post subject: Re: Compiling a GTK program, that uses libraries MySql (gcc)
PostPosted: Fri Apr 13, 2012 9:11 am 
Offline
Familiar Face

Joined: Thu Apr 12, 2012 10:34 am
Posts: 8
That the development headers are installed I am sure, because the only programs that use gtk, or just the MySQL API, compile correctly.
The problem comes when I decide to compile a program that utlizzi both libraries.

In your opinion, the arguments that pass in GCC are correct?
Code:
gcc -Wall -g main.c -o main `mysql_config --cflags --libs` `pkg-config --cflags --libs gtk+-2.0`


Top
 Profile  
 
 Post subject: Re: Compiling a GTK program, that uses libraries MySql (gcc)
PostPosted: Fri Apr 13, 2012 1:07 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Actually my mistake. MySQL is one of those annoying pieces of software that doesn't use .pc files. I gave your compilation instructions a test on a piece of software that kepica had developed for MySQL and gtk2 (http://www.gtkforums.com/viewtopic.php?f=16&t=55595). It worked perfectly, no errors (I'm on Ubuntu 12.04). So I would think it's either a simple error in your code or something to do with your configuration.
Do you have the right sql_config file? You say you downloaded the libraries from mysql.com. You would probably be better obtaining them through apt-get in order to ensure they are configured right for your distribution (I sourced mine from libmysqlclient-dev).


Top
 Profile  
 
 Post subject: Re: Compiling a GTK program, that uses libraries MySql (gcc)
PostPosted: Fri Apr 13, 2012 6:10 pm 
Offline
Familiar Face

Joined: Thu Apr 12, 2012 10:34 am
Posts: 8
That was the problem! mysql.com library was not suited to my linux distribution.
Now compiles fine, thanks for everything! :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group