Why am I getting an “Undefined reference” error when I run my Makefile on some computers, but not others?

1.8k views Asked by At

I am doing some research on parallel processing and need to test counter output with different parallel-ization APIs. Every time I try to make my code, I get undefined reference to 'PAPI_....

I am using PAPI 5.1.1 and already know which directories libpapi.a and papi.h are in. I had no issues running this Makefile on another PC but on the other one I need, it doesn't seem to be working. Here's what I have

CC=g++
CFLAGS="-fopenmp"
LIB=/usr/local/lib/libpapi.a -lm -lpthread
INCLUDE=-I/usr/local/include

all: test
     echo "Done"
test: testPandP.cpp
     ${CC} ${CFLAGS} ${LIB} ${INCLUDE} -o test testPandP.cpp
clean:
     ${RM} *.o test

I have read other posts asking about the undefined reference but, every one I've seen just suggested to use -L/usr/local/lib or /usr/local/lib/libpapi.a, which I'm already doing.

Does anybody have any other suggestions?

1

There are 1 answers

0
RSFalcon7 On

Depending on the version of your linker, the order of the libs might give you trouble. This is probably why you can compile in some machines but not in others.

Changing the order of the compilation should do it:

test: testPandP.cpp
     ${CC} ${CFLAGS} ${INCLUDE} -o test testPandP.cpp ${LIB}

Further information in this question about linking order.