Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
October 11, 2013 Linker error: Symbol Undefined | ||||
---|---|---|---|---|
| ||||
Hey, I'm curious about this linker error: OPTLINK (R) for Win32 Release 8.00.13 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html bar.obj(bar) Error 42: Symbol Undefined _D3foo1A6__dtorMFZv --- errorlevel 1 foo.d: ---- debug import std.stdio; struct A { public: int id; this(int id) { debug writeln("CTor A with ", id); this.id = id; } debug ~this() { writeln("DTor A with ", id); } } ---- bar.d ---- import foo; void test(A a) { a.id++; } void main() { test(A(42)); A a = A(23); test(a); } ---- Usage: C:\Users\Besitzer\Desktop>dmd -lib foo.d C:\Users\Besitzer\Desktop>dmd bar.d foo.lib -debug OPTLINK (R) for Win32 Release 8.00.13 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html bar.obj(bar) Error 42: Symbol Undefined _D3foo1A6__dtorMFZv --- errorlevel 1 ==== Without -debug or with 'debug' _in_ the DTor (before writeln) instead before the DTor works fine. |
October 11, 2013 Re: Linker error: Symbol Undefined | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | It's annoying and I don't get it. What is the problem of Optlink? I tried version(unittest) instead of debug. It works then with -debug, but if you compile with -unittest you get the same error. |
October 11, 2013 Re: Linker error: Symbol Undefined | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | It's due to having the destructor versioned out when building foo and visible when building bar. When brought together, you've created an incompatible whole. There's no destructor actually included in foo's .o file that you told it it could expect to find.
There's no bug in the compiler or linker, just your usage of mis-matched code.
On 10/11/13 11:39 AM, Namespace wrote:
> Hey, I'm curious about this linker error:
>
> OPTLINK (R) for Win32 Release 8.00.13
> Copyright (C) Digital Mars 1989-2010 All rights reserved.
> http://www.digitalmars.com/ctg/optlink.html
> bar.obj(bar)
> Error 42: Symbol Undefined _D3foo1A6__dtorMFZv
> --- errorlevel 1
>
> foo.d:
> ----
> debug import std.stdio;
>
> struct A {
> public:
> int id;
>
> this(int id) {
> debug writeln("CTor A with ", id);
>
> this.id = id;
> }
>
> debug ~this() {
> writeln("DTor A with ", id);
> }
> }
> ----
>
> bar.d
> ----
> import foo;
>
> void test(A a) {
> a.id++;
> }
>
> void main() {
> test(A(42));
> A a = A(23);
> test(a);
> }
> ----
>
> Usage:
>
> C:\Users\Besitzer\Desktop>dmd -lib foo.d
>
> C:\Users\Besitzer\Desktop>dmd bar.d foo.lib -debug
> OPTLINK (R) for Win32 Release 8.00.13
> Copyright (C) Digital Mars 1989-2010 All rights reserved.
> http://www.digitalmars.com/ctg/optlink.html
> bar.obj(bar)
> Error 42: Symbol Undefined _D3foo1A6__dtorMFZv
> --- errorlevel 1
>
> ====
> Without -debug or with 'debug' _in_ the DTor (before writeln) instead before the DTor works fine.
|
October 11, 2013 Re: Linker error: Symbol Undefined | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Roberts | Ok, that is what I wanted to hear. |
October 11, 2013 Re: Linker error: Symbol Undefined | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Roberts | On Friday, 11 October 2013 at 21:16:38 UTC, Brad Roberts wrote:
> It's due to having the destructor versioned out when building foo and visible when building bar. When brought together, you've created an incompatible whole. There's no destructor actually included in foo's .o file that you told it it could expect to find.
>
> There's no bug in the compiler or linker, just your usage of mis-matched code.
>
> On 10/11/13 11:39 AM, Namespace wrote:
>> Hey, I'm curious about this linker error:
>>
>> OPTLINK (R) for Win32 Release 8.00.13
>> Copyright (C) Digital Mars 1989-2010 All rights reserved.
>> http://www.digitalmars.com/ctg/optlink.html
>> bar.obj(bar)
>> Error 42: Symbol Undefined _D3foo1A6__dtorMFZv
>> --- errorlevel 1
>>
>> foo.d:
>> ----
>> debug import std.stdio;
>>
>> struct A {
>> public:
>> int id;
>>
>> this(int id) {
>> debug writeln("CTor A with ", id);
>>
>> this.id = id;
>> }
>>
>> debug ~this() {
>> writeln("DTor A with ", id);
>> }
>> }
>> ----
>>
>> bar.d
>> ----
>> import foo;
>>
>> void test(A a) {
>> a.id++;
>> }
>>
>> void main() {
>> test(A(42));
>> A a = A(23);
>> test(a);
>> }
>> ----
>>
>> Usage:
>>
>> C:\Users\Besitzer\Desktop>dmd -lib foo.d
>>
>> C:\Users\Besitzer\Desktop>dmd bar.d foo.lib -debug
>> OPTLINK (R) for Win32 Release 8.00.13
>> Copyright (C) Digital Mars 1989-2010 All rights reserved.
>> http://www.digitalmars.com/ctg/optlink.html
>> bar.obj(bar)
>> Error 42: Symbol Undefined _D3foo1A6__dtorMFZv
>> --- errorlevel 1
>>
>> ====
>> Without -debug or with 'debug' _in_ the DTor (before writeln) instead before the DTor works fine.
Another question: Is there a way that the DTor is only generated if I compile foo with -debug? So that if I compile and link bar.d and foo.lib, even with -debug, but compiled foo.d without, the DTor is automatically generated? Hope that is not to weird. :D
|
October 13, 2013 Re: Linker error: Symbol Undefined | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Friday, 11 October 2013 at 22:33:31 UTC, Namespace wrote:
> On Friday, 11 October 2013 at 21:16:38 UTC, Brad Roberts wrote:
>> It's due to having the destructor versioned out when building foo and visible when building bar. When brought together, you've created an incompatible whole. There's no destructor actually included in foo's .o file that you told it it could expect to find.
>>
>> There's no bug in the compiler or linker, just your usage of mis-matched code.
>>
>> On 10/11/13 11:39 AM, Namespace wrote:
>>> Hey, I'm curious about this linker error:
>>>
>>> OPTLINK (R) for Win32 Release 8.00.13
>>> Copyright (C) Digital Mars 1989-2010 All rights reserved.
>>> http://www.digitalmars.com/ctg/optlink.html
>>> bar.obj(bar)
>>> Error 42: Symbol Undefined _D3foo1A6__dtorMFZv
>>> --- errorlevel 1
>>>
>>> foo.d:
>>> ----
>>> debug import std.stdio;
>>>
>>> struct A {
>>> public:
>>> int id;
>>>
>>> this(int id) {
>>> debug writeln("CTor A with ", id);
>>>
>>> this.id = id;
>>> }
>>>
>>> debug ~this() {
>>> writeln("DTor A with ", id);
>>> }
>>> }
>>> ----
>>>
>>> bar.d
>>> ----
>>> import foo;
>>>
>>> void test(A a) {
>>> a.id++;
>>> }
>>>
>>> void main() {
>>> test(A(42));
>>> A a = A(23);
>>> test(a);
>>> }
>>> ----
>>>
>>> Usage:
>>>
>>> C:\Users\Besitzer\Desktop>dmd -lib foo.d
>>>
>>> C:\Users\Besitzer\Desktop>dmd bar.d foo.lib -debug
>>> OPTLINK (R) for Win32 Release 8.00.13
>>> Copyright (C) Digital Mars 1989-2010 All rights reserved.
>>> http://www.digitalmars.com/ctg/optlink.html
>>> bar.obj(bar)
>>> Error 42: Symbol Undefined _D3foo1A6__dtorMFZv
>>> --- errorlevel 1
>>>
>>> ====
>>> Without -debug or with 'debug' _in_ the DTor (before writeln) instead before the DTor works fine.
>
> Another question: Is there a way that the DTor is only generated if I compile foo with -debug? So that if I compile and link bar.d and foo.lib, even with -debug, but compiled foo.d without, the DTor is automatically generated? Hope that is not to weird. :D
No, you can't. However, you can use other version condition instead to avoid debug code.
foo.d:
----
version(TrackDTor){
import std.stdio;
}
struct A {
public:
int id;
this(int id) {
debug writeln("CTor A with ", id);
this.id = id;
}
version(TrackDTor){
~this() {
writeln("DTor A with ", id);
}
}
}
then compile foo.d with -version=TrackDTor
|
Copyright © 1999-2021 by the D Language Foundation