Configured eclipse for gtkmm and gtk+ on ubuntu

送分小仙女□ 提交于 2020-07-10 09:57:32

问题


I am trying to configure latest Eclipse for C++ (Oxygen) to work with gtkmm. How can I remove errors from Eclipse such as unresolved symbols and gtkmm header files.

I am able to compile from command line using g++ and pkg-config flags. How can I do same thing from the Eclipse IDE?

I am using latest IDE 2019 version.


回答1:


I have been using gtkmm and Eclipse for a while now. Here is how I set it up to get both working properly together. To illustrate this, I will take the basic example from the Gtkmm manual. In this example, you have a project containing two files:

simple.cc: This is a simple source code file.

#include <gtkmm.h>

int main(int argc, char *argv[])
{
  auto app =
    Gtk::Application::create(argc, argv,
      "org.gtkmm.examples.base");

  Gtk::Window window;
  window.set_default_size(200, 200);

  return app->run(window);
}

Makefile: This helps you build the project. Note that the spacing before g++ is a tab character, not spaces.

all:
    g++ simple.cc -o simple `pkg-config gtkmm-3.0 --cflags --libs`

Both files are located under the same directory. From what I understand, you are able to build from the command line. So running make as such:

make

should build the project fine. Now, to work on this project from Eclipse, we will first create a Makefile project: File -> New -> Makefile Project from Existing Code. Fill in the information (make sure to select the directory under which the above files are located). At this point, you should have an Eclipse project containing your two files, but with errors everywhere in simple.cc:

The problem is that Eclipse does not know about gtkmm and its includes. We have to locate them for him. To do so, open up a terminal an type this:

echo `pkg-config gtkmm-3.0 --cflags --libs`

The output will look like the following:

-pthread -I/usr/include/gtkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include ...

In this mess, you have many substrings that look like -I/some/path, like -I/usr/include/gtkmm-3.0 or -I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include. These are include file locations. This is what Eclipse needs! What we need to do is to take all those locations and feed them to Eclipse. To do this, go to Project -> Properties -> C/C++ General -> Paths and Symbols. In the languages list, select GNU C++. In the Include directories section, add all those paths (yes, it is very painful. You can add them manually from the cproject file, which can save some time, but I am not doing this here as it is more error prone). You should get something like:

When you are done, click Apply and Close. The errors may not go away, you may have to re-index the project. To do so, right click on it , go to Index -> Rebuild. The errors should then go away (It may take some time).

At this point, you have no more errors in your editor and you can build from within Eclipse: Project -> Build Project.

Hope you can get it working!



来源:https://stackoverflow.com/questions/58910311/configured-eclipse-for-gtkmm-and-gtk-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!