Intel® oneAPI Data Analytics Library
Community support for building compute-intensive applications that run fast on Intel® architecture.
Announcements
The Intel sign-in experience is changing in February to support enhanced security controls. If you sign in, click here for more information.
213 Discussions

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

Graham_M_
Beginner
429 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
429 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;
}

 

Ilya_B_Intel
Employee
429 Views

Thanks, Graham!

We fixed that in internal code base.

Alvin_S_
Beginner
429 Views

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

Has "return;" two lines in a row.

Regards,

ACS
 

Andrey_N_Intel
Employee
429 Views

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

Reply