954,242 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Makefile Error: undefined reference to...

Hi all,

I have been trying to compile some c++ using GNU make. This involves linking with a third party library and it is this that seems to have caused the problem. The error message tells me that there are undefined references in my program to one of my own classes (RandNos) and its member functions. My suspicions are, that this problem arises during the linking stage, even though the error seems to suggest it does not. I have compiled similar code with make many times before without hitch, the only difference with the current code is the inclusion of the third party library. Please take a look at my make file and the subsequent error messages, which follow. I hope you can help

JFLIB =  /home/network/findlay/jfcpplib/

all:SynSurvey_v2

SynSurvey_v2: SynSurvey_v2.o RandNos.o $(JFLIB)Bisection.o
	g++ -std=c+98  -I/usr/include SynSurvey_v2.o -L/usr/lib -lboost_regex RandNos.o $(JFLIB)Bisection.o SynSurvey_v2

SynSurvey_v2.o: SynSurvey_v2.cpp	
	g++ -std=c++98 -I/usr/include SynSurvey_v2.cpp -L/usr/lib -lboost_regex 

RandNos.o: RandNos.cpp RandNos.h
	g++ -c RandNos.cpp

Bisection.o: $(JFLIB)Bisection.cpp $(JFLIB)Bisection.h
	g++ -c $(JFLIB)Bisection.cpp

clean:
	rm -f SynSurvey_v2 SynSurvey_v2.o RandNos.o $(JFLIB)Bisection.o
/tmp/ccFiW4Do.o: In function `main':
SynSurvey_v2.cpp:(.text+0x10ea): undefined reference to `RandNos::RandNos(int)'
SynSurvey_v2.cpp:(.text+0x10f8): undefined reference to `RandNos::generate()'
SynSurvey_v2.cpp:(.text+0x1109): undefined reference to `RandNos::get_err()'
collect2: ld returned 1 exit status
make: *** [SynSurvey_v2.o] Error 1
findlay
Newbie Poster
10 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

No Worries, problem solved:

JFLIB =  /home/network/findlay/jfcpplib/

all:SynSurvey_v2

SynSurvey_v2:  SynSurvey_v2.o RandNos.o $(JFLIB)Bisection.o
	g++ -std=c++98 -I/usr/include/ SynSurvey_v2.o  -L /usr/lib -lboost_regex RandNos.o $(JFLIB)Bisection.o -o SynSurvey_v2

SynSurvey_v2.o:SynSurvey_v2.cpp
	g++ -c SynSurvey_v2.cpp

RandNos.o: RandNos.cpp RandNos.h
	g++ -c RandNos.cpp

Bisection.o: $(JFLIB)Bisection.cpp $(JFLIB)Bisection.h
	g++ -c $(JFLIB)Bisection.cpp

clean:
	rm -f SynSurvey_v2 SynSurvey_v2.o RandNos.o $(JFLIB)Bisection.o


Seems to work now, thought i'd tried this but obsv not.

findlay
Newbie Poster
10 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

well done, best to mark your thread as solved if it is.

sillyboy
Practically a Master Poster
686 posts since Mar 2007
Reputation Points: 85
Solved Threads: 64
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: