Thread overview
unresolved external symbol in BetterC
Dec 08, 2019
Marcel
Dec 08, 2019
Mike Parker
Dec 08, 2019
Marcel
Dec 08, 2019
Marcel
Dec 08, 2019
kinke
Dec 08, 2019
Marcel
December 08, 2019
I've been getting some weird linker errors around main() when I declare a struct with a destructor. Is it possible that exception code is being generated even though I have the -betterC flag enabled?

//Example code:
extern(C) void main()
{
	auto window = Window("Hello", 0, 0, 800, 600);
	while(window.IsLive)
		window.Update;
}
December 08, 2019
On Sunday, 8 December 2019 at 19:29:23 UTC, Marcel wrote:
> I've been getting some weird linker errors around main() when I declare a struct with a destructor. Is it possible that exception code is being generated even though I have the -betterC flag enabled?
>
> //Example code:
> extern(C) void main()
> {
> 	auto window = Window("Hello", 0, 0, 800, 600);
> 	while(window.IsLive)
> 		window.Update;
> }

Struct destructors should work in betterC. It would be helpful if you can paste the errors.
December 08, 2019
On Sunday, 8 December 2019 at 19:36:40 UTC, Mike Parker wrote:
> Struct destructors should work in betterC. It would be helpful if you can paste the errors.

extern(C) void main()
{
	auto pool = ObjectPool!(int)(100);
	auto a = pool.Acquire;
	pool.Release(*a);
}

This code generates the two following errors:

1>Test.obj : error LNK2019: unresolved external symbol _d_enter_cleanup referenced in function "?dtor$5@?0?"ref Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array.opAssign(const(Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array))" (_D11Collections6Arrays__T5ArrayTSQBf11ObjectPools__T10ObjectPoolTiTS6Memory10Allocators16DefaultAllocatorZQCc5EntryTQBxZQDr8opAssignMFNcxSQFgQEw__TQEsTQEpTQDkZQFeZSQGgQFw__TQFsTQFpTQEkZQGe)@4HA" (?dtor$5@?0?"ref Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array.opAssign(const(Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array))" (_D11Collections6Arrays__T5ArrayTSQBf11ObjectPools__T10ObjectPoolTiTS6Memory10Allocators16DefaultAllocatorZQCc5EntryTQBxZQDr8opAssignMFNcxSQFgQEw__TQEsTQEpTQDkZQFeZSQGgQFw__TQFsTQFpTQEkZQGe)@4HA)

1>Test.obj : error LNK2019: unresolved external symbol _d_leave_cleanup referenced in function "?dtor$5@?0?"ref Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array.opAssign(const(Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array))" (_D11Collections6Arrays__T5ArrayTSQBf11ObjectPools__T10ObjectPoolTiTS6Memory10Allocators16DefaultAllocatorZQCc5EntryTQBxZQDr8opAssignMFNcxSQFgQEw__TQEsTQEpTQDkZQFeZSQGgQFw__TQFsTQFpTQEkZQGe)@4HA" (?dtor$5@?0?"ref Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array.opAssign(const(Collections.Arrays.Array!(Collections.ObjectPools.ObjectPool!(int, Memory.Allocators.DefaultAllocator).ObjectPool.Entry, Memory.Allocators.DefaultAllocator).Array))" (_D11Collections6Arrays__T5ArrayTSQBf11ObjectPools__T10ObjectPoolTiTS6Memory10Allocators16DefaultAllocatorZQCc5EntryTQBxZQDr8opAssignMFNcxSQFgQEw__TQEsTQEpTQDkZQFeZSQGgQFw__TQFsTQFpTQEkZQGe)@4HA)
December 08, 2019
On Sunday, 8 December 2019 at 19:57:11 UTC, Marcel wrote:
> On Sunday, 8 December 2019 at 19:36:40 UTC, Mike Parker wrote:
>> [...]
>
> extern(C) void main()
> {
> 	auto pool = ObjectPool!(int)(100);
> 	auto a = pool.Acquire;
> 	pool.Release(*a);
> }
>
> [...]

Ok, I found a way to make this work by writing "nothrow:" inside each struct and module. Is this normal?
December 08, 2019
On Sunday, 8 December 2019 at 19:29:23 UTC, Marcel wrote:
> Is it possible that exception code is being generated even though I have the -betterC flag enabled?

Yes, a cleanup/finally is used, apparently in an opAssign. - These 2 symbols are apparently used to prevent too aggressive LLVM optimizations and are normally provided in druntime here [1]; you can add the 2 one-liners manually in a betterC project.

[1] https://github.com/ldc-developers/druntime/blob/d363d27e119e7cc41b8fd5ef2145d8a7ad140080/src/ldc/eh_msvc.d#L593-L606
December 08, 2019
On Sunday, 8 December 2019 at 20:58:44 UTC, kinke wrote:
> On Sunday, 8 December 2019 at 19:29:23 UTC, Marcel wrote:
>> Is it possible that exception code is being generated even though I have the -betterC flag enabled?
>
> Yes, a cleanup/finally is used, apparently in an opAssign. - These 2 symbols are apparently used to prevent too aggressive LLVM optimizations and are normally provided in druntime here [1]; you can add the 2 one-liners manually in a betterC project.
>
> [1] https://github.com/ldc-developers/druntime/blob/d363d27e119e7cc41b8fd5ef2145d8a7ad140080/src/ldc/eh_msvc.d#L593-L606

Perfect! Thank you very much!