在Ubuntu上为gtkmm和gtk +配置的Eclipse [英] Configured eclipse for gtkmm and gtk+ on ubuntu

查看:324
本文介绍了在Ubuntu上为gtkmm和gtk +配置的Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将最新的Eclipse for C ++(Oxygen)配置为可与gtkmm一起使用.如何从Eclipse中清除未解决的符号和gtkmm标头文件之类的错误.

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.

我能够使用g ++和pkg-config标志从命令行进行编译.如何在Eclipse IDE中执行相同的操作?

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

我正在使用最新的IDE 2019版本.

I am using latest IDE 2019 version.

推荐答案

我已经使用gtkmm和Eclipse已有一段时间了.这是我设置它的方法,以使两者都能正常工作.为了说明这一点,我将从

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:这是一个简单的源代码文件.

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:这可以帮助您构建项目.请注意,g++之前的空格是制表符,而不是空格.

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`

两个文件都位于同一目录下.据我了解,您可以从命令行进行构建.因此,这样运行make:

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

应该可以很好地构建项目.现在,要在Eclipse上处理该项目,我们首先将创建一个 Makefile项目:File -> New -> Makefile Project from Existing Code.填写信息(确保选择以上文件所在的目录).此时,您应该有一个包含两个文件的Eclipse项目,但是simple.cc:

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:

问题是Eclipse不了解gtkmm及其包含的内容.我们必须为他找到他们.为此,打开一个终端,输入以下内容:

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`

输出将如下所示:

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

在这种混乱中,您有许多看起来像-I/some/path的子字符串,例如-I/usr/include/gtkmm-3.0-I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include.这些是包含文件的位置.这就是Eclipse所需要的!我们需要做的是获取所有这些位置并将它们提供给Eclipse.为此,请转到Project -> Properties -> C/C++ General -> Paths and Symbols.在语言列表中,选择GNU C++.在Include directories部分中,添加所有这些路径(是的,这很痛苦.您可以从cproject文件中手动添加它们,这可以节省一些时间,但是我在这里不这样做,因为它更容易出错).您应该得到类似的东西:

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:

完成后,单击Apply and Close.错误可能不会消失,您可能必须重新索引项目.为此,右键单击它,转到Index -> Rebuild.错误应消失(可能需要一些时间).

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).

这时,您的编辑器中没有更多错误,可以在Eclipse中进行构建:Project -> Build Project.

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!

这篇关于在Ubuntu上为gtkmm和gtk +配置的Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