I'm getting this error:
Ld /Users/liam_baron/Library/Developer/Xcode/DerivedData/Genetics_2-gplfrpbisvmichdvymcavjcyqveh/Build/Products/Debug/Genetics_2 normal x86_64
cd /Users/liam_baron/Documents/Xcode/Genetics_2
export MACOSX_DEPLOYMENT_TARGET=10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/Users/liam_baron/Library/Developer/Xcode/DerivedData/Genetics_2-gplfrpbisvmichdvymcavjcyqveh/Build/Products/Debug -F/Users/liam_baron/Library/Developer/Xcode/DerivedData/Genetics_2-gplfrpbisvmichdvymcavjcyqveh/Build/Products/Debug -filelist /Users/liam_baron/Library/Developer/Xcode/DerivedData/Genetics_2-gplfrpbisvmichdvymcavjcyqveh/Build/Intermediates/Genetics_2.build/Debug/Genetics_2.build/Objects-normal/x86_64/Genetics_2.LinkFileList -mmacosx-version-min=10.9 -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/liam_baron/Library/Developer/Xcode/DerivedData/Genetics_2-gplfrpbisvmichdvymcavjcyqveh/Build/Intermediates/Genetics_2.build/Debug/Genetics_2.build/Objects-normal/x86_64/Genetics_2_dependency_info.dat -o /Users/liam_baron/Library/Developer/Xcode/DerivedData/Genetics_2-gplfrpbisvmichdvymcavjcyqveh/Build/Products/Debug/Genetics_2
duplicate symbol __Z12calcAllCostsRNSt3__16vectorI10chromosomeNS_9allocatorIS1_EEEE in:
/Users/liam_baron/Library/Developer/Xcode/DerivedData/Genetics_2-gplfrpbisvmichdvymcavjcyqveh/Build/Intermediates/Genetics_2.build/Debug/Genetics_2.build/Objects-normal/x86_64/chromosome.o
/Users/liam_baron/Library/Developer/Xcode/DerivedData/Genetics_2-gplfrpbisvmichdvymcavjcyqveh/Build/Intermediates/Genetics_2.build/Debug/Genetics_2.build/Objects-normal/x86_64/main.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is all the code:
main.cpp
int main(){
std::vector <chromosome> cromo(NPOP);
calcAllCosts(cromo); //calculate costs for all chromosomes
return 0;
}
functions.h
#ifndef Genetics_2_functions_h
#define Genetics_2_functions_h
#include "chromosome.h"
#include "defines.h"
void calcAllCosts(std::vector <chromosome>& cromo){
for (auto& i : cromo){
i.costFunc();
}
}
#endif
chromosome.cpp
#include <random>
#include <vector>
#include "chromosome.h"
#include "defines.h"
#include "functions.h"
#include <random>
#include <math.h>
void chromosome::costFunc(){
cost = 3*cos(variables.at(0)) + 1.2*sin(variables.at(1)) / 2*tan(variables.at(2) - 3*cos(variables.at(3)));
}
chromosome.h
#ifndef __Genetics_2__chromosome__
#define __Genetics_2__chromosome__
#include <iostream>
#include <vector>
#include "defines.h"
class chromosome{
private:
std::vector <float> variables;
float cost;
public:
void costFunc(); //calculate cost to be minimised
};
#endif /* defined(__Genetics_2__chromosome__) */
defines.h
#ifndef Genetics_2_defines_h
#define Genetics_2_defines_h
#define NVAR 4
#define NPOP 8
#define LOWLIMIT -5
#define UPLIMIT 5
#define NITER 10
#endif
I've been stuck n this for days, and I can't seem to translate the error message into anything useful. Obviously my program contains a lot more code than this, but this is all that is needed to reproduce the error. This is why there are a lot more includes than needed.
If there were any problems with syntax or anything, these error messages would be present instead of this difficult one, so I believe there isn't anything obviously wrong (that someone with my lack of knowledge could fix).
I have tried looking for people with the same issue, but there seems to be a massive variation in possible fixes. Any help at all would be appreciated.
Thanks a lot in advance.
edit: This has been marked as duplicate with a question on templates. Please clarify.