I keep getting the error "In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status". Something is wrong and I am clueless as to what the problem is. In Xcode it says "linker command failed with exit code 1 (use -v to see invocation)" and that there is a duplicate symbol color and a duplicate symbol print_iii(im guessing the print function). Its kinda frustrating. Really need some help. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//My .h file
#ifndef COLOR_H
#define COLOR_H
class Color {
public:
int red;
int green;
int blue;
inlinevoid setRed(int red);
inlinevoid setGreen(int green);
inlinevoid setBlue(int blue);
inlineint getRed();
inlineint getGreen();
inlineint getBlue();
};
#endif
So I solved it by placing print() inline and by making the variables in the class functions in class reference variables. however in g++ im still having problems. It keeps saying
/usr/lib/gcc/x86_64-redhat-linux/4.6.1/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
What does it mean by undefined ref in main. This works in xcode but in g++ it doesn't. Any ideas?
void print(int red, int blue, int green) should be replaced by void print(Color color) in both cpp and h files, and in main use print(color). Alternatively, define print as a function in the Color class, and call it from the main as color.print().
Otherwise your print function does not use red, green, or blue, and instead tries to deal with the global object color
Also, make sure you are linking all the files in g++
I solved it. I was linking it right but in inline functions I was supposed to define them in the class so it was giving me errors. With a few other tweaks here and there and it is now running properly.