使用 Makefile 与其他库组合编译 gtk 库
Compile gtk library in combination with other libraries using a Makefile
我在用c ++程序编译gtk库时遇到麻烦。我安装了 gtk,并且在使用终端命令时我的程序可以工作,例如:
gcc -Wall -g helloworld.c -o helloworld `gtk-config --cflags`
`gtk-config --libs`
但是我需要它与其他一些库一起编译,所以我有一个 Makefile,但不知道如何让它也编译 gtk 库。
CFLAGS = -g -Wall -fPIC -Wextra -Werror -lpthread -pthread # for Linux and other gcc systems
OP=$(CFLAGS)
CC=g++ #for Linux
# compilation rule for general cases
.o :
$(CC) $(OP) -o $@ $? -lm
.c.o:
$(CC) -c $(OP) $<
SWEOBJ = swedate.o swehouse.o swejpl.o swemmoon.o swemplan.o swepcalc.o sweph.o
swepdate.o swephlib.o swecl.o swehel.o
astrogtk: astrogtk.o libswe.a
$(CC) $(OP) -I/home/arjan/astroproject -o astrogtk astrogtk.o -L. -lswe -lm -ldl
swemini: swemini.o libswe.a
$(CC) $(OP) -o swemini swemini.o -L. -lswe -lm
# create an archive and a dynamic link libary fro SwissEph
# a user of this library will inlcude swephexp.h and link with -lswe
libswe.a: $(SWEOBJ)
ar r libswe.a $(SWEOBJ)
libswe.so: $(SWEOBJ)
$(CC) -shared -o libswe.so $(SWEOBJ)
clean:
rm -f *.o astrogtk libswe*
###
swecl.o: swejpl.h sweodef.h swephexp.h swedll.h sweph.h swephlib.h
sweclips.o: sweodef.h swephexp.h swedll.h
swedate.o: swephexp.h sweodef.h swedll.h
swehel.o: swephexp.h sweodef.h swedll.h
swehouse.o: swephexp.h sweodef.h swedll.h swephlib.h swehouse.h
swejpl.o: swephexp.h sweodef.h swedll.h sweph.h swejpl.h
swemini.o: swephexp.h sweodef.h swedll.h
swemmoon.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h
swemplan.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h swemptab.h
swepcalc.o: swepcalc.h swephexp.h sweodef.h swedll.h
sweph.o: swejpl.h sweodef.h swephexp.h swedll.h sweph.h swephlib.h
swephlib.o: swephexp.h sweodef.h swedll.h sweph.h swephlib.h
astrogtk.o: swephexp.h sweodef.h swedll.h astromath.h
我尝试在生成文件内的不同位置添加 gtk 行
gtk-config --cflags gtk-config --libs
但是无论我尝试放置它在哪里,它只是说它找不到 gtk 头文件......
astrogtk.cpp:1:21: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
<builtin>: recipe for target 'astrogtk.o' failed
make: *** [astrogtk.o] Error 1
那么使用此生成文件编译 gtk 库的解决方案是什么?
只需将gtk-config --cflags
添加到您的CFLAGS
中即可。然后将gtk-config --libs
添加到您的库中,就在这些-lswe -lm -ldl
旁边
经过修补,我在这里的这个网站上找到了这个命令,它解决了我在 Arch 上使用 c++ 的编译问题:
$ gcc -o simple simple.c `pkg-config --libs --cflags gtk+-3.0`
可能需要使命令适应您的 GTK 版本。
使用 VS 代码作为 IDE 对导入库有很大帮助。
相关文章:
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 如何在运行中期切换GTK CSS style_context
- 可组合的lambda/std::函数与std::可选
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 混合组合和继承的C++问题
- 我需要将多个函数组合为一个函数
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 通过组合不同的类型来创建唯一的id
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 如何在GTK程序运行时禁用屏幕保护程序/电源管理/屏幕消隐
- 模板元编程:如何将参数包组合成新的参数包
- 检查向量是否具有所有可能的字符组合
- 如何在加密++中将两个源组合成新的源
- 根中的组合
- 如何使用 GTK 3 正确设置默认文本
- 更改 C++ 中的组合分类变量
- 是否可以使用 Gtk::D rawingArea (GTKmm) 作为组合而不是继承?
- 使用 Makefile 与其他库组合编译 gtk 库
- GTK+2.0组合框-如何获得条目的位置
- 在 GTK 中组合的指针