I want to learn gtk to make GUI using c language I installed all the stuff required as per the website installation guide but then I don't know what to do next how to compile the code, I use atom for writing my c code sometimes also dev c++, so can I set up gtk in atom or dev c++ and compile my code and if not is there any good alternatives for compiling gtk code?
If you are using Dev-C++ (that project is ancient BTW, I would suggest moving on from that) I expect you are working in a Windows environment? I would suggest using MSYS2 for compiling GTK applications in Windows:
https://www.msys2.org/
MSYS uses the Pacman package manager for its shell. You will need to download the following package in order to compile GTK applications in MSYS/MinGW:
pacman -S mingw-w64-x86_64-gtk3
You should also download gcc and pkg-config to compile:
pacman -S pkg-config gcc
Note that pkg-config is generally used to compile GTK applications due to the number of dependencies that are required (Glib, Cairo, etc.). I can't imagine you possibly compiling a GTK application using Dev-C++ as a result. You should add the following line to your .bashrc file (this will be located in the home directory of MSYS):
export PKG_CONFIG_PATH="/mingw64/lib/pkgconfig:$PKG_CONFIG_PATH"
A typical compile line for a GTK application would look like this:
gcc -o <program> <program>.c $(pkg-config gtk+-3.0 --cflags --libs) -rdynamic -lm
Related
I'm running MSYS under Windows and although it works I want to know if there is such a thing as a MSYS script file.
For example to compile a GTK program in C I need to type: gcc source.c -o executable.exe 'pkg-config --cflags --libs gtk+-3.0' to compile. Is there a way to store this in a file and run the file from MSYS without having to type in the command each time (IE like .bat, .sh files)?
If you want to automate building an application, just use a build system. The Meson build system is what the GTK+ developers recommend now (and GStreamer, and many other projects). It's multiplatform, and available as a package in MSYS2 (I used it there, works like a charm). They have a simple Meson tutorial where they build a GTK application. That's 3 lines of code.
kplot is a UNIX programming library for plotting graphs on a Cairo surface. The source code is available here.
After downloading the source code I extraced it to the directory kplot-master and cd into it. Simple ls now shows
array.c
border.c
bucket.c
buffer.c
....
example0.c
example1.c
....
I am using Ubuntu 14.04 LTS. Cairo is installed in my system and I tested it by successfully compiling C codes available in [zetcode dot com slash gfx slash cairo slash cairobackends slash] (Sorry as I am not allowed to link more than two).
I am new to GTK and Cairo plotting library and would like help in the following directions:
I do not want to install kplot in my system.
I just want to learn how kplot uses Cairo.
When I use the following command:
gcc example0.c -o example `pkg-config --cflags --libs gtk+-3.0`
it produces the following error message:
example0.c:17:20: fatal error: compat.h: No such file or directory
#include "compat.h"
^
compilation terminated.
It will be very helpful if somebody shows me how to test those kplot examples without installing it.
There is no need to install.
First you will need to compile the kplot library. For that, cd to the kplot directory and run a make command. This will generate the file compat.h. After that you will be able to compile example by example with make example(n) command, or with gcc example(n).c -o example(n) `pkg-config --cflags --libs gtk+-3.0` libkplot.a -lbsd -lm command.
If you have GTK+-3.0 and Cairo dev libraries installed, everything should go well.
According to a tutorial on
https://developer.gnome.org/gtk-tutorial/stable/c39.html
for making GUI for c-apps the compiling syntax is
gcc base.c -o base `pkg-config --cflags --libs gtk+-2.0`
Its all about these backticksymbols and seem to be suited for POSIX on linux.
If backticks in this context is not allowed in CMD-windows - is there a workaround for compiling a GTK-app in c easily?
Try to use for example GTK+ for Windows (MinGW). Also see related questions How to hide command prompt for my Windows Gtk Apps? and Help compiling GTK+ on Windows using MinGW.
stackoverflow, et. al.,
I just installed Allegro 5 on my Ubuntu machine and I see some source code for this game development tool, but I do not see specific instructions for how to compile it.
For C programs I use gcc on the terminal.
My questions are:
From what directory do I compile allegro5 programs?
What compiler options are necessary? (the normal gcc someCProgram.c -o MyProgram doesnt work)
Thank-you for reading. I have read two c books so I am not a complete noob, but I have the struggles...
All the best,
user2085446
Okay, let's put this into an answer:
If your program just consists of a single .c file, you can run gcc from the path the file is in. However, in general there's nothing wrong with invoking gcc from anywhere else as long as you get the paths right.
For linking with external libraries, you need -lmylibrary options in the compiler command, e.g. -lfreetype for the freetype library and so on.
Now, this can get a bit complicated when your libraries depend on other libraries etc. That's what the pkg-config tool is for.
When you look at the allegro wiki page, you will see the following sample command:
gcc [source file(s)] -o [output] `pkg-config --libs allegro-5.0`
The pkg-config bit will resolve the relevant -l options for you.
I am having some trouble compiling 32-bit GTK+ applications on 64-bit Linux, specifically Ubuntu 10.04. Compiling 64-bit GTK+ applications works fine, and everything is set up to compile 32-bit apps as well, but it doesn't work with GTK+
I have a very simple test program that I am using for trouble shooting that is simply a gtk_init and a gtk_main, which compiles fine as -m64. I am compiling with gcc 4.6.2, calling it with:
gcc -m32 gtktest.c `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
These are the two different kinds of error messages I get:
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../x86_64-unknown-linux-gnu/bin/ld: warning: libXext.so.6, needed by /usr/lib/../lib32/libgtk-x11-2.0.so, not found (try using -rpath or -rpath-link)
and
/usr/lib/../lib32/libgdk-x11-2.0.so: undefined reference to `XmbSetWMProperties'
Keep in mind that these aren't the only errors, I just included the two specific types for reference and to keep it short, I get errors for the whole stack of GTK+ libraries.
I do have all of the proper 32-bit versions of the libraries in my lib32 folders.
Hopefull someone has had this problem before and can help me, this is really causing me quite the headaches, and I can't fine much help any where on the net.
Please ask if there is any other information you need me to provide to help with diagnosing this problem.
Note: I do have the ia32-libs and gcc-multilib packages. Ubuntu 10.04 does not have a separate ia32-libs-gtk packages, but I think these are wrapped in to the ia32-libs packages. They all are present on my system.
I think this must be some sort of linker config problem. I've recently built the new Free Pascal compiler and a 32 bit cross compiler, and I also upgraded GCC to 4.6.2 to take advantage of some of the new C++ features and fixes to C99 support. The default 4.4.3 GCC still exists on my system. Where I think the problem has been introduced is when I installed a new binutils because I've been experimenting with Clang and LLVM as a toolchain, and I wanted and ld with plug-in capabilities, so I figured might as well upgrade them all.
Everything works fine compiling 64 bit programs, there hasn't been a single problem with the new tools at all, and I can compile 32-bit programs but when it comes time to explicitly link something in I have problems.
I know my current set of libs is appropriate, and I have Free Basic installed which only emits 32 bit code, and I was able to build 32-bit GTK+ programs no problem before this upgrade.
Just wondering if anyone has any ideas what configs might have been changed in this upgrade or has had this happen to them before? I really should upgrade to a newer distro so I can take advantage of all the new software with out have to hack up all of my packages, but unfortunatly there is a bug in the newer kernels that prevents my computer from coming back from standby, and this is a laptop I use for personal side projects, so proper power management is pretty important, and it's not a huge loss if I bork the system, other than I have it set up pretty much perfect for my workflow.
You may tell pkg-config to search for the 32-bit libraries with the environment variable PKG_CONFIG_PATH.
For Ubuntu:
export PKG_CONFIG_PATH=/usr/lib32/pkgconfig:$PKG_CONFIG_PATH
For Redhat:
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:$PKG_CONFIG_PATH
I think you need to install the ia32-libs-gtk & gcc-multilib packages, and you need to compile and link with gcc -m32 as you already do.
The GTK package in 12.04 doesn't seem to work correctly with multiarch. You can work around this on Ubuntu 12.04 by creating the following symlinks:
sudo ln -s /lib/i386-linux-gnu/libglib-2.0.so.0 /usr/lib32/libglib-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0 /usr/lib32/libgtk-x11-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0 /usr/lib32/libgdk-x11-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libatk-1.0.so.0 /usr/lib32/libatk-1.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libpangox-1.0.so.0 /usr/lib32/libpangox-1.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libpango-1.0.so.0 /usr/lib32/libpango-1.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgmodule-2.0.so.0 /usr/lib32/libgmodule-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 /usr/lib32/libgobject-2.0.so
sudo ln -s /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so.0 /usr/lib32/libgdk_pixbuf-2.0.so
I found the answer in this thread: http://www.blitzbasic.com/Community/posts.php?topic=101357
Alternatively (probably better), you can leave the base system untouched and update your link to search by file name instead of library name. Something like:
gcc -m32 gtktest.c `pkg-config --cflags gtk+-2.0` -L/usr/lib/i386-linux-gnu -l:libgio-2.0.so.0 ...
This isn't great. You'll have to add a -l: for each library that the linker can't find and your build will break if the library file name ever changes.