How can I specify library path when using Meson?
If I understand the documentation correctly, you could use different / others build system as subproject, and it doesn't seem basing on cmake.
You should be able to define CMAKE_PREFIX_PATH
in a CMakeList.txt of a cmake project, and access the generated library within meson
context:
in your cmake subproject:
add_library(cm_lib SHARED ${SOURCES})
in your meson:
cmake = import('cmake')
# Configure the CMake project
sub_proj = cmake.subproject('libsimple_cmake')
# Fetch the dependency object
cm_lib = sub_proj.dependency('cm_lib')
executable(exe1, ['sources'], dependencies: [cm_lib])
if you only want to propagate any specific library to meson
, than it looks like you'll need to bundle those third party library, or using built-in options.
But first of all: Have you check, either /opt/conda
is in your LD_LIBRARY_PATH
?
I see two possible approaches to solve your problem.
- the first solution uses
LIBRARY_PATH
, which is different fromLD_LIBRARY_PATH
as explained later. the second solution uses a modified meson file to directly pass options to the linker. Optionally, it also uses
rpath
that eliminates the need to modifyLD_LIBRARY_PATH
afterward.- First solution
When building your project the linker use LIBRARY_PATH
(and not LD_LIBRARY_PATH
)
LIBRARY_PATH
is used by gcc before compilation to search directories containing static and shared libraries that need to be linked to your program.
LD_LIBRARY_PATH
is used by your program to search directories containing shared libraries after it has been successfully compiled and linked.
further details: LD_LIBRARY_PATH vs LIBRARY_PATH
Maybe you can try
export LIBRARY_PATH=/opt/conda/:$LIBRARY_PATH
before running meson to build your project.
- Second solution
Modifying your meson file and use rpath
(optional)
An alternative to the previous first solution is to directly modify your Meson file to pass some options to the linker.
Here is something I used in the past you can easily adapt to your problem:
#
# blaspp
#
blaspp_lib = 'blaspp'
blaspp_lib_dir = '/opt/slate/lib'
blaspp_header_dir = '/opt/slate/include'
blaspp_dep = declare_dependency(
link_args : ['-L' + blaspp_lib_dir, '-l' + blaspp_lib],
include_directories : include_directories(blaspp_header_dir))
executable('test_blaspp',
'test_blaspp.cpp',
build_rpath : blaspp_lib_dir,
install_rpath : blaspp_lib_dir,
dependencies : [blaspp_dep])
declare_dependency(...) defines options to pass to the linker (this replaces the need to define
LIBRARY_PATH
in the first solution)executable(...) defines
rpath
. This is an optional step that embeds the extra library path information directly into the executable. If you use this, you will not have to modify theLD_LIBRARY_PATH
when running your executable.
Further details: https://amir.rachum.com/blog/2016/09/17/shared-libraries/ (have a look at the "rpath and runpath" section) and see wikipedia: https://en.wikipedia.org/wiki/Rpath