1

I have a project A that uses meson as the build system and another project B that depends on A.

A runs, compiles and passes all tests. I installed A by doing meson install, which put all the headers and shared library objects where I needed them to be.

After installing A I want to compile B so I added:

A               = dependency('A', include_type : 'system')
exe = executable(
    'B', 
    src, 
    dependencies: [
        A
    ],
    cpp_args : '-DSHADER_PATH="' +  meson.current_source_dir() + '/"',)

To the meson.build of B. meson does find A as a package and starts compiling B but fails to link. A defines a plethora of small utilities, each one as its own independent .so binary, all of which need to be linked against. Looking at the commands executed when compiling B, the directory where A's .so libraries are is added to the path using -L, but none of the libraries in that directory are listed for linking. So linking fials because the symbols in those binaries are not found (obviously they are not linked).

What do I need to specify in A to let it know a given library needs to be linked by default when the project is used as a dependency?

For example this is what one of the utilities of A looks like:

renderer_so_relative_path = \
    '' + renderer_lib.full_path().replace(meson.build_root() + '/', '')
peripheral_so_relative_path = \
    '' + peripheral_lib.full_path().replace(meson.build_root() + '/', '')

loader_sources = [
    'ModuleStorage.cpp',
    'CLI.cpp'
]
install_subdir('.', install_dir : 'include/ModuleStorage/')
loader_lib = library(
    'ne_loader',
    sources : loader_sources,
    cpp_args : [
        '-DNE_RENDERER_PATH="' + renderer_so_relative_path + '"',
        '-DNE_PERIPHERAL_PATH="' + peripheral_so_relative_path + '"'
        ],
    link_with : [],
    include_directories : [],
    dependencies : [core_dep, image_dep, argparse_dep, glfw],
    install: true)

module_storage_dep = declare_dependency(link_with:loader_lib, include_directories: ['..'])

subdir('Imgui')
Makogan
  • 8,208
  • 7
  • 44
  • 112

1 Answers1

1

Maybe this helps:

Add to your A project:

# C compiler
ccompiler = meson.get_compiler('c')
# Where is the lib: 
a_lib_dir = '/install/dir'
# Find the lib: 
a_lib = ccompiler.find_library('a_lib_name', dirs: a_lib_dir)
# Create dependency
a_lib_dep = declare_dependency(
  dependencies: a_lib,
  include_directories: include_directories(inc_dir)
)

And link the dependency in B:

# Dependencies
b_deps = []
b_deps += dependency('alib', fallback:['alib', 'a_lib_dep'])
# Your B object
b_lib = static_library( 'blib', src,
    dependencies: b_deps,
    etc...)
# Your B object as someone's dependency (if needed):
b_as_dep = declare_dependency(
    link_with: b_lib,
    include_directories: inc_dirs,
    dependencies: b_deps)
Danijel
  • 8,198
  • 18
  • 69
  • 133