Reputation: 123
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?
Upvotes: 0
Views: 2832
Reputation: 225
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()
Upvotes: 0
Reputation: 123
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.
Upvotes: 2
Reputation: 8491
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?
Upvotes: 2