www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - The module 'foo' is already defined in 'libmylib.so'

reply Timothee Cour via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
I want to update a library with new symbols (ie partial recompilation):

libmylib.so : compiled from bar.d and foo.d

now update the file foo.d

dmd -c -fPIC foo.d -offoo.o

clang++ -o libmylib_update.so foo.o -shared -Wl,-lmylib

When trying to dlopen libmylib_update.so from C++ it fails with:
The module 'foo' is already defined in 'libmylib.so'

(it somehow works when the dlopen is called from D)

How would I achieve that?
Dec 01 2016
parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Thursday, 1 December 2016 at 22:05:06 UTC, Timothee Cour wrote:
 I want to update a library with new symbols (ie partial 
 recompilation):

 libmylib.so : compiled from bar.d and foo.d

 now update the file foo.d

 dmd -c -fPIC foo.d -offoo.o

 clang++ -o libmylib_update.so foo.o -shared -Wl,-lmylib

 When trying to dlopen libmylib_update.so from C++ it fails 
 with: The module 'foo' is already defined in 'libmylib.so'

 (it somehow works when the dlopen is called from D)

 How would I achieve that?
Have a look at what `trace -E d_executable args` and `trace -E c++_executable args` print on startup and grep for dlopen calls and the like.
Dec 01 2016
parent reply timotheecour <timothee.cour2 gmail.com> writes:
 Have a look at what `trace -E d_executable args` and `trace -E 
 c++_executable args`
 print on startup and grep for dlopen calls and the like.
do you mean strace? I have trace on OSX but I'm asking for linux.
Dec 09 2016
parent timotheecour <timothee.cour2 gmail.com> writes:
On Saturday, 10 December 2016 at 02:39:33 UTC, timotheecour wrote:
 Have a look at what `trace -E d_executable args` and `trace -E 
 c++_executable args`
 print on startup and grep for dlopen calls and the like.
do you mean strace? I have trace on OSX but I'm asking for linux.
Looking at the code for $checkModuleCollisions in druntime [src/rt/sections_elf_shared.d:859]: ``` * Check for module collisions. A module in a shared library collides * with an existing module if it's ModuleInfo is interposed (search * symbol interposition) by another DSO. Therefor two modules with the * same name do not collide if their DSOs are in separate symbol resolution * chains. ``` Not exactly sure what that means nor how to fix my issue: ``` void some_fun(){ handle=dlopen2("path/liblib.so", RTLD_LAZY | RTLD_LOCAL); // error: The module 'foo' is already defined in 'libmylib.so' } ``` How would I modify the code to avoid this?
Dec 09 2016