Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
50 Views

ODR violation attempting to link more than one object that included daal.h

Hi,

If I create a file, a.cpp:

#include "daal.h"

void f() { return; }

and another file, b.cpp:

#include "daal.h"

void g() { return; }

then when I attempt to compile and link them with:

g++ a.cpp -I/opt/intel/compilers_and_libraries_2016.0.069/linux/daal/include -c -fPIC
g++ b.cpp -I/opt/intel/compilers_and_libraries_2016.0.069/linux/daal/include -c -fPIC
g++ -shared -o ab.so a.o b.o

then the following error is produced:

b.o: In function `void daal::data_management::DataSource::allocateNumericTableImpl<daal::data_management::AOSNumericTable>(daal::data_management::AOSNumericTable**)':
b.cpp:(.text+0x0): multiple definition of `void daal::data_management::DataSource::allocateNumericTableImpl<daal::data_management::AOSNumericTable>(daal::data_management::AOSNumericTable**)'
a.o:a.cpp:(.text+0x0): first defined here
b.o: In function `void daal::data_management::DataSource::allocateNumericTableImpl<daal::data_management::SOANumericTable>(daal::data_management::SOANumericTable**)':
b.cpp:(.text+0xa0): multiple definition of `void daal::data_management::DataSource::allocateNumericTableImpl<daal::data_management::SOANumericTable>(daal::data_management::SOANumericTable**)'
a.o:a.cpp:(.text+0xa0): first defined here
collect2: error: ld returned 1 exit status

Should I expect to be able to include daal.h in more than one source file? If so, is there a way around this error?

For reference, I am using this G++ version:

$ g++ --version
g++ (Debian 4.9.2-10) 4.9.2

Many thanks,
Graham.

0 Kudos
4 Replies
Highlighted
Beginner
50 Views

As a workaround, declaring those two functions in include/data_management/connectors/data_source.h inline suppresses the issue:

template<>
inline void DataSource::allocateNumericTableImpl(AOSNumericTable **nt)
{
    size_t nFeatures = _dict->getNumberOfFeatures();
    size_t structureSize = getStructureSize();
    *nt = new AOSNumericTable(structureSize, nFeatures, 0);
    setNumericTableDictionary(*nt);
}

template<>
inline void DataSource::allocateNumericTableImpl(SOANumericTable **nt)
{
    *nt = 0;
}

 

0 Kudos
Highlighted
Employee
50 Views

Thanks, Graham!

We fixed that in internal code base.

0 Kudos
Highlighted
Beginner
50 Views

Minor cleanup required in soa_numeric_table.h on line 291 in allocateDataMemory().

Has "return;" two lines in a row.

Regards,

ACS
 

0 Kudos
Highlighted
Employee
50 Views

Thank you, Alvin, for the catch! We will remove it. Andrey

0 Kudos