Find libffi header files with CMake - linux

I require libffi to build my C++ project. The problem is that there exists no premade script to find libffi and ffi.h is located at strange locations depending on the version of the library and the Linux distribution.
The is my attempt:
# Look for the header file.
Find_Path(LIBFFI_INCLUDE_DIR NAMES ffi.h)
Mark_As_Advanced(LIBFFI_INCLUDE_DIR)
# Look for the library.
Find_Library(LIBFFI_LIBRARY NAMES
ffi
)
Mark_As_Advanced(LIBFFI_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set LIBFFI_FOUND to TRUE
# if all listed variables are TRUE
Include(FindPackageHandleStandardArgs)
Find_Package_Handle_Standard_Args(libffi DEFAULT_MSG
LIBFFI_LIBRARY LIBFFI_INCLUDE_DIR)
If(LIBFFI_FOUND)
SET(LIBFFI_LIBRARIES ${LIBFFI_LIBRARY})
SET(LIBFFI_INCLUDE_DIRS ${LIBFFI_INCLUDE_DIR})
Endif(LIBFFI_FOUND)
But it obviously doesn't work because Find_Path() doesn't search recursivly.
How to do it better?
I tried to use CMake's pkg-config module, but pkg-config can't find it either.
[ethon#Fleckstation Paper]$ pkg-config --cflags libffi Package libffi
was not found in the pkg-config search path. Perhaps you should add
the directory containing `libffi.pc' to the PKG_CONFIG_PATH
environment variable No package 'libffi' found
Thanks!

I am the author of libffi. pkg-config should find it. What system are you working on? Do you have a libffi.pc file anywhere on your system?

Take a look at how it's implemented in LLVM project. Search for if( LLVM_ENABLE_FFI ) line.

Related

autoconf: `PKG_CONFIG_PATH` not working in `configure.ac` when using `PKG_CHECK_EXISTS`

I want to check whether gmodule exists in my custom PKG_CONFIG_PATH
// configure.ac
AC_SUBST([PKG_CONFIG_PATH],"./glib/lib/x86_64-linux-gnu/pkgconfig/")
PKG_PROG_PKG_CONFIG
PKG_CHECK_EXISTS([gmodule-2.0],[],[
AC_MSG_ERROR(can't find gmodule in glib-2.0)
])
But I have the following error:
checking for libunwind.h... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
configure: error: can't find gmodule in glib-2.0
I'm 100 percent sure that gmodule-2.0.pc is in my custom path:
> ls ./glib/lib/x86_64-linux-gnu/pkgconfig/
gio-2.0.pc gio-unix-2.0.pc glib-2.0.pc gmodule-2.0.pc gmodule-export-2.0.pc gmodule-no-export-2.0.pc gobject-2.0.pc gthread-2.0.pc
And I can also use pkg-config to find gmodule-2.0:
> PKG_CONFIG_PATH="./glib/lib/x86_64-linux-gnu/pkgconfig/" pkg-config gmodule-2.0 --cflags
-pthread -I/home/xxx/fuzz/test/StochFuzz/glib/include -I/home/xxx/fuzz/test/StochFuzz/glib/include/glib-2.0 -I/home/xxx/fuzz/test/StochFuzz/glib/lib/x86_64-linux-gnu/glib-2.0/include
Do I miss something?
Do I miss something?
It looks like you are expecting this ...
AC_SUBST([PKG_CONFIG_PATH],"./glib/lib/x86_64-linux-gnu/pkgconfig/")
... to cause configure to use ./glib/lib/x86_64-linux-gnu/pkgconfig/ as the PKG_CONFIG_PATH when it runs pkg-config. In that case, you are at least missing that
the purpose of AC_SUBST() is to create an output variable. You want an output variable if you want to convey the pkg-config path to your Makefiles, but that is not directly relevant to your configure script.
although AC_SUBST does set the value of the specified shell variable if you designate a value for it,
It does not necessarily export that variable.
The assignment does not necessarily appear in the configure script at a place corresponding to the macro's location in configure.ac.
if you are trying to use components that are bundled with your project (and surely that's what you are doing if the wanted details are provided by pkg-config data from within your own source tree) then pkg-config is way overkill. Just put the needed paths and flags in your Makefile.am file(s), or if you're not using Automake then directly in your Makefile.in file(s).
If you insist on doing it with pkg-config anyway, then this variation will likely induce the behavior you want from the PKG_CHECK_EXISTS macro:
# configure.ac
PKG_CONFIG_PATH=./glib/lib/x86_64-linux-gnu/pkgconfig/
export PKG_CONFIG_PATH
PKG_PROG_PKG_CONFIG
PKG_CHECK_EXISTS([gmodule-2.0],[],[
AC_MSG_ERROR(can't find gmodule in glib-2.0)
])
If you also need to convey your custom PKG_CONFIG_PATH to your makefiles then you can add ...
AC_SUBST([PKG_CONFIG_PATH])
... but you shouldn't. Notwithstanding the fact that you shouldn't be using pkg-config at all in this case (see above), when you do use pkg-config in an Autotools build system, the best way to use it is entirely within configure. Extract the needed paths and flags there, and convey those to your makefiles via output variables.

Cabal don't find relative library for compilation of gsasl package

I'm using Haskell on webfaction server, with non root access, on a CentOS 6 system.
I have a /lib/ folder which contain libraries.
Actually, i have a problem with some libraries needed for an installation of package using cabal install.
I need the libgsasl library installed, so i download and compile the gsasl package from sources :
I wget the latest tar.gz here
I run ./configure --prefix=$HOME to install compiled libraries into $HOME/lib
i make and make install
Next, i try two way with cabal install gsasl command, which actually fails :
export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH
cabal install gsasl --bindir=$HOME/bin --extra-include-dirs=/home/reyman64/lib/ --extra-lib-dirs=/home/reyman64/lib
Any of the command found the good libraries ...
The pkg-config package 'libgsasl' version superior to 1.1 is required but it could not be found.
So i verify, my version is 1.8, and i have the libgsasl.sa .la .so .so.7 .so.7.9.6 in $HOME/lib and i have a libgsasl.pc into $home/lib/pkgconfig
Any idea of the problem ?
Make sure your PKG_CONFIG_PATH environment variable is set to include $HOME/lib/pkgconfig, i.e. the directory where you've placed libgsasl.pc.

Where are package library and header files installed?

After downloading and installing a package in Ubuntu, how can I check where the library and header files were written to? I believe that this has something to do with the package's .pc file, but I do not know how to find that file either.
For example, I have downloaded the PCL (Point Cloud Library) package, and then in a sample CMakeLists.txt file, I have been given the following:
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
Where are these environment variables defined, and how can I see them?
If I compiled the libraries from source rather than through a package, will this be any different? Will a .pc file be created automatically?
If you install the package containing the libpcl development files
sudo apt-get install libpcl-dev
You can list the installed files
dpkg -L libpcl-dev
an see the location of all headers.
...
/usr/include/pcl-1.7/pcl/filters/fast_bilateral.h
/usr/include/pcl-1.7/pcl/filters/voxel_grid_covariance.h
/usr/include/pcl-1.7/pcl/filters/voxel_grid_occlusion_estimation.h
/usr/include/pcl-1.7/pcl/filters/median_filter.h
/usr/include/pcl-1.7/pcl/filters/crop_box.h
/usr/include/pcl-1.7/pcl/filters/voxel_grid_label.h
/usr/include/pcl-1.7/pcl/filters/covariance_sampling.h
/usr/include/pcl-1.7/pcl/filters/random_sample.h
/usr/include/pcl-1.7/pcl/filters/normal_refinement.h
/usr/include/pcl-1.7/pcl/filters/project_inliers.h
/usr/include/pcl-1.7/pcl/filters/fast_bilateral_omp.h
/usr/include/pcl-1.7/pcl/filters/clipper3D.h
/usr/include/pcl-1.7/pcl/filters/convolution.h
/usr/include/pcl-1.7/pcl/filters/passthrough.h
/usr/include/pcl-1.7/pcl/filters/conditional_removal.h
/usr/include/pcl-1.7/pcl/filters/impl
/usr/include/pcl-1.7/pcl/filters/impl/frustum_culling.hpp
/usr/include/pcl-1.7/pcl/filters/impl/conditional_removal.hpp
/usr/include/pcl-1.7/pcl/filters/impl/convolution_3d.hpp
/usr/include/pcl-1.7/pcl/filters/impl/voxel_grid_covariance.hpp
/usr/include/pcl-1.7/pcl/filters/impl/fast_bilateral_omp.hpp
/usr/include/pcl-1.7/pcl/filters/impl/project_inliers.hpp
/usr/include/pcl-1.7/pcl/filters/impl/morphological_filter.hpp
/usr/include/pcl-1.7/pcl/filters/impl/crop_box.hpp
/usr/include/pcl-1.7/pcl/filters/impl/covariance_sampling.hpp
/usr/include/pcl-1.7/pcl/filters/impl/local_maximum.hpp
/usr/include/pcl-1.7/pcl/filters/impl/plane_clipper3D.hpp
/usr/include/pcl-1.7/pcl/filters/impl/bilateral.hpp
/usr/include/pcl-1.7/pcl/filters/impl/voxel_grid_occlusion_estimation.hpp
....
By default libraries are installed in /usr/lib and header files will be in /usr/include
Usually extension of the library file is .so and corresponding header file will be .h
gui method for finding installed libraries is open software center->Developer tools-> Libraries

link wpa_supplicant against non-default openssl version

I want to compile wpa_supplicant using another version of openssl then the one installed on the build system.
To do this, I set these settings in the .config file:
CFLAGS += -I/custom-openssl/include
LIBS += -L/custom-openssl/lib
However, it is still linking against the default installed openssl version.
Your -L directive will be added to the end of the list of libraries to look for .so files during linking.
Instead, either control which directory the loader should look in while loading the binary (which can be compiled into the binary) or change the list of libraries to search using the LD_LIBRARY_PATH environment variable.
I also had to set LIBS_p. Everything else was fine.

How to find where older version of GLIB has been installed?

I am trying to install atk-2.4.0 and I get the error:
'pkg-config --modversion glib-2.0' returned 2.32.3, but GLIB (2.26.1)
*** was found!
I also tried updating PKG_CONFIG_PATH to include the path of glib-2.0.pc but still same error appears. Could anyone help me how to find where 2.26.1 was installed I am relatively new to Ununtu? Thanks.
Posting comments as response:
From find /usr/ -iname "*glib*.pc" it is found that there .pc file related to glib is available in /usr/lib/pkgconfig & /usr/local/lib/pkgconfig. Checking the system package management it appears that version 2.26.1 is installed from the repositories. The path for installation of glib from repositories is generally /usr/lib (This may vary a bit in case of 64 bit systems wherein there are different folders for 32 bit & 64 bit libraries). Thus it appears that glib also has been installed from source (guessing by installation path /usr/local/lib) which of version 2.32.2. If you need version 2.32.2 set PKG_CONFIG_PATH to /usr/local/lib/pkgconfig & LD_LIBRARY_PATH to /usr/local/lib/
Hope this helps!
You have to synchronize you PKG_CONFIG_PATH and LD_LIBRARY_PATH environment variables. Assuming that your prefix is /usr/local the followings should be set:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
LD_LIBRARY_PATH=/usr/local/lib
You may also need to set other variables to compile glib dependent softwares:
ACLOCAL_PATH=/usr/local/share/aclocal/
PATH=/usr/local/bin:$PATH

Resources