tags:

views:

569

answers:

3

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.

+4  A: 

Make sure you are linking TiffSpec.cpp into your project. How to do this depends on your development environment.

For GCC, make sure you add TiffSpec.o to your linker (and compile TiffSpec.cpp into TiffSpec.o, of course).

For MSVC, make sure you add TiffSpec.cpp to be compiled and linked into your executable. (FIXME)

strager
I'm using eclipse (I'm using Ubuntu for this project)I created the class in the project from the IDE. There are in the same project folder and everything their properties box seems to suggest the are in the same project.Any other way to make sure of this?
Chad
+1  A: 

Make sure that you are linking in TiffSpec.o.

Carlos A. Ibarra
Could you explain this a little more? I think this is the in the right direction. I edited the question.
Chad
+2  A: 

It's the CLI_OBJECTS line that seems to list the object files. Add TiffSpec.o:

CLI_OBJECTS=main.o TiffSpec.o


The linking command comes from this rule in the makefile:

main: $(CLI_OBJECTS)
   $(LINK) $(CLI_OBJECTS) $(LDADD) $(LIBS)

This says that main should be built from the files listed in CLI_OBJECTS by running the command on the line below.

CAdaker