Intel® oneAPI Data Analytics Library
Learn from community members on how to build compute-intensive applications that run efficiently on Intel® architecture.
226 Discussions

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

Graham_M_
Beginner
715 Views

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
Graham_M_
Beginner
715 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
Ilya_B_Intel
Employee
715 Views

Thanks, Graham!

We fixed that in internal code base.

0 Kudos
Alvin_S_
Beginner
715 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
Andrey_N_Intel
Employee
715 Views

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

0 Kudos
Reply