I have a 3 source files. The main file has a function that use if
statements to define a pointer:
main(int dispersalfn) {
if(dispersalfn == 0) {
kernel1 = flatdisp;
} else if(dispersalfn == 1) {
kernel1 = expdisp;
}
[...more stuff...]
}
In main.h
I have a definition for kernel1
:
arma::vec (*kernel1)(arma::vec d, arma::vec m);
In disp.cpp
I have definitions for flapdisp
and expdisp
:
arma::vec flatdisp(arma::vec d, arma::vec m) {
return m;
}
arma::vec expdisp(arma::vec d, arma::vec m) {
return (square(m) / (2*M_PI)) % exp(-m % d);
}
disp.h
has corresponding definitions for flatdisp
and expdisp
:
arma::vec flatdisp(arma::vec d, arma::vec m);
arma::vec expdisp(arma::vec d, arma::vec m);
Finally upfun.cpp
has a number of functions that call kernel1
. The functions in upfun
are called by main()
.
When I compile, I get an error:
duplicate symbol _kernel in upfun.o and main.o for architecture x86_64
All my header files source each other have include guards, so I don't think that's it. The idea is that when I call main()
, I include variables to choose which function is used for kernel1
. This worked until I broke up my functions into different files. What causes this error?