[英]Compile gtk library in combination with other libraries using a Makefile
I'm having troubles compiling the gtk library with my c++ program.我在用我的 C++ 程序编译 gtk 库时遇到了麻烦。 I have gtk installed and my program is working when using terminal command like:
我已经安装了 gtk 并且我的程序在使用终端命令时正在运行,例如:
gcc -Wall -g helloworld.c -o helloworld `gtk-config --cflags` \
`gtk-config --libs`
But i need it to compile with some other libraries to, so i have a Makefile, but don't know how to make it also compile the gtk libraries.但是我需要它与其他一些库一起编译,所以我有一个 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
I tried adding the gtk line on different locations inside the Makefile我尝试在 Makefile 内的不同位置添加 gtk 行
gtk-config --cflags gtk-config --libs
But where ever i try to place it, it just says it can't find the gtk header file...但是无论我在哪里尝试放置它,它只是说它找不到 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
So whats the solution for compiling the gtk library, using this makefile?那么使用这个makefile编译gtk库的解决方案是什么?
Just add gtk-config --cflags
to your CFLAGS
.只需将
gtk-config --cflags
添加到您的CFLAGS
。 Then add gtk-config --libs
to your libraries, right next to those -lswe -lm -ldl
然后将
gtk-config --libs
添加到您的库中,就在那些-lswe -lm -ldl
旁边
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.