ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am a competent user of Ubuntu 8.04, competent in python but just starting to learn C++.
I want to start making GUIs using gtk. On my system the gtk header files,installed with the system are in /usr/include/gtk-2.0/gtk.
I've been attempting an extremely basic script to try to access the header files, like this:
#include <iostream>
using namespace std;
#include <gtk>
int main() {
cout << "DONE";
return 0;
}
When attempting to compile it, I've been using the -I flag to direct it to the gtk header files. However I get a long list of errors like this:
gtk/gtkwindow.h:218: error: ‘GtkWindow’ was not declared in this scope
gtk/gtkwindow.h:218: error: ‘window’ was not declared in this scope
gtk/gtkwindow.h:219: error: ‘gboolean’ was not declared in this scope
etc etc.
Is this a namespace issue? Can someone tell me how to go about including these gtk header files, or maybe point me to an existing web page somewhere which addresses the issue.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Rep:
Quote:
Originally Posted by cbabbage
I am a competent user of Ubuntu 8.04, competent in python but just starting to learn C++.
I want to start making GUIs using gtk. On my system the gtk header files,installed with the system are in /usr/include/gtk-2.0/gtk.
I've been attempting an extremely basic script to try to access the header files, like this:
#include <iostream>
using namespace std;
#include <gtk>
int main() {
cout << "DONE";
return 0;
}
When attempting to compile it, I've been using the -I flag to direct it to the gtk header files. However I get a long list of errors like this:
gtk/gtkwindow.h:218: error: ‘GtkWindow’ was not declared in this scope
gtk/gtkwindow.h:218: error: ‘window’ was not declared in this scope
gtk/gtkwindow.h:219: error: ‘gboolean’ was not declared in this scope
etc etc.
Is this a namespace issue? Can someone tell me how to go about including these gtk header files, or maybe point me to an existing web page somewhere which addresses the issue.
Thanks in advance,
cb.
C++ namespaces are stupid.
all includes should before any using statments
You have a path issue, not a namespace one (always look at the first error from the compiler).
The gtk libraries have lots of include and library directories (not just /usr/include/gtk2.0), so it is usually easier just to use pkg-config to generate these, eg:
Code:
gcc `pkg-config gtk+-2.0 --cflags --libs` test.c
If you are using the C++ wrappers for gtk, you can also use gtkmm-config, eg:
Code:
g++ `gtkmm-config --cflags --libs` test.cpp
Last edited by neonsignal; 10-27-2009 at 07:28 PM.
Namespaces shouldn't be causing problems here.. The first problem is that your include should be <gtk/gtk.h>, not just <gtk>. You should also use `pkg-config gtk+-2.0 --cflags` in CXXFLAGS and `pkg-config gtk+-2.0 --libs` in LDFLAGS. You are using at least a Makefile to build this, right?
I would personally avoid "using namespace std". It pollutes your global namespace with all the symbols from the standard library. A classic example is that if you try to name a counter with the rather reasonable "count", it'll clash with the std::count function.
C++ namespaces are stupid.
all includes should before any using statments
This is wrong, #includes can appear after using statements. They can appear at any point in the file, however in some locations it may not make sense (such as within a function), but a #include is just a preprocessor directive which says expand the contents of this file here, so it is quite legitimate to have a #include contain some code and expand it at that point. Having said that this is not anything that I would encourage.
But in summary what this means is that #includes can appear after code, such as a class or function declaration. Occasionally it is necessary to include a #include after a class declaration to avoid circular references.
it is quite legitimate to have a #include contain some code and expand it at that point
Indeed. I've used a macro-based trick to make it easy to dynamically load functions from shared objects. I've also heard of some code that uses perl to create a lookup table that's #included in the right spot. XPM files are also just C, so you can #include them right into an app.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.