0

I'm using meson-build for a c++ project.

I created a directory called libs and put all the libraries I need inside it , how do I link with it?

Daniel Trugman
  • 8,186
  • 20
  • 41

3 Answers3

2

After reading meson's dependencies manual, I don't think it has such an option. You should specify a dependency for every library you want to link.

And here is a snippet from the manual on how you should do that with your own libraries:

my_inc = include_directories(...)
my_lib = static_library(...)
my_dep = declare_dependency(link_with : my_lib, include_directories : my_inc)

BUT This is for the best, since you SHOULD control the linked libraries very carefully, why?

  1. Linking can be successful even if not all symbols are resolved, and the app will crash only at runtime.
  2. You want to control linkage order, in case you have more than one library with the same symbols
  3. You don't want to link unwanted libraries, because they might insert malicious code into your application (e.g. Your co-worker can plant a malicious library in that folder, and you will never know, but have a backdoor in your app)
Daniel Trugman
  • 8,186
  • 20
  • 41
2

Okay this is what I was looking for,

    cmplr = meson.get_compiler('cpp')
    mylib1 = cmplr.find_library('lib_name1', dir : 'path_to_directory')
    mylib2 = cmplr.find_library('lib_name2', dir : 'path_to_directory')
    ....
    executable(.... , dependencies : [mylib1, mylib2])

And thanks for the Tips.

0

I am reading all the file entries into a variable, then I parse them to get short lib name thanks to regexps. Then I loop on them to link them to my client lib (in my case imported libs...):

set(LIBS_DIR ${CMAKE_CURRENT_LIST_DIR}/../SMP/libs)
file(GLOB LIBS_FULL_NAME ${LIBS_DIR}/*.so)
message(STATUS "LIBS ${LIBS_FULL_NAME}")


FOREACH(LIB_FULL_NAME ${LIBS_FULL_NAME})
    message(STATUS "${LIB_FULL_NAME}")
    string(REGEX REPLACE "^.+/lib(.+).so$" "\\1" LIB_NAME ${LIB_FULL_NAME})
    message(STATUS "LIB_NAME ${LIB_NAME}")

    add_library( ${LIB_NAME}
            SHARED
            IMPORTED )

    set_target_properties( # Specifies the target library.
            ${LIB_NAME}

            # Specifies the parameter you want to define.
            PROPERTIES IMPORTED_LOCATION

            # Provides the path to the library you want to import.
            ${LIB_FULL_NAME} )

    target_link_libraries(clientlib ${LIB_NAME})
ENDFOREACH()
Cyrille Cormier
  • 167
  • 1
  • 8