C++ Compilation Include problems


 
Thread Tools Search this Thread
Top Forums Programming C++ Compilation Include problems
# 1  
Old 02-10-2013
C++ Compilation Include problems

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

This is the error I get
Code:
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.

Code:
 > 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

Code:
#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.

Code:
> 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[Size];
  for (int i = 0; i < Size; i++) {
    X[i] = 0;
  }

}

etc ...


Last edited by kristinu; 02-10-2013 at 05:37 PM..
# 2  
Old 02-11-2013
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.
# 3  
Old 02-12-2013
Coding C++ classes

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??

Code:
> 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


Code:
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.

Code:
#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
Code:
  	 	 	 	 	 	  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

Code:
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

# 4  
Old 02-12-2013
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Compilation C program

Hi guys... Im trying to compile a program written in C.. I am able to compile it to X86, especifically Ubuntu.. But i cant compile it to mips ar71xx architecture.. im using mips-linux-uclibc-gcc cross compiler. this is the portion of code: //STAT: LOGIN INFO // 3. login info i =... (3 Replies)
Discussion started by: lordtrex
3 Replies

2. Shell Programming and Scripting

Compilation

Hi All, Do we have a way to compile a shell program? I am using ksh/bash/sh and not CSH. Cheers Ravi (12 Replies)
Discussion started by: panyam
12 Replies

3. Solaris

Compilation - unable to finding include files

Hey there, This is gotta be a stupid question, if there ever was one, but I am learning a lot by asking such questions. Now I am trying to build this humungous library, which has all kinds a dependencies, which I realize as it makes, and i download all those dependent libs. The compilation is... (1 Reply)
Discussion started by: shriyer123
1 Replies

4. UNIX for Dummies Questions & Answers

Compilation

Hi All, We have a C program existing in one of the folders which I have to modify a lil bit, When I'm trying to compile the program using GCC or CC command its showing as ksh: gcc: not found is that mean there is no compiler or do I have to verify for something, please advice Thank... (2 Replies)
Discussion started by: diggermf
2 Replies

5. Programming

Compilation error : Please help

state_field state_abvr = { "AL","ALABAMA", "AK","ALASKA", "AZ","ARIZONA", "AR","ARKANSAS", "CA","CALIFORNIA", "CO","COLORADO", "CT","CONNECTICUT", "DE","DELAWARE", "DC","DISTRICT-OF-COLUMBIA", "FL","FLORIDA", "GA","GEORGIA", "HI","HAWAII", "ID","IDAHO", "IL","ILLINOIS",... (1 Reply)
Discussion started by: jagan_kalluri
1 Replies

6. UNIX for Dummies Questions & Answers

Compilation Options

hi, currently I have Fedora Core 7 and I use the Compiler ported with FC7. i.e "cc src.c". but I am unable to explore the Compilation Options that can be passed with cc... like cc -c and options like that.. but when I tried man cc, I did not find any mnaual page for CC.. so now how do... (2 Replies)
Discussion started by: compbug
2 Replies

7. Programming

Compilation error

I am compiling a software xchm on solaris 10. First i run './configure' There is no error. But when i start compiling using 'gmake' following error shown /usr/local/include/wx-2.6/wx/x11/brush.h: In copy constructor `wxBrush::wxBrush(const wxBrush&)':... (3 Replies)
Discussion started by: mansoorulhaq
3 Replies

8. Solaris

compilation problem

I am compiling a software named wine When i run make then at the end following error generated. DVAPI32_ -foversion.res version.rc ld.so.1: ../../tools/wrc/wrc: fatal: relocation error: file ../../tools/wrc/wrc: symbol wine_casemap_upper: referenced symbol not found *** Signal 9 make:... (0 Replies)
Discussion started by: mansoorulhaq
0 Replies

9. UNIX for Dummies Questions & Answers

Kernel compilation

I have re-compiled kernel source code available in /usr/src/linux.2.4.20 with "make" command. The compilation is succesful. Now the problem is create the image for this. The documentation in the same folder says that now you have compile "make image". There is no option for image in Makefile. ... (3 Replies)
Discussion started by: mankrish
3 Replies

10. Programming

compilation error

Hi, While trying compile a C++ file in UNIX with gcc whose make rule involves the usage of /usr/ccs/bin/as, I get the following error: /usr/ccs/bin/as: No such file or directory /usr/ccs/bin/as: error: write error on output file "<filename>.o" *** Error code 1 clearmake: Error: Build... (2 Replies)
Discussion started by: smanu
2 Replies
Login or Register to Ask a Question