Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

c++ - How to setup GTK+ to develop with Code::Blocks on Ubuntu Linux

I am trying to develop a GTK+ application on Ubuntu 11.4, using Code::Blocks.

www.gtk.org has instructions on building GTK+ from source, that looked complicated. But the Ubuntu package manager listed libgtk3-dev as a package that I installed.

Code::Blocks I installed using the Ubuntu Software Center.

Using the Code::Blocks project wizard to create a GTK+ project, when I build, the project fails to compile "cannot find gtk/gtk.h".

Clearly the GTK include (and lib) folders are not added to the Code::Blocks search folders. I have located the relevant paths and files...

Do I have to explicitly & manually add all the search paths to Code::Blocks' search paths? Or am I missing some installation step.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming that you have located and installed the correct package. As of 2011, the current package was libgtk-3-dev then the pkg-config tool can be used to extract the linker and compiler flags - and with proper escaping in the Code:Blocks settings can inject the correct settings automatically.

Open Code::Blocks Settings > Compiler and Linker Settings... and add the following under Global Compiler Settings > Compiler Settings > Other Options

`pkg-config --cflags gtk+-3.0`

and add this to Global Compiler Settings > Linker Settings > Other Options

`pkg-config --libs gtk+-3.0`

With the ` this has the effect of running the pkg-config tool calling --cflags gtk+-3.0 (or --libs) which, assuming libgtk3-dev is installed, injects the necessary search folders and lib directives onto the gcc command line.


As an alternative, developer.ubuntu.com lists Anjuta as a C/C++ IDE that can create GTK+ projects. As an alternative to Code::Blocks its far more polished as an Ubuntu IDE.


Scratch that. Anjuta looses its sheen quickly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...