On Wed, May 22, 2013 at 04:46:36PM -0700, Jordan H. wrote: | I'm using mysql in a program. Here is a snipped of my Makefile.am: | | project_LDADD += -lboost_thread | project_LDADD += -lboost_regex | project_LDADD += -lboost_system | | AM_LDFLAGS = -L/usr/local/lib | AM_LDFLAGS += `mysql_config --libs_r` | AM_LDFLAGS += `mysql_config --include` | AM_LDFLAGS += -std=c++0x | AM_LDFLAGS += `mysql_config --cflags` | | When I compile the program, automake generated: | | g++ -g -O2 -L/usr/local/lib `mysql_config --libs_r` `mysql_config | --include` -std=c++0x | `mysql_config --cflags` -o /[ ... a bunch of .o files ... ]/ | -lboost_thread -lboost_regex | -lboost_system | | As expected, since g++ needs linker flags at the end I get a bunch of | compile errors saying the `mysql_*` functions don't exist. How do I | specify for the linker flags to go at the end? I tried to put them in | the project_LDADD macro but automake complained: | | Makefile.am:13: linker flags such as `--libs_r`' belong in | `project_LDFLAGS | | Which got me back to square one. I must be doing something wrong. Any | ideas? This has been bugging me for days. Thanks in advance.
Hi Jordan, I define some automake substition variables in configure.ac as part of the checks for MySQL: # Look for mysql via the presence of 'mysql_config' or 'mysql_config5' # AC_PATH_PROGS([TOOL_MYSQL_CONFIG], [mysql_config mysql_config5], [], [$PATH:/opt/local/bin]) AS_IF([test -n "$TOOL_MYSQL_CONFIG"], [MYSQL_CFLAGS=`$TOOL_MYSQL_CONFIG --cflags` MYSQL_LIBS=`$TOOL_MYSQL_CONFIG --libs_r` MYSQL_VERSION=`$TOOL_MYSQL_CONFIG --version`], [AC_MSG_ERROR([missing program 'mysql_config'; is 'mysql' or 'MySQL-devel' installed?])]) WANT_MYSQL_VERSION=5.1.55 AC_MSG_CHECKING([for mysql >= $WANT_MYSQL_VERSION]) AS_VERSION_COMPARE([$MYSQL_VERSION], [$WANT_MYSQL_VERSION], [AC_MSG_RESULT([no]) AC_MSG_FAILURE([mysql $MYSQL_VERSION is too old, need $WANT_MYSQL_VERSION])]) AC_MSG_RESULT([yes]) AC_SUBST([MYSQL_CFLAGS]) AC_SUBST([MYSQL_LIBS]) AC_PATH_PROGS([TOOL_MYSQL], [mysql mysql5], [], [$PATH:/opt/local/bin]) AS_IF([test -n "$TOOL_MYSQL"], [:], [AC_MSG_ERROR([missing program 'mysql'; is 'mysql' or 'MySQL-client-community' installed?])]) I then use these in the Makefile.am as: prog_CPPFLAGS += $(MYSQL_CFLAGS) prog_LDADD += $(MYSQL_LIBS) (As an aside, you probably don't want includes and cflags in LDFLAGS) I don't bother with `mysql_config --include` Feel free to reuse those snippets as you like. I hope that's useful. Regards, Luke.
pgpNPITqk3tSe.pgp
Description: PGP signature