I think that this should be:AM_CXXFLAGS=-DDATADIR="\"$(datadir)\"" or (the preferred) bin_CXXFLAGS=-DDATADIR="\"$(datadir)\"" That way, you don't stomp on the $CXXFLAGS environment variable set by the user.
See the automake manual for more info http://www.gnu.org/software/automake/manual/html_mono/automake.html.gz#Program%20variables ~dan
In your Makefile.am, put this in: CXXFLAGS=-DDATADIR="\"$(datadir)\"" CXXFLAGS is a variable used during compilation to pass additional command-line options to the compiler. The -D option defines a new macro (as if you had used a #define directive at the top of your source file). In this case, it's defining a macro named DATADIR and setting it equal to "$(datadir)", which would be fully expanded to something like /usr/local/share. So then your app can simply have this: