www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Creating a dynamic library

reply Tony <tonytdominguez aol.com> writes:
I would like to know that command line (I am on Linux) I would 
use to compile a D file and create an object file that is 
suitable for a Linux dynamic library (.so).

I believe it is probably

dmd -c -fPIC my_file.d

Also, what is the command line to create a dynamic library from 
one or more object files that have been compiled for dynamic 
invocation?

dmd ??? -shared ???
	
Sep 29 2017
parent reply Elronnd <elronnd em.slashem.me> writes:
dmd bla.d bla2.d -shared -fPIC -oflibbla.so
Sep 29 2017
parent reply Tony <tonytdominguez aol.com> writes:
On Saturday, 30 September 2017 at 01:02:08 UTC, Elronnd wrote:
 dmd bla.d bla2.d -shared -fPIC -oflibbla.so
Thanks. I don't normally compile right into a .so, but I think this is OK: dmd my_file.o my_other_file.o -shared -of=libutest.so One thing I picked up from SCons is creating dynamic object files with a .os extension and static object files with the standard .o extension. That way they can be compiled in the same directory in the same build step. But dmd rejects the files that are named *.os. Is there an extension besides .o that dmd would accept for the dynamic object files?
Sep 29 2017
parent reply Mike Wey <mike-wey example.com> writes:
On 30-09-17 03:27, Tony wrote:
 One thing I picked up from SCons is creating dynamic object files with a 
 .os extension and static object files with the standard .o extension. 
 That way they can be compiled in the same directory in the same build 
 step. But dmd rejects the files that are named *.os. Is there an 
 extension besides .o that dmd would accept for the dynamic object files?
I've been using .pic.o so it still ends with .o for dmd. -- Mike Wey
Sep 30 2017
parent Tony <tonytdominguez aol.com> writes:
On Saturday, 30 September 2017 at 10:09:43 UTC, Mike Wey wrote:
 On 30-09-17 03:27, Tony wrote:
 One thing I picked up from SCons is creating dynamic object 
 files with a .os extension and static object files with the 
 standard .o extension. That way they can be compiled in the 
 same directory in the same build step. But dmd rejects the 
 files that are named *.os. Is there an extension besides .o 
 that dmd would accept for the dynamic object files?
I've been using .pic.o so it still ends with .o for dmd.
Thanks for the suggestion! I was thinking that this might be a linker function only and tried to use g++ and gcc for the .so creation but, while they both create the same size file as each other, it is different than what dmd does when called with -shared.
Sep 30 2017