So, this is problem a stupid mistake, but I've been hacking away at it for about an hour and can't seem to solve it.
I have a class main.cpp which is full of random GUI crap (not really relevant to my problem I believe) but in one of my methods I make a reference to another one of my classes "TiffSpec"
TiffSpec is a class I wrote and so far have no compile errors in it. The compile error I get is:
"undefined reference to TiffSpec::TiffSpec(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
"
Note: I don't believe this is a problem with the string class as I tried to write a default constructor and reference it and still got the same error without the "std::basic_..." stuff.
TiffSpec.h, TiffSpec.cpp and main.cpp are all in the same directory.
Here is the code in main.cpp up until the error:
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctype.h>
#include <vector>
#include <list>
#include <typeinfo>
#include <math.h>
#include "TiffSpec.h"
/* Create checkerboard image */
#define checkImageWidth 1024
#define checkImageHeight 1024
GLubyte checkImage[checkImageHeight][checkImageWidth][3];
static GLint height;
//list of all non-main methods
void init(void);
void display(void);
void reshape(int w, int h);
void motion(int x, int y);
void read_next_command(unsigned char key, int x, int y);
void makeCheckImage(void);
void main_loop(char line[]);
void evaluateLine(char line[], std::vector<char> delimiters);
void evaluateCommand(std::list<std::string> command);
void read(std::list<std::string> command);
void draw(std::list<std::string> command);
void color(std::list<std::string> command);
void move(std::list<std::string> command);
void TiffStat(std::string fileName);
std::string convertInputToFloating(std::string input);
std::string trimExtraZeros(std::string input);
std::vector<char> getDelimiters();
//end of list
void
TiffStat(std::string fileName)
{
TiffSpec * testing = new TiffSpec(fileName);
}
Here is the beginning of the code in TiffSpec.h:
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctype.h>
#include <vector>
#include <list>
#include <typeinfo>
#include <math.h>
#include <exception>
#ifndef TIFFSPEC_H_
#define TIFFSPEC_H_
using namespace std;
class TiffSpec {
public:
TiffSpec();
TiffSpec(std::string filename);
And for good measure, here is some code from TiffSpec.cpp
#include "TiffSpec.h"
#include <algorithm>
bool isLittleEndian();
void ByteSwap_(unsigned char * b, int n);
bool tagRecognized(unsigned short tag);
bool fieldTypeRecognized(unsigned short fieldType);
void gatherValues(IFDEntry & entry, ifstream &fileStream);
valueTypes retrieveCorrectType(unsigned short fieldType, unsigned long numberOfValues);
int getFieldByteSize(short fieldType);
TiffSpec::TiffSpec()
{}
TiffSpec::TiffSpec(std::string fileName)
{
std::ifstream fileStream;
Any idea what my problem might be? Also, is there any more effiecient way to signify a coding block rather than writing 4 spaces before every line? Looked in the reference guide and didn't see anything...
Okay I think I have an idea of what is going wrong. I'm using eclipse for the first time (in c++ at least) and have been pampered by MSVS in some ways. One of those ways being the make file. I think the problem is my makefile.
The makefile was supplied to me. I think I need to make a reference to these new classes, but where? And do I need to do it for both the .h and .cpp files?
makefile:
SHELL = /bin/sh
prefix = /usr
CC = gcc
C++ = g++
GLUT_LIBS = $(prefix)/lib/libglut.so.3
X_LIBADD = -lXmu -lXext -lXi -lX11
INCLUDES = -Iinclude -I$(prefix)/include
LDADD = $(GLUT_LIBS) $(prefix)/lib/libGLU.so.1 $(prefix)/lib/libGL.so.1 -lm
CFLAGS = -g -O2 -Wall -fomit-frame-pointer -ffast-math -fexpensive-optimizations-D_REENTRANT
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@
.SUFFIXES:
.SUFFIXES: .cpp .c .o
.c.o:
$(COMPILE) -c $<
.cpp.o:
$(C++) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $<
all: main
CLI_OBJECTS=main.o
main: $(CLI_OBJECTS)
$(LINK) $(CLI_OBJECTS) $(LDADD) $(LIBS)
clean:
-rm -f *.o $(PROGRAMS)
I believe it has something to do with only main.o being there. But what I exactly need to write to correct it is unknown to me.