FastFilter / xor_singleheader

Header-only binary fuse and xor filter library
Apache License 2.0
348 stars 32 forks source link

multiple definition #44

Closed boulevard-h closed 2 years ago

boulevard-h commented 2 years ago

I have 2 c++ files, which both include the binaryfusefilter.h header. And they are compiled by cmake together. when I compile my project, there are errors like:

/usr/bin/ld: ../lib/libPSI.a(PsiSender.cpp.o): in function `binary_fuse_mulhi(unsigned long, unsigned long)':
PsiSender.cpp:(.text._Z17binary_fuse_mulhimm+0x0): multiple definition of `binary_fuse_mulhi(unsigned long, unsigned long)'; ../lib/libPSI.a(PsiReceiver.cpp.o):PsiReceiver.cpp:(.text._Z17binary_fuse_mulhimm+0x0): first defined here
/usr/bin/ld: ../lib/libPSI.a(PsiSender.cpp.o): in function `binary_fuse_max(double, double)':
PsiSender.cpp:(.text._Z15binary_fuse_maxdd+0x0): multiple definition of `binary_fuse_max(double, double)'; ../lib/libPSI.a(PsiReceiver.cpp.o):PsiReceiver.cpp:(.text._Z15binary_fuse_maxdd+0x0): first defined here
/usr/bin/ld: ../lib/libPSI.a(PsiSender.cpp.o): in function `binary_fuse8_populate(unsigned long const*, unsigned int, binary_fuse8_s*)':
PsiSender.cpp:(.text._Z21binary_fuse8_populatePKmjP14binary_fuse8_s+0x0): multiple definition of `binary_fuse8_populate(unsigned long const*, unsigned int, binary_fuse8_s*)'; ../lib/libPSI.a(PsiReceiver.cpp.o):PsiReceiver.cpp:(.text._Z21binary_fuse8_populatePKmjP14binary_fuse8_s+0x0): first defined here
/usr/bin/ld: ../lib/libPSI.a(PsiSender.cpp.o): in function `binary_fuse16_populate(unsigned long const*, unsigned int, binary_fuse16_s*)':
PsiSender.cpp:(.text._Z22binary_fuse16_populatePKmjP15binary_fuse16_s+0x0): multiple definition of `binary_fuse16_populate(unsigned long const*, unsigned int, binary_fuse16_s*)'; ../lib/libPSI.a(PsiReceiver.cpp.o):PsiReceiver.cpp:(.text._Z22binary_fuse16_populatePKmjP15binary_fuse16_s+0x0): first defined here
collect2: error: ld returned 1 exit status

I know when 2 files include a same header, this may happen. But I looked at binaryfusefilter.h, there is defines like:

#ifndef BINARYFUSEFILTER_H
#define BINARYFUSEFILTER_H

So why does this error still happen? How can I avoid it?

boulevard-h commented 2 years ago

Also, I tried to define my filter as a static variety in my 2 files.

static binary_fuse8_t MyBFF;

However, error still happens.

lemire commented 2 years ago

Thanks for the report. I will update the code. These functions should be declared inline.

lemire commented 2 years ago

Please pull the latest version, it should solve your issue. If not, open a new issue.

Thanks for the report.