User forums > General (but related to Code::Blocks)
GTK 3 in Ubuntu and Code::Blocks
ordak:
Hi,
I tried and compiled a GTK 3 sample code in Ubuntu 18.04 OS and Code::Blocks IDE. Code is taken from this link. And for Code::Blocks setting I used this one.
In "Compiler setting" , "Other compiler options" I used:
--- Code: ---pkg-config --libs gtk+-3.0
--- End code ---
In "Linker settings":
--- Code: ----pthread -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0
--- End code ---
In "Search directories" I added several but not all of above packages like:
--- Code: ---/usr/include/
/usr/include/atk-1.0
--- End code ---
And so on for about 8 include sources. Consequently I was able to "Build and run" my sample. A terminal was shown with a window which was expected. However I deleted first "Search directory" in order to removed all directories and build only from libraries. But now I get this error from Clang compiler:
With "Search directories":
--- Code: ---
-------------- Clean: Release in Temp (compiler: LLVM Clang Compiler 8)---------------
Cleaned "Temp - Release"
-------------- Build: Release in Temp (compiler: LLVM Clang Compiler 8)---------------
clang -m64 -pedantic -Weverything -Wall -std=c11 pkg-config --libs gtk+-3.0 -I/usr/include/ -I/usr/include/gtk-3.0 -I/usr/include/glib-2.0/ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ -I/usr/include/pango-1.0/ -I/usr/include/cairo/ -I/usr/include/gdk-pixbuf-2.0/ -I/usr/include/atk-1.0 -c /home/mehdi/Documents/Code_Blocks_Projects/Temp/Main.c -o obj/Release/Main.o
clang: error: unsupported option '--libs'
clang: error: no such file or directory: 'pkg-config'
clang: error: no such file or directory: 'gtk+-3.0'
Process terminated with status 1 (0 minute(s), 0 second(s))
3 error(s), 0 warning(s) (0 minute(s), 0 second(s))
--- End code ---
Without "Search directories":
--- Code: ---
-------------- Clean: Release in Temp (compiler: LLVM Clang Compiler 9 GTK)---------------
Cleaned "Temp - Release"
-------------- Build: Release in Temp (compiler: LLVM Clang Compiler 9 GTK)---------------
clang -m64 -pedantic -Weverything -Wall -std=c11 pkg-config --libs gtk+-3.0 -c /home/mehdi/Documents/Code_Blocks_Projects/Temp/Main.c -o obj/Release/Main.o
clang: error: unsupported option '--libs'
clang: error: no such file or directory: 'pkg-config'
clang: error: no such file or directory: 'gtk+-3.0'
Process terminated with status 1 (0 minute(s), 0 second(s))
3 error(s), 0 warning(s) (0 minute(s), 0 second(s))
--- End code ---
Any help on this now ?
Miguel Gimenez:
I haven't read your whole message, but the pkg-config --libs gtk+-3.0 command must be enclosed in backticks to work
ordak:
--- Quote from: Miguel Gimenez on October 31, 2019, 02:36:56 pm ---I haven't read your whole message, but the pkg-config --libs gtk+-3.0 command must be enclosed in backticks to work
--- End quote ---
`pkg-config --libs gtk+-3.0`
Above gives:
--- Code: ---
-------------- Clean: Release in Temp (compiler: LLVM Clang Compiler 9 GTK)---------------
Cleaned "Temp - Release"
-------------- Build: Release in Temp (compiler: LLVM Clang Compiler 9 GTK)---------------
clang -m64 -pedantic -Weverything -Wall -std=c11 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -c /home/mehdi/Documents/Code_Blocks_Projects/Temp/Main.c -o obj/Release/Main.o
clang: warning: -lgtk-3: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lgdk-3: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lpangocairo-1.0: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lpango-1.0: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -latk-1.0: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lcairo-gobject: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lcairo: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lgdk_pixbuf-2.0: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lgio-2.0: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lgobject-2.0: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lglib-2.0: 'linker' input unused [-Wunused-command-line-argument]
/home/mehdi/Documents/Code_Blocks_Projects/Temp/Main.c:2:10: fatal error: 'gtk/gtk.h' file not found
#include <gtk/gtk.h>
^~~~~~~~~~~
1 error generated.
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 11 warning(s) (0 minute(s), 0 second(s))
--- End code ---
But given "Search directories" as my original post, I was able to build. Lots of warning are generated and specially this takes some seconds to build. Can I just use libraries for every possible package and build faster than current one ?
ordak:
In other words , can I build a static library from GTK 3 and link that to my project ?
File > New > Project > Static library
from :
/usr/include/gtk-3.0
I may download newer source from gtk site too.
Note that searching for gtk static library on my system I have :
--- Code: ---:~$ mlocate *gtk*.a
/usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.a
:~$
--- End code ---
Miguel Gimenez:
--- Quote ---Lots of warning are generated
--- End quote ---
You are specifying -pedantic, -Weverything and -Wall, so don't surprise with the amount of warnings.
The 'linker' warnings are generated because you are compiling main.c to main.o, so no linking will be made, and you are specifying libraries. The pkg-config --libs part must be in the linker settings, not in the compiler settings. Linker settings should look similar to this (may be incomplete):
--- Code: ----pthread -lgthread -lrt `pkg-config --libs gtk+-3.0`
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version