www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - How to get ldc2 to link dynamically to Phobos

reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
W.r.t. my recent thread 
http://forum.dlang.org/post/mvt67j$3dg$1 digitalmars.com on Phobos still 
being statically linked in, it was suggested that I should use the -
defaultlib=libphobos2.so option. This works fine with DMD 2.068.2 but I'm 
not sure how to get it working with LDC. LDC doesn't seem to ship with a 
compiled Phobos SO so I just symlinked it from DMD's one (not sure whether 
that is compatible or not though):

$ pwd
/opt/ldc2-0.16.0-beta2-linux-x86_64/lib
$ ls -l
total 51956
-rw-r--r-- 1 samjnaa samjnaa  2403108 Oct 10 18:25 libdruntime-ldc.a
-rw-r--r-- 1 samjnaa samjnaa  4822716 Oct 10 18:25 libdruntime-ldc-debug.a
-rw-r--r-- 1 samjnaa samjnaa 15820544 Oct 10 18:28 libphobos2-ldc.a
-rw-r--r-- 1 samjnaa samjnaa 30150532 Oct 10 18:29 libphobos2-ldc-debug.a
lrwxrwxrwx 1 samjnaa samjnaa       18 Oct 18 08:19 libphobos2.so -> 
libphobos2.so.0.68
lrwxrwxrwx 1 samjnaa samjnaa       20 Oct 18 08:19 libphobos2.so.0.68 -> 
libphobos2.so.0.68.2
lrwxrwxrwx 1 samjnaa samjnaa       46 Oct 18 08:18 libphobos2.so.0.68.2 -> 
/usr/lib/x86_64-linux-gnu/libphobos2.so.0.68.2

... but anyhow I keep getting the error:

/usr/bin/ld: cannot find -llibphobos2.so
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1

BTW why is LDC using gcc and not clang to link?

-- 
Shriramana Sharma, Penguin #395953
Oct 17 2015
parent David Nadlinger via digitalmars-d-ldc <digitalmars-d-ldc puremagic.com> writes:
On 18 Oct 2015, at 5:07, Shriramana Sharma via digitalmars-d-ldc wrote:
 LDC doesn't seem to ship with a compiled Phobos SO
This is a restriction in our current build system that could be easily lifted by some refactoring; I wish somebody would take care of it (*hint, hint*).
 so I just symlinked it from DMD's one (not sure whether
 that is compatible or not though):
It is not; not even between different releases of the same compiler.
 ... but anyhow I keep getting the error:

 /usr/bin/ld: cannot find -llibphobos2.so
 collect2: error: ld returned 1 exit status
 Error: /usr/bin/gcc failed with status: 1
Seems like that's an invalid linker command, right? (DMD might detect whether you pass a whole file name, but I'm not sure we do, although I vaguely remember Kai working on something to that effect.)
 BTW why is LDC using gcc and not clang to link?
Because all we really care about is that it is a gcc-compatible C compiler that knows where to find its standard libraries. If not for the latter, we'd use the system linker directly. As for "gcc" vs. "clang", it turns out that for example on OS X, where Clang is the default, there is still a "gcc" symlink for compatibility purposes anyway (FreeBSD doesn't have one, though, IIRC). And on Linux, GCC is still more widespread than Clang, so simply using "gcc" just works on most systems. — David
Oct 18 2015