M
M
Monnoroch2012-10-15 23:28:31
linux
Monnoroch, 2012-10-15 23:28:31

Shared library on D?

Is there a way to build .so on D cross-platform?
At the moment, I encountered the fact that on one machine (ubuntu 12.04, x86) it is assembled, and moreover, it fully works, but on the other (the same OS, x86-64) it does not.
I collect like this:

dmd -c -fPIC test.d -I. -J.
gcc test.o -shared -lrt -lpthread -lphobos2 -o libtest.so

On one machine (x86) everything builds and works, on the other (x86-64) the first command succeeds: compilation, while building with gcc gives the following error:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libphobos2.a(minfo.o): relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC

/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libphobos2.a: could not read symbols: Bad value

collect2: error: ld returned 1 exit status

make: *** [test] Ошибка 1<br>

The dmd version is the latest, freshly downloaded. Version of gcc 4.7 (was 4.6, the same garbage happened there).
Also, despite the fact that it should determine by itself, I tried to set the -m64 flag for both commands, without changing the result.
Accordingly, the question is: is it possible, and if so, how, to build a dynamic library in D on a 64-bit system? The use of dmd is not essential, that is, I would still like to leave the reference compiler, but if it is not possible, then other implementations are also good.
Upd: The solution was to build druntime and phobos themselves manually with the gcc and dmd -fPIC options enabled. I made a pull request with patched makefiles to the official repository, let's see if they will accept it, but I collected everything at home, thanks to everyone.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
egorinsk, 2012-10-16
@egorinsk

If they don’t answer here, you should write directly to the mailing list of this compiler, they should definitely know there.

M
mithraen, 2012-10-16
@mithraen

It looks like -fPIC is simply ignored by the compiler.
On x86 it is possible to build shared libs without -fPIC. On x86_64, no.

M
Monnoroch, 2012-10-16
@Monnoroch

The solution was to build druntime and phobos themselves manually with the gcc and dmd -fPIC options enabled. I made a pull request with patched makefiles to the official repository, let's see if they will accept it, but I collected everything at home, thanks to everyone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question