我正在尝试为我的一个Vala项目设置一个autotools构建系统,这是我到目前为止所提出的。
configure.ac
AC_INIT(White House, 1.0)
AC_CONFIG_SRCDIR(src/Window.vala)
AM_INIT_AUTOMAKE
AC_PROG_CC
AC_PROG_CC_STDC
AM_PROG_VALAC([0.7.0])
AC_PROG_INSTALL
WHITE_HOUSE_PACKAGES="--pkg gio-2.0 --pkg gtk+-3.0 --pkg gee-0.8 --target-glib 2.32 --pkg json-glib-1.0"
PKG_CHECK_MODULES(WHITE_HOUSE, [gio-2.0 gtk+-3.0 gee-0.8 json-glib-1.0])
AC_SUBST(WHITE_HOUSE_CFLAGS)
AC_SUBST(WHITE_HOUSE_LIBS)
AC_SUBST(WHITE_HOUSE_PACKAGES)
AC_CONFIG_FILES([
Makefile
resources/white-house.desktop
resources/Makefile
src/Makefile
])
AC_OUTPUT
Makefile.am
SUBDIRS = resources src
EXTRA_DIST = autogen.sh
的src / Makefile.am
AM_CPPFLAGS = $(WHITE_HOUSE_CFLAGS)
bin_PROGRAMS = white-house
white_house_SOURCES = AutomapDialog.vala Drawable.vala Map.vala Preferences.vala Room.vala TextView.vala AutoMapper.vala Handle.vala Passage.vala RoomDialog.vala Tab.vala Window.vala
white_house_VALAFLAGS = $(WHITE_HOUSE_PACKAGES)
white_house_CFLAGS = $(WHITE_HOUSE_CFLAGS)
white_house_LDFLAGS = $(WHITE_HOUSE_LIBS)
资源/ Makefile.am
desktopdir = $(datadir)/applications
desktop_DATA = white-house.desktop
icondir = $(datadir)/icons
icon_DATA = white-house.svg
当我运行 make 时,我会以src/File.c:####: undefined reference to some_function ()
的形式出现很多错误。这让我觉得它没有正确传递CFLAGS。我做错了什么?
编辑:经过进一步研究后,我发现如果在 libs之后将源文件传递给gcc ,则会发生'未定义的引用'错误。这是命令make is using。
gcc -std=gnu99 -pthread -I/usr/local/include/gee-0.8 -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircommon -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/json-glib-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -L/usr/local/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgee-0.8 -ljson-glib-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -o white-house white_house-Window.o
正如您所看到的那样,源文件是最后一件事。如果我在-l
参数之前移动它们就可以编译好。所以问题是:为什么Makefile把它们放错了?
答案 0 :(得分:2)
看起来我应该使用LDADD
代替LDFLAGS
。我的新 Makefile.am 如下。
bin_PROGRAMS = white-house
white_house_SOURCES = AutomapDialog.vala Drawable.vala Map.vala Preferences.vala Room.vala TextView.vala AutoMapper.vala Handle.vala Passage.vala RoomDialog.vala Tab.vala Window.vala
white_house_VALAFLAGS = $(WHITE_HOUSE_PACKAGES) --target-glib 2.32
white_house_CFLAGS = $(WHITE_HOUSE_CFLAGS)
white_house_LDADD = $(WHITE_HOUSE_LIBS) -lm
答案 1 :(得分:1)
您通常要设置white_house_CPPFLAGS
,而不是white_house_CFLAGS
。 CPPFLAGS
传递给编译器和一些预处理步骤。此外,您应该能够在执行命令之前查看命令。如果没有,请尝试make V=1
。