So I have been struggling to get my code to compile over the last few hours and I can not understand where I am going wrong.
This is my make file:
This is the output:
g++ -c LPfilter.cpp -o LPfilter.o -g
g++ -c EKSmoother.cpp -o EKSmoother.o -g
g++ -c ECGFitter.cpp -o ECGFitter.o -g
g++ -c KalmanFiltering.cpp -o KalmanFiltering.o -g
g++ -c helper.cpp -o helper.o -g
g++ -c math.cpp -o math.o -g
g++ -o kalmanFiltering LPfilter.o EKSmoother.o ECGFitter.o KalmanFiltering.o helper.o math.o -lm -larmadillo -L. -lmpfit
EKSmoother.o: In function `EKSmoother':
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/EKSmoother.cpp:30: undefined reference to `double Math::calculateMean<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/EKSmoother.cpp:31: undefined reference to `double Math::sd2<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/EKSmoother.cpp:39: undefined reference to `double Math::findAbsMax<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/EKSmoother.cpp:51: undefined reference to `double Math::calculateMean<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/EKSmoother.cpp:58: undefined reference to `double Math::calculateMean<double>(std::vector<double, std::allocator<double> >)'
ECGFitter.o: In function `ECGFitter':
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:19: undefined reference to `double Math::calculateMeanSqrt<double>(std::vector<double, std::allocator<double> >)'
ECGFitter.o: In function `SignalFitter::ECGFitter::peakDetection(double)':
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:60: undefined reference to `double Math::getMaxStd<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:60: undefined reference to `double Math::getMinStd<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:83: undefined reference to `bool Math::compare<double>(double, double)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:106: undefined reference to `bool Math::compare<double>(double, double)'
ECGFitter.o: In function `SignalFitter::ECGFitter::phaseCalculation()':
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:140: undefined reference to `int Math::sumStd<int>(std::vector<int, std::allocator<int> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:173: undefined reference to `bool Math::GT<double>(double, double)'
ECGFitter.o: In function `SignalFitter::ECGFitter::meanECGExtraction(bool)':
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:195: undefined reference to `bool Math::GTE<double>(double, double)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:195: undefined reference to `bool Math::LT<double>(double, double)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:204: undefined reference to `double Math::calculateMean<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:205: undefined reference to `double Math::sd<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:215: undefined reference to `bool Math::GTE<double>(double, double)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:215: undefined reference to `bool Math::LT<double>(double, double)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:226: undefined reference to `double Math::calculateMean<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:227: undefined reference to `double Math::calculateMean<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:228: undefined reference to `double Math::sd<double>(std::vector<double, std::allocator<double> >)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:264: undefined reference to `double Math::calculateMean<double>(std::vector<double, std::allocator<double> >)'
ECGFitter.o: In function `SignalFitter::ECGFitter::findIndicies(std::vector<double, std::allocator<double> >)':
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/ECGFitter.cpp:355: undefined reference to `bool Math::compare<double>(double, double)'
KalmanFiltering.o: In function `main':
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/KalmanFiltering.cpp:37: undefined reference to `Helper::readDataFile(char const*)'
/home/ryan/Documents/Research_Work/SimpleHealth/KalmanFilter/KalmanFilter_C++/test/cmpfit-1.2/KalmanFiltering.cpp:40: undefined reference to `Helper::readDataFile(char const*)'
collect2: ld returned 1 exit status
make: *** [kalmanFiltering] Error 1
My make file is:
CC = g++
LDFLAGS = -lfltk
CFLAGS = -g $(OPT)
OPT =
LIBS = -lm -larmadillo -L. -lmpfit
SRCS = LPfilter.cpp EKSmoother.cpp ECGFitter.cpp KalmanFiltering.cpp helper.cpp math.cpp
OBJS =$(SRCS:.cpp=.o)
DEPS =
MAIN = kalmanFiltering
all: $(MAIN)
@echo ------ $(MAIN) has been compiled ------
.cpp.o:
$(CC) -c $< -o $@ $(CFLAGS)
$(MAIN): $(OBJS)
$(CC) -o $@ $^ $(LIBS)
.PHONY: clean cleanest
clean:
rm *.o
cleanest: clean
rm octhecdec
Basically my math.cpp
and helper.cpp
files contain some functions that are used in ECGFitter.cpp
, ECGSmoother.cpp
and KalmanFiltering.cpp
. I understand that you need only to include the .hpp file for the assembler to produce your .o file and then you need to link the .o file of the corresponding source code before you run the linker. I thought I was doing this just fine but clearly I am not.
Thanks for the help!
PS:
math.hpp
#ifndef MATH
#define MATH
#include <cmath>
#include <vector>
#define EPSILON 0.0000001
#define templateT template<typename T>
const double PI = 3.141592653589793;
namespace Math {
templateT T calculateMeanSqrt(const std::vector<T>);
templateT T calculateMean(const std::vector<T>);
templateT T sd(std::vector<T>);
templateT T sd2(std::vector<T>);
templateT T getMaxStd(std::vector<T>);
templateT T getMinStd(std::vector<T>);
templateT T sumStd(std::vector<T>);
templateT bool compare(T, T);
templateT bool GTE(T, T);
templateT bool LTE(T, T);
templateT bool GT(T, T);
templateT bool LT(T, T);
templateT T findAbsMax(std::vector<T>);
}
#endif
helper.hpp:
#ifndef HELPER
#define HELPER
#include <iostream>
#include <vector>
#include <cmath>
#define __DEBUGG
#ifdef __DEBUGG
#include <algorithm> // only used to display vector
#endif
#define EPSILON 0.0000001
namespace Helper {
template<typename T> void displayVector(const std::vector<T>);
std::vector<double> readDataFile(const char*);
}
#endif