I want to include two sample programs A and B into the existing library packages.
program A depends on libfoo library, and program B depends on libbar library.
libfoo and libbar are provided as pkg-config aware.
And I want that configure will automatically detect the existence of libfoo and libbar,
and if libfoo found, program A should be built, and if libbar found, program B should be built.
Here is what I'm trying to in configure.ac:
PKG_CHECK_MODULE([FOO], [libfoo])
PKG_CHECK_MODULE([BAR], [libbar])
Here is what I'm trying to in Makefile.am:
if LIBFOO
noinst_PROGRAMS += A
A_SOURCES = ...
A_CPPFLAGS = $(FOO_CFLAGS)
A_LDADD = $(FOO_LIBS)
endif
if LIBBAR
noinst_PROGRAMS += B
B_SOURCES = ...
B_CPPFLAGS = $(BAR_CFLAGS)
B_LDADD = $(BAR_LIBS)
end
The problem is, I don't know how to define the predicates, LIBFOO and LIBBAR.
Any idea?
First, it's PKG_CHECK_MODULES:
PKG_CHECK_MODULES([FOO], [libfoo], [have_libfoo=yes], [have_libfoo=no])
PKG_CHECK_MODULES([BAR], [libbar], [have_libbar=yes], [have_libbar=no])
then it's AM_CONDITIONAL:
AM_CONDITIONAL([LIBFOO], [test "$have_libfoo" = "yes"])
AM_CONDITIONAL([LIBBAR], [test "$have_libbar" = "yes"])
BTW, since these are sample programs, building them as noinst_PROGRAMS probably isn't what you want, since they won't be installed when make install is invoked.
Related
I am playing a bit around with my Raspberry Pi and Yocto. I wrote a program. This is build with cmake and links against some parts of the boost library.
To keep the sd-card memory food print as small as possible I like to tell yocto, that it has only to link/build & deploy against some certain parts of the the boost library. My problem I do not know how to do this. Maybe someone can tell me.
Below I put the listing of my recipe:
SUMMARY = "mytest"
SECTION = "app"
LICENSE = "CLOSED"
inherit cmake
DEPENDS = "boost libconfig"
SRCREV = "${AUTOREV}"
SRC_URI = "git:///home/mytest/;protocol=file"
S = "${WORKDIR}/git"
I am only using from boost:
system thread program_options
As far as I see Yocto is building separate packages for the libs - like
libboost-thread1.66.0-1.66.0-r0.cortexa7hf_neon_vfpv4.rpm
The source of the boost recipe does not tell how to include the parts.
You can add the following instructions to your recipe:
DEPENDS = "boost libconfig"
RDEPENDS_${PN} = "boost-system boost-thread boost-program-options"
And it will ship only requested libs.
I'm trying to use LDADD to reference a prebuilt library and Automake insists that the library has to be built. The Automake manual says:
"If you need to link against libraries that are not found by configure, you can use LDADD to do so. This variable is used to specify additional objects or libraries to link with; it is inappropriate for specifying specific linker flags, you should use AM_LDFLAGS for this purpose."
In my code I have used both
LDADD = ../lib/library.a
and
prog_LDADD = ../lib/librarya.
In both cases make outputs
*** No rule to make target 'library.a', needed by 'SlipTest.exe'. Stop.
It's got me stumped.
art
check whether the file ../lib/library.a actually exists.
when building libraries with automake you should use libtool, and libtool-libraries use the (platform independent) .la extension:
prog_LDADD = ../lib/library.la
I have this directory structure
prog/libA
prog/libB
In libA, I have a Makefile.am that looks like this:
noinst_LTLIBRARIES = libA.la
libA_la_SOURCES = ...
libA_la_LIBADD = ... $(LAPACK)
where LAPACK is my system's lapack installation. This works as expected. However, in libB I have this:
noinst_LTLIBRARIES = libB.la
bin_PROGRAMS = compLibB
libB_la_SOURCES = ...
compLibB_SOURCES = ...
libB_LIBADD = $(top_builddir)/libA/libA.la ...
compLibB_LDADD = libB.la
which does not work. The linking stage of compLibB complains about undefined references to LAPACK unless I change the last line to
compLibB_LDADD = libB.la $(LAPACK)
but that seems redundant. Haven't I already linked in $(LAPACK) when I build the libA.la convenience lib? It's unclean because now compLibB has to concern itself with the details of libA. Is there no way to link in the LAPACK libs at the libA build stage so that I don't have to re-specify it at the compLibB build stage?
Haven't I already linked in $(LAPACK) when I build the libA.la convenience lib?
As your linker has already told you, no. libA.la being a convenience library is somewhat like a static library (a collection of object files).
It's unclean because now compLibB has to concern itself with the details of libA. Is there no way to link in the LAPACK libs at the libA build stage so that I don't have to re-specify it at the compLibB build stage?
You shouldn't need to specify the LAPACK libs when libA.la is built because the final link hasn't happened yet. There's no way I know of accomplishing what you want without making libA a shared library.
This is actually supposed to work, as the _LIBADD is intended to make the dependency transitive and working. On the other hand, you may have a different problem for using $(top_builddir), as libtool handles differently libraries that are linked in with relative paths and with absolute ones.
I recently downloaded the graclus software. While trying to install it I had to be complete the makefile.in with some options.I figured out other options but I couldn't find what do we write for the LDOPTIONS.
Can anybody help me out in figuring what do I fill in the options used by the compiler?
Help will be truly appreciated.
//Here is the makefile.in
# Which compiler to use
CC = g++
# What optimization level to use
OPTFLAGS = -O2 -fPIC
# What options to be used by the compiler
COPTIONS = -DNUMBITS=32
# What options to be used by the loader
LDOPTIONS =
# What archiving to use
AR = ar rv
# What to use for indexing the archive
RANLIB = ranlib
ARCH = P4SSE2
LAPACK = -llapack_$(ARCH)
ARPACK = -lcarpack_$(ARCH)
ATLAS = -latlas_$(ARCH)
CBLAS = -lcblaswr -lcblas -lblas -lmyf2c
GSL = -lgslcblas -lgsl
SPARSE = -lsparse
UTIL = -lmyutil
Since the Makefile you provided is just an excerpt and you've not mentioned what package or library you're compiling it with, I'm just making a wild-guess here.
LDOPTIONS could serve a similar puprose as the commonly used variable LDFLAGS which provides a way to specify extra flags to the linker. It depends on the linker you use. If you're using gcc, then you can run man ld to see the list of linker options.
I maintain a library with FFI bindings on Hackage. So my Haskell library depends on the corresponding C library and its header files. Now I specify the external dependency in the .cabal file like this:
PkgConfig-Depends:
libfoo >= 1.2
And it works well for me in Linux. However, I have a user of the library who reports, that installing pkg-config on Windows is rather cumbersome, and instead he prefers
Includes:
foo.h
Extra-libraries:
foo
I'd like my library to be as easy to build as possible, and don't want to force build dependencies which are not strictly required. However, I see that Cabal manual suggests to use PkgConfig-Depends.
My questions:
Which way I should prefer for cross-platform packages?
Is it possible to write a .cabal file in such a way, that it can work with pkg-config and without?
And, by the way, is pkg-config included in the Haskell platform (I don't have a Windows machine to check right now)?
The pkg-config method is preferable because pkg-config knows where to find include and library files, which may be in nonstandard locations on some systems.
You can write the .cabal file to use both methods. Using a flag, as shown here, has the advantage that Cabal will automatically try the other flag value if the default fails. (Below example is not tested)
Flag UsePkgConfig
Description: Use pkg-config to check for library dependences
Default: True
Executable hax
if flag(UsePkgConfig)
PkgConfig-Depends: libfoo >= 1.2
else
Includes: foo.h
Extra-libraries: foo
pkg-config is not included in the Haskell Platform, nor could I imagine that it ever would be.
Usually I will use includes/Extra-libraries if they're relatively simple. But for complex packages that may have a lot of included libraries, such as gtk, it's much nicer to use pkg-config when available.
It is possible to write a .cabal file that will work with and without specific fields. Try this:
if os(windows)
Includes:
foo.h
Extra-libraries:
foo
else
PkgConfig-Depends:
libfoo >= 1.2
Also note that .cabal can run a configure script, which can help in some situations but isn't very windows-friendly.