makefile 和 gtkmm 的问题
我目前正在尝试使用 gtkmm 编写一个简单的程序,但是当我尝试编译它时遇到了问题。我有一些简单的文件: main.cc 只包含主函数, test.cc 和 test.h 定义了一个基于类的 Gtk::Window ,其中有一对按钮,最后是一个简单的 makefile。
当我尝试编译 makefile 时出现问题,它返回:
In file included from main.cc:2:
test.h:12: fatal error: gtkmm.h: No such file or directory
如果我随后将 #include
替换为 #include
In file included from test.h:12,
from main.cc:2:
/usr/include/gtkmm-2.4/gtkmm.h:87: fatal error: glibmm.h: No such file or directory
我一直在寻找解决方案一段时间,并在网上寻找它,但对于有类似问题的其他用户来说,这是由于不包括 `pkg-config --cflags -- 引起的库gtkmm-2.4` 在他们的 makefile 中。不幸的是,这不是我的问题的根源,因为我一直都有这个问题。
最奇怪的部分是当我不使用 makefile 时它可以工作。如果我从 main.cc 中取出 main 函数并将其放入 test.cc 文件中,然后
g++ test.cc -o output `pkg-config --cflags --libs gtkmm-2.4`
在控制台中输入: ,它就可以正常工作。这只是一个临时解决方案,因为我已经到了需要上不止一堂课的地步。我不知道这是否是安装 make 或 gtkmm 的问题,并尝试重新安装两者,但无济于事。我不知道还能尝试什么。
最后,如果它有帮助的话,我正在运行 Ubuntu 10.10,g++ 版本 4.4.5
谢谢您的帮助
makefile 如下:
main: main.o
@echo "Main"
@g++ -g main.cc test.o -o output `pkg-config --cflags --libs gtkmm-2.4`
test.o:
@echo "Test"
@g++ test.cc -o test.o `pkg-config --cflags --libs gtkmm-2.4`
clean:
@clear
@rm -f *.o
I am currently trying to write a simple program with gtkmm, but I am running into issues when I try to compile it. I have a few simple files: main.cc which only contains the main function, test.cc and test.h which define a class based Gtk::Window with a pair of buttons in it, and finally a simple makefile.
The problem arises when I try to compile the makefile, it returns:
In file included from main.cc:2:
test.h:12: fatal error: gtkmm.h: No such file or directory
If I then replace #include <gtkmm.h>
with #include <gtkmm-2.4/gtkmm.h>
it returns the error:
In file included from test.h:12,
from main.cc:2:
/usr/include/gtkmm-2.4/gtkmm.h:87: fatal error: glibmm.h: No such file or directory
I been searching for a solution for a while and have looked around online for it, but for other users who had a similar problem, it was caused by not including `pkg-config --cflags --libs gtkmm-2.4` in their makefile. Unfortunately this was not the source of my problem, as I have had it in mine all along.
The strangest part is that it works when I don't use a makefile. If I take the main function from my main.cc and put it into my test.cc file, then type:
g++ test.cc -o output `pkg-config --cflags --libs gtkmm-2.4`
into the console, it works fine. This is only a temporary fix, as I am coming to the point where I need to have more than one class. I don't know if this is is some problem with the installation of make or gtkmm, and have tried re-installing both, to no avail. I don't know what else to try.
Finally if it helps I am running Ubuntu 10.10, with g++ version 4.4.5
Thank you for any help
The makefile is as follows:
main: main.o
@echo "Main"
@g++ -g main.cc test.o -o output `pkg-config --cflags --libs gtkmm-2.4`
test.o:
@echo "Test"
@g++ test.cc -o test.o `pkg-config --cflags --libs gtkmm-2.4`
clean:
@clear
@rm -f *.o
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,我通过将 pkg-config gtkmm-3.0 --cflags --libs 添加到构建的两个步骤(编译和链接)来解决它。我的 makefile:
请注意,用于 pkg-config 的引号类型很重要,如果您使用 ' 而不是 ´,则它不起作用。
PS:我是 makefile 的新手,所以我不太确定我做了什么。
I had the same problem and I have solved it by adding
pkg-config gtkmm-3.0 --cflags --libs
to both steps of build (compilation and linking). My makefile:Note that the type of quotation marks used for pkg-config is important, if you use ' instead of ´ it doesn't work.
P.S.: I'm a newbie on makefiles so I am not perfectly sure about what I did.
此错误:
建议您必须将 glibmm-2.4 添加到 pkg-config 搜索中:
This error:
suggests that you must add glibmm-2.4 to pkg-config search: