Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Link time: multiple definitions

Moderators: kris

Posted: 07/25/08 13:49:59

Hello, I'm using last (SVN) Tango checkout.

I have a project with multiple files, the main called MyProj?.d, importing the module of VectorPath?.d, this last file imports tango.text.xml.Document, when linking, I obtain :

dsss_objs/D/_VectorPath.o:(.rodata+0x860): multiple definition of `_D5tango4text3xml8Document15T8DocumentTaZ8Document7Visitor6initZ' dsss_objs/D/_MyProj.o:(.rodata+0x1868): first defined here dsss_objs/D/_VectorPath.o:(.rodata+0x870): multiple definition of `_D5tango4text3xml8Document15T8DocumentTaZ8Document8NodeImpl6initZ' dsss_objs/D/_MyProj.o:(.rodata+0x1870): first defined here dsss_objs/D/_VectorPath.o:(.rodata+0x8b8): multiple definition of `_D5tango4text3xml8Document14T7XmlPathTaZ7XmlPath7NodeSet6initZ' dsss_objs/D/_MyProj.o:(.rodata+0x18b8): first defined here collect2: ld returned 1 exit status --- errorlevel 1

tango.text.xml.Document is not imported in MyProj?.d (though it does not change anything if I import it there). My imports are set to private in all files.

If I remove the code using Document (but not necessarily the import statement) and I put this code in the file MyProj?.d (and add the corresponding import statement) it compiles fine.

Someone has a clue ?

My dsss.conf file looks like this : [src/MyProj.d] type = binary target = myProj

+ some imports and flags, etc

Author Message

Posted: 08/25/08 17:06:57

Hi, I’m running into the same problem with the latest Tango version

I do have an example with three files that produces the same result with dmd on Linux

1. init.d 2. xml_1.d 3. xml_2.d

/* ==================================

File init.d

*/ ==================================

module init;

import xml_1; import xml_2;

void main () {

new xml_1(); new xml_2();

}

/* ==================================

File xml_1.d

*/ ================================== module xml_1;

private import tango.text.xml.Document,

tango.text.xml.DocPrinter?;

class xml_1 {

this () {

auto doc = new Document!(char);

}

}

/* ==================================

File xml_2.d

*/ ==================================

module xml_2;

private import tango.text.xml.Document,

tango.text.xml.DocPrinter?;

class xml_2 {

this () {

auto doc = new Document!(char);

}

}

OUTPUT:

init.d => init + /usr/local/dmd/bin/rebuild -Idsss_imports/ -I. -S./ -I/usr/local/dmd/include/d -S/usr/local/dmd/lib/ -I/usr/local/dmd/include/d -S/usr/local/dmd/lib -I/root/d/include/d -S/root/d/lib -oqdsss_objs/D -debug -g init.d -ofinit dsss_objs/D/_xml_2.o: In function `_D5tango4text3xml8Document15T8DocumentTaZ8Document8NodeImpl4nameMFAaZAa': /usr/local/dmd/bin/../import/tango/text/xml/Document.d:991: multiple definition of `_D5tango4text3xml8Document15T8DocumentTaZ8Document7Visitor6initZ' dsss_objs/D/_xml_1.o:/usr/local/dmd/bin/../import/tango/text/xml/Document.d:991: first defined here dsss_objs/D/_xml_2.o: In function `_D5tango4text3xml8Document15T8DocumentTaZ8Document8NodeImpl4nameMFAaZAa': /usr/local/dmd/bin/../import/tango/text/xml/Document.d:1002: multiple definition of `_D5tango4text3xml8Document15T8DocumentTaZ8Document8NodeImpl6initZ' dsss_objs/D/_xml_1.o:/usr/local/dmd/bin/../import/tango/text/xml/Document.d:1002: first defined here dsss_objs/D/_xml_2.o: In function `_D5tango4text3xml8Document15T8DocumentTaZ8Document8NodeImpl6removeMFZPS5tango4text3xml8Document15T8DocumentTaZ8Document8NodeImpl': /usr/local/dmd/bin/../import/tango/text/xml/PullParser.d:303: multiple definition of `_D5tango4text3xml8Document14T7XmlPathTaZ7XmlPath7NodeSet6initZ' dsss_objs/D/_xml_1.o:/usr/local/dmd/bin/../import/tango/text/xml/PullParser.d:303: first defined here collect2: ld returned 1 exit status --- errorlevel 1

Thanks for any support on this issue.

Posted: 08/25/08 19:37:30

This is definately not a common error - and when it shows up, it tends to mean what it says. So for some reason, you have multiple objects defining these particular symbols in the libraries and/or object files linked into your application.

A wild guess would be that you have a Tango library installed (libtango), in addition to dsss libraries. These would be likely to cause issues even if you don't actually use the symbols you get errors about.

Posted: 08/25/08 21:48:31

Actually what do you mean by "Tango library installed (libtango), in addition to dsss libraries". The import folder just contains the usual tango source files and the lib folder contains:

drwxr-xr-x 2 root root 4096 Aug 25 23:14 .
drwxr-xr-x 11 root root 4096 May 24 14:20 ..
-rw-r--r-- 1 root root 481368 Aug 25 16:53 libDD-mango-icu.a
-rw-r--r-- 1 root root 975334 Aug 25 16:53 libDD-mango-net.a
-rw-r--r-- 1 root root 292858 Aug 25 16:53 libDD-mango-xml.a
-rw-r--r-- 1 root root 622806 Aug 25 19:31 libtango-base-dmd.a
-rw-r--r-- 1 root root 7352702 Aug 25 19:32 libtango-user-dmd.a

the include folder just contains source files. all other libraries are working fine even in the example above. we've been following this tutorials while installing DMD and tango: http://www.lars-kirchhoff.de/go/journal/comments/a-kickstart-with-d/

I found a solution based on class inheritance. This example actually works out(in addition to the post above):

// file xml_abstract.d
public import tango.text.xml.Document;

class xml_abstract
{

public Document!(char) XMLDocument()
{

return new Document!(char);

}

}

// file xml_1.d
private import xml_abstract;

class xml_1 : xml_abstract {

this () {

auto doc = XMLDocument;

}

}

// file xml_2.d

private import xml_abstract;

class xml_2 : xml_abstract {

this () {

auto doc = XMLDocument;

}

}

Posted: 09/03/08 14:03:31

tomni wrote:

Actually what do you mean by "Tango library installed (libtango), in addition to dsss libraries". The import folder just contains the usual tango source files and the lib folder contains:

drwxr-xr-x 2 root root 4096 Aug 25 23:14 .
drwxr-xr-x 11 root root 4096 May 24 14:20 ..
-rw-r--r-- 1 root root 481368 Aug 25 16:53 libDD-mango-icu.a
-rw-r--r-- 1 root root 975334 Aug 25 16:53 libDD-mango-net.a
-rw-r--r-- 1 root root 292858 Aug 25 16:53 libDD-mango-xml.a
-rw-r--r-- 1 root root 622806 Aug 25 19:31 libtango-base-dmd.a
-rw-r--r-- 1 root root 7352702 Aug 25 19:32 libtango-user-dmd.a

What lars meant is that you may be linking libtango-user-dmd.a into your build as well as dsss linking in objects it has compiled from the tango modules (dsss_objs/...). You don't need to link in libtango-user-dmd if you use dsss.