www.digitalmars.com         C & C++   DMDScript  

D.gnu - creating static/dynamic lib (_minit remains unresolved)

reply =?ISO-8859-15?Q?Manuel_K=F6nig?= <manuelk89 gmx.net> writes:
Hi there,

I've got a problem creating libraries with gdc (Windows-version). I want 
to build a library in D using gdc and link it against a C-program using 
gcc. Since the spec says I have to do some module startup I have to call 
_minit() like this:

// in library.d:
extern (C)
{
	void gc_init();
	void gc_term();
	void _minit();
	void _moduleCtor();
}

extern(C) export void initLibrary()
{
	gc_init();			
	_minit();		// <== initialize module list
	_moduleCtor();
}

As you can see I export this function, so that my C-prog can call that 
to initialize the library. Building the (static) library and linking it 
to a C-program works fine with dmd and dmc. But when I use gdc/gcc, my 
library compiles without errors, but linking it against my C-program gives:

	undefined reference to '_minit'

Hence this functions? implementation is not in my lib. I tried linking 
"libgphobos" against both gdc and gcc in any combination, but the 
problem remains.

I tried building it without this init stuff, and gdc built the library, 
I could link it with my C-prog and call the exported functions, but for 
sure it gave errors when memory got allocated 'n stuff. But this shows 
that its no general library creation problem, rather an unresolved external.

Does anyone know how to get rid of this problem? (or show me that I'm a 
noob and theres a totally different approach for gdc ...)
Jan 17 2007
next sibling parent reply Sean Kelly <sean f4.ca> writes:
Manuel König wrote:
 Hi there,
 
 I've got a problem creating libraries with gdc (Windows-version). I want 
 to build a library in D using gdc and link it against a C-program using 
 gcc. Since the spec says I have to do some module startup I have to call 
 _minit() like this:
 
 // in library.d:
 extern (C)
 {
     void gc_init();
     void gc_term();
     void _minit();
     void _moduleCtor();
 }
 
 extern(C) export void initLibrary()
 {
     gc_init();           
     _minit();        // <== initialize module list
     _moduleCtor();
 }
 
 As you can see I export this function, so that my C-prog can call that 
 to initialize the library. Building the (static) library and linking it 
 to a C-program works fine with dmd and dmc. But when I use gdc/gcc, my 
 library compiles without errors, but linking it against my C-program gives:
 
     undefined reference to '_minit'
 
 Hence this functions? implementation is not in my lib. I tried linking 
 "libgphobos" against both gdc and gcc in any combination, but the 
 problem remains.
 
 I tried building it without this init stuff, and gdc built the library, 
 I could link it with my C-prog and call the exported functions, but for 
 sure it gave errors when memory got allocated 'n stuff. But this shows 
 that its no general library creation problem, rather an unresolved 
 external.
 
 Does anyone know how to get rid of this problem? (or show me that I'm a 
 noob and theres a totally different approach for gdc ...)
See internal/dgccmain2.d. GDC's startup routine is different from DMD's, which suggests that a function be provided to generalize library startup of D code. However, I think what you need to do is this: _STI_monitor_staticctor(); _STI_critical_init(); gc_init(); _moduleCtor(); _moduleUnitTests(); Sean
Jan 17 2007
parent =?ISO-8859-15?Q?Manuel_K=F6nig?= <manuelk89 gmx.net> writes:
Sean Kelly schrieb:
 Manuel König wrote:
 Hi there,

 I've got a problem creating libraries with gdc (Windows-version). I 
 want to build a library in D using gdc and link it against a C-program 
 using gcc. Since the spec says I have to do some module startup I have 
 to call _minit() like this:

 // in library.d:
 extern (C)
 {
     void gc_init();
     void gc_term();
     void _minit();
     void _moduleCtor();
 }

 extern(C) export void initLibrary()
 {
     gc_init();               _minit();        // <== initialize module 
 list
     _moduleCtor();
 }

 As you can see I export this function, so that my C-prog can call that 
 to initialize the library. Building the (static) library and linking 
 it to a C-program works fine with dmd and dmc. But when I use gdc/gcc, 
 my library compiles without errors, but linking it against my 
 C-program gives:

     undefined reference to '_minit'

 Hence this functions? implementation is not in my lib. I tried linking 
 "libgphobos" against both gdc and gcc in any combination, but the 
 problem remains.

 I tried building it without this init stuff, and gdc built the 
 library, I could link it with my C-prog and call the exported 
 functions, but for sure it gave errors when memory got allocated 'n 
 stuff. But this shows that its no general library creation problem, 
 rather an unresolved external.

 Does anyone know how to get rid of this problem? (or show me that I'm 
 a noob and theres a totally different approach for gdc ...)
See internal/dgccmain2.d. GDC's startup routine is different from DMD's, which suggests that a function be provided to generalize library startup of D code. However, I think what you need to do is this: _STI_monitor_staticctor(); _STI_critical_init(); gc_init(); _moduleCtor(); _moduleUnitTests(); Sean
Many Thanks, Sean. You saved more thand 11.000 lines of code! I searched hours for that, is there any documentation? If not, there really should be one! Manuel König
Jan 17 2007
prev sibling parent sclytrack <sclytrack pi.be> writes:
== Quote from Manuel_König (manuelk89 gmx.net)'s article
 Hi there,
 I've got a problem creating libraries with gdc (Windows-version). I want
 to build a library in D using gdc and link it against a C-program using
 gcc. Since the spec says I have to do some module startup I have to call
all: main.o libgui.so cc -o main main.o -lpthread -ldl -lm -lgphobos -L. -lgui
 "libgphobos" against both gdc and gcc in any combination, but the
 problem remains.
Jan 17 2007