gdc so files

Sclytrack Sclytrack at pi.be
Wed Jan 3 11:32:54 PST 2007


With dmd I had some trouble with so files. I could add plain functions in them
but once I started adding a class it went completely bezurk. I was informed
that this was due to dmd not supporting the linux so file format.

Now with version 1.0 I decided to give gdc 0.21 a try. I made a class and an
interface like this.

module gui;

interface ICaption
{
	char [] getCaption();
	void setCaption(char []);
}



class Window:ICaption {
private:
	char [] _caption;
public:
	void setCaption(char [] caption)
	{
		_caption = caption;
	}
	char [] getCaption()
	{
		return _caption;
	}
}


The above file is the file that goes into the so library, called libgui.so
I get an access violation when I try the interface from the
libgui.so file.

import std.stdio;
import gui;

int main()
{
	Window test = new Window();
	test.setCaption("Access via interface gives me a violation");
	ICaption itest = test;
	       //next line gets access violation
	writefln(itest.getCaption());
               //previous line Access violation via ICaption
	return 0;
}


I like listing the complete documentation. So here is the makefile I used.

all: main.o libgui.so
#	cc -o main main.o -lpthread -ldl -lm -lgphobos -L. -lgui
	gdc -o main main.o -L. -lgui

main.o: main.d
	gdc -c main.d

libgui.so: gui.o
	gdc -shared -o libgui.so gui.o

gui.o: gui.d
	gdc -c -fPIC gui.d


I was wondering is this the right method of doing .so files? Because in the
windows dll example one starts another garbage collector. Here no extra
garbage collector is started, or not that I'm aware of.

In the likely event that I won't thank you afterwards.

     Thanks in advance, Sclytrack


Go D, Go !!!


More information about the Digitalmars-d-learn mailing list