[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Specifying Flag Order?

From: Luke Mewburn
Subject: Re: Specifying Flag Order?
Date: Thu, 23 May 2013 15:03:04 +1000
User-agent: Mutt/1.5.20 (2009-12-10)

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
  |     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:
  | 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 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], [],
        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?])])


        AC_MSG_CHECKING([for mysql >= $WANT_MYSQL_VERSION])
              AC_MSG_FAILURE([mysql $MYSQL_VERSION is too old, need 

        AC_PATH_PROGS([TOOL_MYSQL], [mysql mysql5], [],
        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 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.


Attachment: pgpmHZ4H5syac.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]