jeudi 20 octobre 2022

Undefined reference to `FastPForLib:..' while linking FastPForlib

Any suggestion regarding the following query would be appreciated. I have tried everything and am still struck with this error. The library (FastPFor) works fine with the visual studio solution; the issue arises when I try to use it with my project containing the file (src/example.cpp).

I am trying to link the static library (lib/FastPFor/libFastPFOR.a) to my example.cpp. I have copied the header files in the (include/FastPFor/*h) while I obtained FastPForlib.a by running the CMake command followed by make, on Ubuntu run via WSL.

Following is my dependency-tree

example (proj)
include
------------>FastPFor
--------------------->*h
lib
------------>FastPFor
--------------------->liblibFastPFor.a
src
------------>example.src
Makefile

Following is my makefile:

.SUFFIXES:
#
.SUFFIXES: .cpp .o .c .h
LDFLAGS = -Llib/FastPFor -llibFastPFOR
# replace the CXX variable with a path to a C++11 compatible compiler.
# to build an aligned version, add -DUSE_ALIGNED=1
ifeq ($(INTEL), 1)
# if you wish to use the Intel compiler, please do "make INTEL=1".
    CXX ?= /opt/intel/bin/icpc
    CC ?= /opt/intel/bin/icpc
ifeq ($(DEBUG),1)
    CXXFLAGS = -fpic -std=c++11 -O3 -Wall -ansi -xAVX -DDEBUG=1 -D_GLIBCXX_DEBUG -ggdb 
    CCFLAGS = -fpic -std=c99 -O3 -Wall  -ansi -xAVX -DDEBUG=1 -D_GLIBCXX_DEBUG -ggdb 
else
    CXXFLAGS = -fpic -std=c++11 -O2 -Wall  -ansi -xAVX -DNDEBUG=1  -ggdb 
    CCFLAGS = -fpic -std=c99 -O2 -Wall   -ansi -xAVX -DNDEBUG=1  -ggdb 
endif # debug
else #intel
    CXX ?= g++-4.7
ifeq ($(DEBUG),1)
    CXXFLAGS = -fpic -mavx -std=c++11  -Weffc++ -pedantic -ggdb -DDEBUG=1 -D_GLIBCXX_DEBUG -Wall  -Wextra -Wextra -Wsign-compare  -Wwrite-strings -Wpointer-arith -Winit-self  -Wno-sign-conversion
    CCFLAGS = -fpic -mavx -std=c99  -pedantic -ggdb -DDEBUG=1 -D_GLIBCXX_DEBUG -Wall  -Wextra -Wsign-compare -Wwrite-strings -Wpointer-arith -Winit-self  -Wno-sign-conversion 
else
    CXXFLAGS = -fpic -mavx -std=c++11  -Weffc++ -pedantic -O3 -Wall  -Wextra -Wsign-compare  -Wwrite-strings -Wpointer-arith -Winit-self  -Wno-sign-conversion 
    CCFLAGS = -fpic -mavx -std=c99 -pedantic -O3 -Wall -Wextra -Wsign-compare -Wwrite-strings -Wpointer-arith -Winit-self -Wno-sign-conversion 
endif #debug
endif #intel


HEADERS= $(shell ls include/FastPFor/*.h)

all: example


example: $(HEADERS) src/example.cpp
    $(CXX) $(CXXFLAGS) -o example $(LDFLAGS) src/example.cpp 

clean:
    rm -f *.o example

astyle:
    astyle --options=astyle.conf --recursive "*.cpp" "*.h"

.PHONY: all clean astyle

Running make produced bunch of errors, all related to undefined reference to FastPFOR. It looks something like following:

/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x781): undefined reference to `__fastunpack11(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x791): undefined reference to `__fastunpack10(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x7a1): undefined reference to `__fastunpack9(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x7b1): undefined reference to `__fastunpack4(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x7c1): undefined reference to `__fastunpack3(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x7d1): undefined reference to `__fastunpack64(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x7e1): undefined reference to `__fastunpack8(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x7f1): undefined reference to `__fastunpack7(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x801): undefined reference to `__fastunpack6(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x811): undefined reference to `__fastunpack5(unsigned int const*, unsigned long*)'
/usr/bin/ld: example.cpp:(.text._ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm[_ZN11FastPForLib12FastPForImplILj8EmE13__decodeArrayEPKjRmPmm]+0x87c): undefined reference to `__fastunpack2(unsigned int const*, unsigned long*)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:36: example] Error 1

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire