[CMake] How to build and reference dlopen-able libraries?

J Decker d3ck0r at gmail.com
Fri Sep 5 23:49:44 EDT 2014


you'll need separate includes for dlopen thing, because you'll need the
functions declares are pointers...

void (*f)( void );
or typedefed as functions
typedef void (*some_function_type)( void );
some_function_type f;

Or better include all those in a structure

struct dl_interface
{
    void (*f)( void );
} lib_interface;

void Init(void )
{
   int dl = dlopen( "lib", 0 );
   lib_interface.f = dlsym( dl, "f" );
}

but none of that will be given by external headers.


On Fri, Sep 5, 2014 at 4:16 PM, Nils Gladitz <nilsgladitz at gmail.com> wrote:

> On 06.09.2014 00:44, Ted Middleton wrote:
>
>> Just wondering if there's a nice way of getting a library target's
>> includes but not linking to it, so I can use dlopen() on it instead. If I
>> want to build a shared library that gets implicitly loaded by an
>> executable, I would do this:
>>
>>   mylib/CMakeLists.txt:
>>   add_library( mylib SHARED src/mylibmain.c src/mylibsomething.c )
>>   target_include_directories( mylib PRIVATE src PUBLIC inc )
>>   target_link_libraries( mylib png )
>>
>>   myexe/CMakeLists.txt:
>>   add_executable( myexe src/main.c src/stuff.c )
>>   target_include_directories( myexe PRIVATE src )
>>   target_link_libraries( myexe PRIVATE mylib )
>>
>> What I really want, though, is for mylib's public include dir to be
>> accessible to myexe, but I don't want myexe to link to mylib - I'm going to
>> load it with dlopen()/LoadLibrary(). Do I have to do something like this:
>>
>>   myexe/CMakeLists.txt:
>>   get_property( mylibincs TARGET mylib PROPERTY
>> INTERFACE_INCLUDE_DIRECTORIES )
>>   add_executable( myexe src/main.c src/stuff.c )
>>   target_include_directories( myexe PRIVATE src ${mylibincs} )
>>   #target_link_libraries not necessary
>>
>>
>> This must be really simple, but I can't seem to find anything about it on
>> the cmake wikis or through google. There's a very old post from 2006 or so
>> (pre target properties, it uses include_directories()).
>>
>
> Try target_include_directories(myexe PRIVATE $<TARGET_PROPERTY:mylib,
> INTERFACE_INCLUDE_DIRECTORIES>)
>
> Nils
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140905/24664036/attachment.html>


More information about the CMake mailing list