Jump to page: 1 2
Thread overview
undefined symbol: rt_finalize
Feb 27, 2014
Tolga Cakiroglu
Feb 28, 2014
evilrat
Feb 28, 2014
Tolga Cakiroglu
Feb 28, 2014
evilrat
Feb 28, 2014
Mike
Feb 28, 2014
Mike
Feb 28, 2014
Tolga Cakiroglu
Feb 28, 2014
Tolga Cakiroglu
Feb 28, 2014
Mike
Feb 28, 2014
Tolga Cakiroglu
Feb 28, 2014
Tolga Cakiroglu
Feb 28, 2014
Tolga Cakiroglu
Feb 28, 2014
evilrat
Feb 28, 2014
Tolga Cakiroglu
Feb 28, 2014
Stanislav Blinov
Feb 28, 2014
Tolga Cakiroglu
February 27, 2014
I am trying to compile a shared library on Linux and use it.

lib.d
---------------------------
import core.runtime;

class A{}

extern(C) void foo(){
	Object obj = new Object();

	A objA = new A();

	char[] c = new char[ 1024 ];

	destroy( objA );
	destroy( c );
}


makefile:
--------------------------
lib:
	dmd -c lib.d -fPIC -debug -gc -g -w -wi
	gcc --shared lib.o -o lib.so


After getting the `foo` symbol in the app by using dlsym, I call it, the following is output on the shell:

library is loaded now
Running functions...
./app: symbol lookup error: ./lib.so: undefined symbol: rt_finalize


Where exactly is that function linked into an application? and why is it not linked into the library? Does it require an extra flag?
February 28, 2014
On Thursday, 27 February 2014 at 06:25:45 UTC, Tolga Cakiroglu wrote:
> I am trying to compile a shared library on Linux and use it.
>
> lib.d
> ---------------------------
> import core.runtime;
>
> class A{}
>
> extern(C) void foo(){
> 	Object obj = new Object();
>
> 	A objA = new A();
>
> 	char[] c = new char[ 1024 ];
>
> 	destroy( objA );
> 	destroy( c );
> }
>
>
> makefile:
> --------------------------
> lib:
> 	dmd -c lib.d -fPIC -debug -gc -g -w -wi
> 	gcc --shared lib.o -o lib.so
>
>
> After getting the `foo` symbol in the app by using dlsym, I call it, the following is output on the shell:
>
> library is loaded now
> Running functions...
> ./app: symbol lookup error: ./lib.so: undefined symbol: rt_finalize
>
>
> Where exactly is that function linked into an application? and why is it not linked into the library? Does it require an extra flag?

because there is no finalize. rt_init/rt_term is what you need

https://github.com/D-Programming-Language/druntime/blob/master/src/core/runtime.d#L30
February 28, 2014
>
> because there is no finalize. rt_init/rt_term is what you need
>
> https://github.com/D-Programming-Language/druntime/blob/master/src/core/runtime.d#L30

I looked at the `/usr/include/dmd/druntime` folder with `grep finalize -r`, and it brought me only one file, that is `object.di`.

When I check `object.di`, I see that rt_finalize is defined as `extern(C)` and it is called in `destroy` function. Thereby, it is defined by the DMD itself. So, there is a `finalize`, but even I am not doing anything special in the code, it is not finding it while having it in a normal programme.
February 28, 2014
On Friday, 28 February 2014 at 05:41:04 UTC, Tolga Cakiroglu wrote:
>>
>> because there is no finalize. rt_init/rt_term is what you need
>>
>> https://github.com/D-Programming-Language/druntime/blob/master/src/core/runtime.d#L30
>
> I looked at the `/usr/include/dmd/druntime` folder with `grep finalize -r`, and it brought me only one file, that is `object.di`.
>
> When I check `object.di`, I see that rt_finalize is defined as `extern(C)` and it is called in `destroy` function. Thereby, it is defined by the DMD itself. So, there is a `finalize`, but even I am not doing anything special in the code, it is not finding it while having it in a normal programme.

that finalize i guess is for finalizing objects. but destroy itself is deprecated. use clear() to do this instead.
February 28, 2014
On Friday, 28 February 2014 at 05:46:03 UTC, evilrat wrote:
>
> that finalize i guess is for finalizing objects. but destroy itself is deprecated. use clear() to do this instead.

