Commits

ariovistus committed 2b08c1e

Oh, Ubuntu, how I love thee.
A difference in configuration of ld on ubuntu vs fedora was causing
phobos-ldc to not get linked in to extensions

Comments (0)

Files changed (5)

         self._outputOpts = ['-of', '%s']
         self._linkOutputOpts = ['-o', '%s']
         # _linkOpts
-        self._linkOpts = ['-nostartfiles', '-shared','-lphobos-ldc','-ldruntime-ldc', '-lrt','-lpthread','-ldl','-lm']
+        self._linkOpts = ['-nostartfiles', '-shared','-Wl,--no-as-needed','-lphobos-ldc','-ldruntime-ldc', '-lrt','-lpthread','-ldl','-lm']
         # _includeOpts
         self._includeOpts = ['-I', '%s']
         # _versionOpt

examples/misc/ldc_sharedlibs/makefile

 # from fedora repos
 LDC=ldc2
 
+# build a shared library written in D, main program written in C.
 test1: test1.x libtest1.so
 	LD_LIBRARY_PATH=. ./test1.x
 
+# build 2 shared libraries written in D, main program written in C.
+# not working: druntime needs some tlc.
 test2: test2.x libtest2a.so libtest2b.so
 	LD_LIBRARY_PATH=. ./test2.x
+# build a shared library written in C with global data. Access global data in D
 test3: test3.x libtest3.so
 	LD_LIBRARY_PATH=. ./test3.x
 clean:
 	rm -f *.so
 	rm -f *.x
 
-LIBS= -lphobos-ldc -ldruntime-ldc -lrt -lpthread -ldl -lm -lpython2.7
+LIBS= -Wl,--no-as-needed -lphobos-ldc -ldruntime-ldc -lrt -lpthread -ldl -lm -lpython2.7
 
 %.o: %.d
 	echo "building $@"
 
 test1.x: test1.c libtest1.so
 	echo "building $@"
-	LD_LIBRARY_PATH=. gcc $< -L. -ltest1 -o $@
+	gcc $< -l:libtest1.so -o $@ 
+
 test2.x: test2.c libtest2a.so libtest2b.so
 	echo "building $@"
 	LD_LIBRARY_PATH=. gcc $< -L. -ltest2a -ltest2b -o $@
 
-test3.x: test3.d
+test3.x: test3.d libtest3.so
 	LD_LIBRARY_PATH=. $(LDC) $< -L-L. -L-ltest3 -of $@ 
 libtest3.so: test3lib.c
 	gcc -fPIC -shared $< -o $@

examples/misc/ldc_sharedlibs/test1.c

 int foo(int);
 
 int main() {
-    printf("foo(%d)=%d\n", 2, foo(2));
+    printf("Success! foo(%d)=%d\n", 2, foo(2));
     return 0;
 }
 

examples/misc/ldc_sharedlibs/test2.c

 
 int main() {
     printf("foo(%d): %d\n", 1, foo(1));
-    printf("wiz(%f): %d\n", 1.0, wiz(1.0));
+    printf("Success! wiz(%f): %d\n", 1.0, wiz(1.0));
     return 0;
 }

examples/misc/ldc_sharedlibs/test3.d

+import std.string;
 
 extern(C) {
     struct Foobar {
         int j;
         double d;
     }
-    __gshared Foobar foo;
+    export extern __gshared Foobar foo;
 }
 
 void main() {
     import std.stdio;
-    writeln(foo.i);
-    writeln(foo.j);
-    writeln(foo.d);
+    assert(foo.i == 1, format("foo.i=%s vs 1", foo.i));
+    assert(foo.j == 2, format("foo.j=%s vs 2", foo.j));
+    assert(foo.d == 3.4, format("foo.j=%s vs 3.4", foo.j));
 }