I want to add --export-dynamic flag to my project's configure.ac file.
I am trying to compile my project files that must use this flag after pkg-config --cflags --libs gtk+-3.0.
The following are contents of my configure.ac file.
AC_INIT(myapp, 1.0)
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([1.11])
AM_SILENT_RULES([yes])
AC_PROG_CXX
AC_PROG_CC
IT_PROG_INTLTOOL([0.35.0])
GETTEXT_PACKAGE=myapp
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [GETTEXT package name])
AM_GLIB_GNU_GETTEXT
LT_INIT
PKG_CHECK_MODULES(MYAPP, [gtk+-3.0 ])
AC_OUTPUT([
Makefile
src/Makefile
po/Makefile.in
])
How do I do that?
How about adding them to AM_LDFLAGS or more specific _LDFLAGS variable in Makefile.am
Related
I am new to autotools and have tried to code up an example. I am creating one library and linking it against another object.
My problem is that the Makefile that is generated for the library seems to be mis-interpreted as C code, but is actually C++. If I replace all occurences of ".c" to ".cpp" in the generated Makefile, all is well.
I am using libtool 2.4.2 and autoconf 2.69. My code structure is listed below:
test/
- Makefile.am
- configure.ac
include/
- mylib.hh
src/
hw/
- Makefile.am
- main.cpp
mylib/
- Makefile.am
- mylib.cpp
Below is my top level Makefile.am:
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src/mylib src/hw
configure.ac
AC_PREREQ([2.65])
AC_INIT([hw],[1.0.0],[foo.bar#example.com])
# directories (relative to top-level) to look into for AutoConf/AutoMake files
AC_CONFIG_MACRO_DIR([m4])
# enable AutoMake
AM_INIT_AUTOMAKE([1.10])
# all defined C macros (HAVE_*) will be saved to this file
AC_CONFIG_HEADERS([config.h])
AC_PROG_CC
AM_PROG_CC_C_O
# Check if you have a C++ compiler
AC_PROG_CXX
AC_PROG_CXX_C_O
AC_PROG_INSTALL
## Initialize GNU LibTool
LT_INIT
AC_CONFIG_FILES([Makefile
src/hw/Makefile
src/mylib/Makefile])
AC_OUTPUT
src/hw/Makefile.am
ACLOCAL_AMFLAGS = -I m4
bin_PROGRAMS = hw
hw_SOURCES = main.cpp
AM_CPPFLAGS = -I$(top_srcdir)/include
hw_LDADD = $(top_srcdir)/src/mylib/libmylib.la
src/mylib/Makefile.am
ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = libmylib.la
libmylib_la_sources = mylib.cpp
libmylib_la_CPPFLAGS = -I$(top_srcdir)/include
The error I get when running make:
make[2]: *** No rule to make target 'libmylib.c', needed by 'libmylib_la-libmylib.lo'. Stop.
Once again, substituting ".cpp" for all occurrences of ".c" in the generated src/mylib/Makefile, the code compiles, links and runs fine. Any help is appreciated.
Did you try changing:
libmylib_la_sources = mylib.cpp
to
libmylib_la_SOURCES = mylib.cpp
(upper case SOURCES)? m4 is case-sensitive.
I am familiar with very simple g++ commands that compile and link programs, however when working with GTK+ I found the tutorial indicate that I should use pkg-config --cflags gtk+-2.0
Now when I type in pkg-config --cflags gtk+-2.0 to the terminal I get a list of libraries and files like this...
-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/harfbuzz
So my question is, what does the -I mean in front of a directory? For example -I/usr/include/libpng12
The -I flag is used to add directories to the list of directories to search for finding files in #include <> statements.
In your case, when a file is included by using #include, /usr/include/libpng12 will be one of the directories in which the pre-processor will search for the file.
Please read the manual. All command line options are present there :-)
-I set the search path for libraries.
https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html
-I is simply adding to the paths to be searched for header files. Note that these are searched before system paths.
You can find pretty much all the options for gcc/g++ here. In this case, you want the Directory Search options specifically; see here. From that page:
-Idir
Add the directory dir to the head of the list of directories to be
searched for header files. This can be used to override a system
header file, substituting your own version, since these directories
are searched before the system header file directories. However, you
should not use this option to add directories that contain
vendor-supplied system header files (use -isystem for that).
If you use more than one -I option, the directories are scanned in
left-to-right order; the standard system directories come after. If a
standard system include directory, or a directory specified with
-isystem, is also specified with -I, the -I option is ignored. The directory is still searched but as a system directory at its normal
position in the system include chain. This is to ensure that GCC's
procedure to fix buggy system headers and the ordering for the
include_next directive are not inadvertently changed. If you really
need to change the search order for system directories, use the
-nostdinc and/or -isystem options.
As the answers from #R Sahu #Klaus and #Yuushi explain, the -I dir tells the compiler where to look for the #include header.h file.
When the program is compiled, it will be linked. You will probably also need to tell the linker where to find the programs that support the functions in the #included headers. This is done with the -llibrary flag. That is a lower case l not a one (1).
The pkg-config command references a set of files and will supply the compiler flags --cflags and link flags --ldflags if you supply the package name.
Put the returned -Includes before the source name(s) and the -l's after in your compile command request.
For other than casual, one-off programs, you should use make. The cflag and ldflag info can be put in variables in the Makefile and referenced throughout your make script.
You can get a complete list of packages configured to pkg-config on your Ubuntu system with locate *.pc
I am creating a program called spellcheck, and I'm using autoconf and automake to create a build system for it. The program relies on the dictionary 'english.dict', which is in the data directory (based on whatever prefix the user selected). I want the data directory path accessible by spellcheck, so I created a custom variable that contained its value:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(libspellcheck, 1.25, corinthianmonthly#hotmail.com)
AC_OUTPUT(Makefile libspellcheck/Makefile spellcheck/Makefile man/Makefile)
AC_CONFIG_SRCDIR([])
AC_CONFIG_HEADERS([config.h])
AC_DEFINE_UNQUOTED([DATA_PATH], ["$pkgdatadir"],"DData Directory Path")
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h,iostream,fstream,string,stdio.h,sstream,cctype,algorithm,boost/algorithm/string.hpp])
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_TYPE_SIZE_T
# Checks for library functions.
AC_OUTPUT
However, in the config.h file, this value is blank:
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* "Description" */
#define DATA_PATH ""
...
I tried changing $pkgdatadir to $datadir, but I got the same result. What am I doing wrong, or is what I am trying to achieve impossible?
EDIT: I redefined the variable in my Makefile.am for spellcheck:
AM_CFLAGS = -DDATA_PATH=\"$(pkgdatadir)\" -m32 -Wall
bin_PROGRAMS = spellcheck
pkgdata_DATA = english.dict
spellcheck_SOURCES = spellcheck.cpp meta.cpp
spellcheck_LDADD = ../libspellcheck/libspellcheck.a
But now it complains about DATA_PATH being nonexistant:
spellcheck.cpp:4:22: error: 'DATA_PATH' was not declared in this scope
#define DEFAULT_DICT DATA_PATH "english.dict"
Because now it seems to be ignoring all CFLAGS:
g++ -DHAVE_CONFIG_H -I. -g -O2 -MT spellcheck.o -MD -MP -MF .deps/spellcheck.Tpo -c -o spellcheck.o spellcheck.cpp
It turns out that I needed to use AM_CPPFLAGS rather than CFLAGS.
I've been trying to build to GLTools library that accompanies The OpenGL SuperBible into a libtool library with automake.
I've set up autoconf and automake but when it comes to actually build the library I get:
$ make
make: *** No rule to make target `GLBatch.lo', needed by `libgltools.la'. Stop.
I've searched google as much as my sanity will let me and come up with nothing, I'm new to automake so I'm not quite sure what to be searching for. I'm sure it's either a tiny mistake or I've missed something fundamental.
Here is my Makefile.am:
ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = libgltools.la
libgltools_la_SOURCES = GLBatch.cpp GLShaderManager.cpp GLTriangeBatch.cpp GLTools.cpp math3d.cpp glew.c
#libgltools_la_CFLAGS =
libgltools_la_LIBADD = -lX11 -lglut -lGL -lGLU -lm
include_HEADERS = GLBatchBase.h GLBatch.h GLFrame.h GLFrustum.h GLGeometryTransform.h GLMatrixStack.h GLShaderManager.h GLTools.h GLTriangleBatch.h math3d.h StopWatch.h GL/glew.h GL/glxew.h GL/wglew.h
EXTRA_DIST = autogen.sh
And my configure.ac if it matters:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([libgltools.la], [0.1], [jon.hatchett#gmail.com])
AM_INIT_AUTOMAKE([libgltools.la], [0.1])
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/])
AC_CONFIG_HEADERS([include/config.h])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lGL':
AC_CHECK_LIB([GL], [main])
# FIXME: Replace `main' with a function in `-lGLU':
AC_CHECK_LIB([GLU], [main])
# FIXME: Replace `main' with a function in `-lX11':
AC_CHECK_LIB([X11], [main])
# FIXME: Replace `main' with a function in `-lglut':
AC_CHECK_LIB([glut], [main])
# FIXME: Replace `main' with a function in `-lm':
AC_CHECK_LIB([m], [main])
# Checks for header files.
AC_PATH_X
AC_CHECK_HEADERS([inttypes.h stddef.h stdint.h stdlib.h string.h sys/time.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_UINT64_T
AC_CHECK_TYPES([ptrdiff_t])
# Checks for library functions.
AC_HEADER_MAJOR
AC_FUNC_MALLOC
AC_CHECK_FUNCS([gettimeofday sqrt strchr strstr])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
Thanks very much.
It's hard to say based on your description but I would wager that you need to put your Makefile.am in the src directory and then create a Makefile.am in the GLTools directory that looks like this:
SUBDIRS = src
ACLOCAL_AMFLAGS = -I m4
It is also possible to do a non-recursive make but that requires some extra setup.
Here I did it for you:
https://github.com/msteinert/gltools
You should add somewhere in your configure.ac file:
LT_INIT
LT_LANG([C++])
Or alternatively, according to the docs:
LT_INIT
AC_PROG_CXX
i want to add a dynamic configuration path (generated from pkg-config) to my project. (this is basically for third-party dependencies like boost, so workspace includes is not appropiate, and filesystem include neither because that would be hardcoded and every developer would have to change that manually)
i am on project properties->c++ general->paths and symbols->includes tab->add...->add directory path->variables but i can only select among existing variables, how do i create a new variable dynamically generated from a command line program? like pkg-config --cflags boost-1.43?
this is easy to do in netbeans; you just add the pkg-config commandline with the backquotes in the build additional options and it resolves the build include and even in theory it should update the indexer (although truth be said, last time the indexer was correctly updating from pkg-config was on netbeans 6.8, it has been broken on 6.9 and 6.9.1)
i read this StackOverflow post but i still not sure how it helps this specific case
i read somewhere that you can use $(shell pkg-config...) to generate environment variables but not sure where to place the command
if there is no easy out of the box solution i'll try the script in this blog post
btw, i'm using eclipse helios -cdt 7
thanks!
Pkg-config support is finally coming to CDT and will be finished on August.
http://code.google.com/p/pkg-config-support-for-eclipse-cdt/
you can use $(shell pkg-config --cflags your_libs) in:
Project properties->C/C++ Build->Settings->"Tools Settings" tab->**C Compiler**->Miscellaneous->Other Flags
and
you can use
$(shell pkg-config **--libs** your_libs)
in
Project properties->C/C++ Build->Settings->"Tools Settings" tab->**C Linker**->Miscellaneous->Other Flags
if the linker doesn't link, make sure (for example in the build console window) that the pkg-config flags appear after the objects to link.
you can do this in properties->C/C++ Build->Settings->"Tools Settings" tab->C Linker->Command line pattern moving ${FLAGS} to the end :
from this (for example) :
${COMMAND} **${FLAGS}** ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} **${INPUTS}**
to this :
${COMMAND} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} **${INPUTS} ${FLAGS}**
In eclipse 4.3.2 at least, it looks as though it's possible to simply add
`pkg-config --libs <mylibname>`
in
Project->Properties->C/C++ Build->Settings->GCC {C|C++} Linker->Miscellaneous->Linker Flags
similarly
`pkg-config --cflags <mylibname>`
in
Project->Properties->C/C++ Build->Settings->GCC {C|C++} Compiler->Miscellaneous->Other Flags
what i found so far is that you can do
project-> properties-> c++ build-> build variables
add a new variable of string type.
Call it whatever you like:
UNITTEST_CPP_CXXFLAGS
then set as its value:
$(shell pkg-config --cflags unittest-cpp)
the go to project properties-> c++ general -> path and symbols,
includes.
Select languages c++, otherwise it defaults to assembly source file.
Click add.
On the add directory path, click variables... (because we want to add the variable we have just created)
type the name of the variable (UNITTEST_CPP_CXXFLAGS), press enter and ok
when you rebuild the result of the shell command is replaced in a -I option (for the gnu gcc toolchain at least), in general pkg-config output might include one or more -I so this won't work. Lets go to c++ build->settings->tool settings->gcc c++ compiler->miscellaneous. In there, add ${UNITTEST_CPP_CXXFLAGS} to the other flags.
now the include will be added, but there is no hope of getting the indexer to browse those include!
Use this link at eclipse help/install new spftware. It installs pkg-config. https://raw.githubusercontent.com/TuononenP/pkg-config.p2/master/site.xml
I did find this link in this webpage. https://groups.google.com/forum/#!topic/pkg-config-support-for-eclipse-cdt/HNblZRTKBQQ