Hi,

I'd like to compile ui/repl.c into a shared library so that I could dlopen 
julia after some other initialization procedures that would otherwise conflict 
with the LLVM linked to julia.

I succeeded in doing that on OSX using:

~~~
diff --git a/ui/Makefile b/ui/Makefile
+julia-release: $(build_bindir)/julia$(EXE) 
$(build_private_libdir)/librepl.$(SHLIB_EXT)
...
+$(build_private_libdir)/librepl.$(SHLIB_EXT): $(OBJS)
+       @$(call PRINT_LINK, $(CXXLD) -shared $(CXXFLAGS) $(CXXLDFLAGS) 
$(LINK_FLAGS) $(SHIPFLAGS) $^ -o $@ -L$(build_private_libdir) -L$(build_libdir) 
-L$(build_shlibdir)
~~~

so I can call julia dynamically as 
~~~
 my_init(); // initalize stuff that hides its LLVM symbols after loading 
...
 void* handle_julia = dlopen(LIBJULIAREPL, RTLD_NOW | RTLD_GLOBAL);
...
 typedef int (*t_jl_main)(int, char**);
 t_jl_main jl_main = (t_jl_main)dlsym(handle_julia, "main");
 return jl_main(argc, argv);
~~~

On linux, I get strange linker errors:
`/usr/bin/ld: repl.o: relocation R_X86_64_TPOFF32 against `tls_states.12084' 
can not be used when making a shared object; recompile with -fPIC`

As far as I can tell, julia uses fPIC throughout. Has anyone encountered 
something like this before? Google links to some old gcc bugs and a go linker 
issue but it's not evident if there is a fix.

Cheers,
Joosep

Reply via email to