I believe delete() and clear() are deprecated and destroy() is the correct method.  I recently read it somewhere, I'll try to find it.
February 28, 2014
On Friday, 28 February 2014 at 05:59:23 UTC, Mike wrote:
> On Friday, 28 February 2014 at 05:46:03 UTC, evilrat wrote:
>>
>> that finalize i guess is for finalizing objects. but destroy itself is deprecated. use clear() to do this instead.
>
> I believe delete() and clear() are deprecated and destroy() is the correct method.  I recently read it somewhere, I'll try to find it.

Here it is:  https://github.com/D-Programming-Language/dlang.org/pull/156
February 28, 2014
> that finalize i guess is for finalizing objects. but destroy itself is deprecated. use clear() to do this instead.

Nope. No chance. I have removed all imports. All `destroy`s are replaced with `clean`, and still same. I have deleted all executables and compiled again and again.

./app: symbol lookup error: ./lib.so: undefined symbol: rt_finalize


I thought maybe it is not about the library but the program. But when I DO NOT call that "foo" function, no error is seen. That means that piece of code is making this.

I have shared codes and makefile on Publink.
http://publink.neffie.com/subject/ydu59u5vXyrnNKDK20yd4SDWY7iGLU1OcM7nlslAuNsPtYSM602xHMYCpKp29WU5#635291642225045068

If you are on Linux and won't bother you, can you test it please.
February 28, 2014
On Friday, 28 February 2014 at 06:02:30 UTC, Mike wrote:
> On Friday, 28 February 2014 at 05:59:23 UTC, Mike wrote:
>> On Friday, 28 February 2014 at 05:46:03 UTC, evilrat wrote:
>>>
>>> that finalize i guess is for finalizing objects. but destroy itself is deprecated. use clear() to do this instead.
>>
>> I believe delete() and clear() are deprecated and destroy() is the correct method.  I recently read it somewhere, I'll try to find it.
>
> Here it is:  https://github.com/D-Programming-Language/dlang.org/pull/156

It doesn't matter. `free`, `destroy`, `clear`. All of them are same. The only successful result I have found was to define `extern(C) rt_finalize2` and use it instead of destroy. It works with it, but this doesn't seem like the correct behaviour.
February 28, 2014
On Thursday, 27 February 2014 at 06:25:45 UTC, Tolga Cakiroglu wrote:
> I am trying to compile a shared library on Linux and use it.
>
> lib.d
> ---------------------------
> import core.runtime;
>
> class A{}
>
> extern(C) void foo(){
> 	Object obj = new Object();
>
> 	A objA = new A();
>
> 	char[] c = new char[ 1024 ];
>
> 	destroy( objA );
> 	destroy( c );
> }
>
>
> makefile:
> --------------------------
> lib:
> 	dmd -c lib.d -fPIC -debug -gc -g -w -wi
> 	gcc --shared lib.o -o lib.so
>
>
> After getting the `foo` symbol in the app by using dlsym, I call it, the following is output on the shell:
>
> library is loaded now
> Running functions...
> ./app: symbol lookup error: ./lib.so: undefined symbol: rt_finalize
>
>
> Where exactly is that function linked into an application? and why is it not linked into the library? Does it require an extra flag?

rt_finalize is defined in lifetime.d (https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d).  Its part of the D runtime.  It just forwards to rt_finalize2.

I don't know why you are getting an undefined symbol, though.  Is the signature different?
February 28, 2014
>
> rt_finalize is defined in lifetime.d (https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d).
>  Its part of the D runtime.  It just forwards to rt_finalize2.
>
> I don't know why you are getting an undefined symbol, though.  Is the signature different?

I made some changes in code and culled a big part of it. Now the new error is:

./app: symbol lookup error: ./lib.so: undefined symbol: _d_newarrayiT


The exact codes are below:

app.d
------------------------------------
import core.sys.posix.dlfcn;

void main(){
	void *lh = dlopen("./lib.so", RTLD_LAZY);
	void function() foo = cast(void function())( dlsym( lh, "foo" ) );
	foo();
}


lib.d
------------------------------------
class A{}

extern(C) void foo(){
	Object obj = new Object();

	A objA = new A();

	char[] c = new char[ 1024 ];

	clear( objA );
	clear( obj );
	clear( c );
}


makefile
------------------------------------
all: clean lib app

lib:
	dmd -c lib.d -fPIC -debug -gc -g -w -wi
	gcc --shared lib.o -o lib.so

app:
	dmd app.d -L-ldl -L-lrt -debug -gc -g -w -wi

clean:
	rm -f lib.so
	rm -f lib.o
	rm -f app
« First   ‹ Prev
1 2