makefile mysql,如何在Makefile.am中包含mysql.h和my_global.h?

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 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?

I currently have the following:

bin_PROGRAMS = db

db_SOURCES = db.c db.h

db_CFLAGS = -Wall `mysql_config --cflags --libs`

Is this the correct way?

解决方案

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)])

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.

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])

and put them in place in Makefile.am

db_CFLAGS = -Wall $(MYSQL_CONFIG_CFLAGS)

db_CPPFLAGS=$(MYSQL_CONFIG_CPPFLAGS)

db_LDADD=$(MYSQL_CONFIG_LIBS)

If all you need is the header files, you probably won't need to set up the cflags variable.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值