如何在Makefile.am中包含mysql.h和my_global.h? [英] How do I include mysql.h and my_global.h into the Makefile.am?
问题描述
我正在尝试创建一个可以通过以下两个头文件与MySQL数据库通信的C程序:
I'm trying to create a C program that can communicate with MySQL database via these two header files:
mysql.h
my_global.h
MySQL带有mysql_config脚本,您可以执行该脚本来查找包含文件和库文件在系统中的位置.我想知道如何在Makefile.am中定义它?
MySQL comes with mysql_config script that you can execute to find out where the include files and library files reside in the system. I was wondering how would you define it in the Makefile.am?
我目前有以下内容:
bin_PROGRAMS = db
db_SOURCES = db.c db.h
db_CFLAGS = -Wall `mysql_config --cflags --libs`
这是正确的方法吗?
推荐答案
我会使用mysql_config
/ax_with_prog.html"rel =" nofollow> AX_WITH_PROG 宏:
I would search for mysql_config
in configure.ac
using the AX_WITH_PROG macro:
AX_WITH_PROG([MYSQL_CONFIG], [mysql_config], [AC_MSG_ERROR(mysql_config is required to build)])
,因此,如果将MYSQL_CONFIG
环境变量安装在程序中的意外位置,则用户可以将其指向该程序.而且,如果用户尚未安装,则他们会收到一条不错的错误消息,警告他们在尝试构建之前 .
so your users will be able to point the MYSQL_CONFIG
environment variable at the program should it be installed in an unexpected location. And if the users haven't installed it, they will get a nice error message which alerts them to that fact before attempting to build.
我可能还会在configure.ac
中设置cflags,cppflags和lib,因为在运行configure
之后它们不应更改:
I'd probably set up the cflags, cppflags, and libs in configure.ac
as well, since they shouldn't change after configure
is run:
MYSQL_CONFIG_CFLAGS=`$MYSQL_CONFIG --cflags`
MYSQL_CONFIG_CPPFLAGS=`$MYSQL_CONFIG --include`
MYSQL_CONFIG_LIBS=`$MYSQL_CONFIG --libs`
AC_SUBST([MYSQL_CONFIG_CFLAGS])
AC_SUBST([MYSQL_CONFIG_CPPFLAGS])
AC_SUBST([MYSQL_CONFIG_LIBS])
并将它们放置在Makefile.am
db_CFLAGS = -Wall $(MYSQL_CONFIG_CFLAGS)
db_CPPFLAGS=$(MYSQL_CONFIG_CPPFLAGS)
db_LDADD=$(MYSQL_CONFIG_LIBS)
如果仅需要头文件,则可能不需要设置cflags变量.
If all you need is the header files, you probably won't need to set up the cflags variable.
这篇关于如何在Makefile.am中包含mysql.h和my_global.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!