C++ Compilation Include problems

I am having problem building my program. Below is the makefile.

This is the error I get

make -f raytrac.mk raytrac 
g++ -I../../../ -O3  -Wno-non-template-friend -Wno-deprecated -DNDEBUG ../../../libs/main/raytrac_main.cpp -o raytrac
In file included from ../../../tomso/string/string.hpp:2669:0,
                 from ../../../tomso/optparse/parseel.hpp:32,
                 from ../../../tomso/optparse/parsing.hpp:27,
                 from ../../../libs/main/raytrac_main.cpp:185:
../../../tomso/string/impl/string.ipp:39:21: fatal error: vect2.hpp: No such file or directory
compilation terminated.
make: *** [raytrac] Error 1

One of the problem lies in the main program. The following is the include directives in the main program
All header files are organised in the directory tomso.

 > cat Makefile

OPSYS = $(shell uname -s )

TARGET = raytrac

ROOTDIR = ../../..
INCDIR = $(ROOTDIR)/tomso
SRCDIR = $(ROOTDIR)/libs
MAINDIR = $(SRCDIR)/main

OBJDIR = $(ROOTDIR)/tools/release/obj
BINDIR = $(ROOTDIR)/tools/release/bin

# ***************************************************************** #

# C++ compiler
CPP_COMP = g++

# C++ compiler options
CPP_OPTS = -I$(ROOTDIR)/ -O3  -Wno-non-template-friend -Wno-deprecated -DNDEBUG

# ***************************************************************** #

# Directories

LIBINC = $(INCLDIR)/linear_algebra/vector.hpp  \
    $(INCLDIR)/linear_algebra/matrix.hpp   \
    $(INCLDIR)/raytrace/layer.hpp          \
    $(INCLDIR)/raytrace/velmod.hpp

LIBSRC = $(SRCDIR)/vect.cpp                        \
    $(INCLDIR)/linear_algebra/impl/vector.ipp  \
    $(INCLDIR)/linear_algebra/impl/matrix.ipp  \
    $(SRCDIR)/string/sstring.cpp               \
    $(SRCDIR)/raytrace/layer.cpp               \
    $(SRCDIR)/raytrace/layint_linear.cpp       \
    $(SRCDIR)/raytrace/laymod_linear.cpp       \
    $(SRCDIR)/raytrace/velmod.cpp

# ***************************************************************** #

.PHONY : help

# ***************************************************************** #

$(TARGET) : $(MAINDIR)/raytrac_main.cpp
    $(CPP_COMP) $(CPP_OPTS) $(MAINDIR)/raytrac_main.cpp -o raytrac
    -mv $(TARGET) $(BINDIR)

# ***************************************************************** #

help :
    @echo ""
    @echo "USAGE: "
    @echo ""
    @echo "  make -f raytrac.mk         To get this listing"
    @echo "  make -f raytrac.mk help    To get this listing"
    @echo "  make -f raytrac            Builds raytrac"
    @echo "  make -f nraypk.mk list     List details of building raytrac"
    @echo "  make -f nraypk.mk clean    Remove *.o and executable"
    @echo ""

#___________________________________________________________________#


---------- Post updated at 04:58 PM ---------- Previous update was at 02:20 PM ----------

I have separated a template as follows

tomso/linear-algebra/vector.hpp
template declarations

tomso/linear-algebra/impl/vector.ipp
template and inline implementations
libs/linear-algebra/vector.cpp
Remaining implementations

#ifndef VECTOR_HPP
#define VECTOR_HPP

#include <assert.h>
#include <cmath>
#include <iostream>

#include "tomso/numeric/numeric.hpp"

template <class T>
class Vector {

  protected:

    int  Size;  ///< Number of elements of the vector
    T*  X;      ///< Vector container object

  public:
   
    Vector (
    ): Size(0) { }

    Vector (
      const int  n
    );

    Vector (
      const int  n,
      const T  v
    );

  etc ...    

};

#include "tomso/linear_algebra/impl/vector.ipp"

#endif  // VECTOR_HPP

As you see I add the implementation file vector.ipp at the end

My question is whether I neen to put the includes in vector.ipp as well.

> cat vector.ipp

#include <assert.h>
#include <cmath>
#include <iostream>

#include "tomso/numeric/numeric.hpp"

template <class T>
inline Vector<T>::Vector(
  const int  n
) {

  Size = n;
  X = new T;
  for (int i = 0; i < Size; i++) {
    X = 0;
  }

}

etc ...

Wherever that included file with relative path is, there needs to be a -I to the directory above.

If the #include is conditional (#if* ... #include ... #endif), there might be problems with the controlling conditions.

I have now fixed some things

I have a string class in the following format

string.hpp : class definition
string.ipp : all inline functions
string.cpp : all other functions

One problem is where to put MaxDimString, in the hpp, ipp or cpp??

> cat string.hpp

#ifndef STRING_HPP
#define STRING_HPP

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "tomso/linear_algebra/vect2.hpp"
#include "tomso/linear_algebra/vector.hpp"
#include "tomso/graph/graph.hpp"
#include "tomso/graph/list.hpp"
#include "tomso/graph/stack.hpp"
#include "tomso/graph/tree.hpp"

const int  MaxDimString = 4000;

class String {

 protected:

    char*  Str;  ///< Character string
    int  Size;   ///< Size of the character string
    int  Ptr;    ///< Pointer pointing to a character position in the string

    int  is_idigit_1 (
      const char  c
    ) const;

...


---------- Post updated at 10:40 PM ---------- Previous update was at 10:32 PM ----------

I am thinking of putting a non-defining declaration in the header file and provide a definition in the cpp file

extern const int  MaxDimString;

And then define things in cpp file.

---------- Post updated 02-12-13 at 12:27 AM ---------- Previous update was 02-11-13 at 10:40 PM ----------

also I think I should only have #ifndef in the hpp file only
and not also in the ipp or cpp.

#ifndef STRING_HPP
#define STRING_HPP

---------- Post updated at 09:20 AM ---------- Previous update was at 12:27 AM ----------

Am trying to create an object file
print_options.o

  	 	 	 	 	 	  print_options.o : $(SRCDIR)/program_options/print_options.cpp $(INCDIR)/program_options/print_options.hpp         g++ $(CPP_OPTS) -c $(SRCDIR)/program_options/print_options.cpp         -mv print_options.o $(OBJDIR)

And getting the error

make -f raytrac.mk print_options.o
g++ -I../../../ -O3  -Wno-non-template-friend -Wno-deprecated -DNDEBUG -c ../../../libs/program_options/print_options.cpp
../../../libs/program_options/print_options.cpp: In function �void printopt_secn(FILE*, int, const char*, bool)':
../../../libs/program_options/print_options.cpp:24:3: error: �string' was not declared in this scope
../../../libs/program_options/print_options.cpp:24:11: error: expected �;' before �format'
../../../libs/program_options/print_options.cpp:29:7: error: �format' was not declared in this scope

The right place for constants is generally in *.h* files in #define, but if you need a type, include a cast or suffix as well.

You need the includes for your string type, for starters.