I have 4 separate functions in 4 different files. The functions look like this:
SieveOfEratosthenes.cpp
bool SieveOfEratosthenes(int n) {
//
}
They all have no includes. In my main.cpp program I have
//Includes
void compare(bool (*f)(int)) {
//
}
int main(int argc, char **argv) {
compare(isPrimeAKS);
compare(isPrimeModulo);
compare(isPrimeSQRT);
compare(SieveOfEratosthenes);
return 0;
}
This is my makefile:
all: main clean
main: main.cpp lib.so
g++ -o main main.cpp -L.
lib.so: EratosthenesSieve.o AKS.o ModuloAlg.o SQRTModuloAlg.o
g++ -shared -o lib.so AKS.o ModuloAlg.o SQRTModuloAlg.o EratosthenesSieve.o
EratosthenesSieve.o: EratosthenesSieve.cpp
g++ -c -Wall -fpic EratosthenesSieve.cpp
AKS.o: AKS.cpp
g++ -c -Wall -fpic AKS.cpp
ModuloAlg.o: ModuloAlg.cpp
g++ -c -Wall -fpic ModuloAlg.cpp
SQRTModuloAlg.o: ModuloAlg.cpp
g++ -c -Wall -fpic SQRTModuloAlg.cpp
clean:
rm -f *.o
Compiling errors at main(after building the shared library lib.so) with errors like:
‘isPrimeAKS’ was not declared in this scope.
I don't understand why, since they all are in the library provided to the compiler.
EDIT if you have the same problem: After declaring in a header the problem becomes
undefined reference to `isPrimeAKS(int)' see the accepted answer why.