[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to determine the filename for dlopen()



Christian Seiler <christian@iwakd.de> writes:

> Am 2017-11-13 13:23, schrieb wferi@niif.hu:
>
>> I'm packaging a program which wants to dlopen() some library.  It finds
>> this library via pkg-config (PKG_CHECK_MODULES).  How to best determine
>> the filename to use in the dlopen() call?  It should work cross-distro,
>> for cross-compilation and whatnot.  Is it always safe to use the SONAME
>> as the filename?
>
> The SONAME is the right thing to do here, as that is what's encoded in
> the DT_NEEDED field by the linker.
>
>> I'm currently considering something like
>>
>> ld -shared -o dummy.so $(my_LIBS)
>> objdump -p dummy.so | fgrep NEEDED
>
> That might work, but I'm not sure that's very stable.

Hi Christian,

The main problem with this is that my_LIBS as set by PKG_CHECK_MODULES
may contain multiple libraries, and nothing guarantees that I need the
first one.  But there's probably no cure for that.  And it failed badly
on FreeBSD for some reason...  So now I need a BSD machine to log on.

> find_library(PNG_LIBRARY_FILE NAMES png)

Yes, finding the library is what I wanted to offload to ld.  It's
somewhat hairy to scan the library path, or at least I haven't found the
appropriate tool.

> Important:

[Lots of interesting stuff, thanks!]

>  - If you do manage to write some relatively generic code, I would
>    urge you to contribute that to CMake as a macro, so that other
>    people could also profit from it.

That probably won't happen in the near future, as I've never used CMake,
just tried to parse your code based on English and common sense. :)
-- 
Regards,
Feri


Reply to: