0

I am currently trying to generate makefile that can handle generating dependancies for a C and C++ raytracer project. I need assistance in generating the include files being used.

# Makefile

# Default Directories:
#  bin  the binary directory
#  inc  the include directory
#  obj  the object directory
#  src  the source directory
BIN_DIR  := bin
INC_DIR  := inc
OBJ_DIR  := obj
SRC_DIR  := src

# The compiler: gcc for C programs, define as g++ for C++
CC       := gcc
CXX      := g++

# Compiler flags:
#  -g      adds debugging information to the executable file
#  -Wall   turns on most, but not all, compiler warnings
#  -O2/O3  defines the optimization level of the program(s)  
CFLAGS   := -g -Wall -O2
CXXFLAGS := -g -Wall -O3

INCLUDES := -I$(INC_DIR)

My file structure is the following:

Raytracer
  |
  |___bin
  |
  |___inc
  |    |__Geometric
  |           |____Vector3D.h
  |
  |___obj
  |
  |___src
       |__Geometric
       |    |______Vector3D.c
       |    |______Vector3D.cpp
       |
       |___Main
            |__Main.c
            |__Main.cpp 

In the Vector3D.h file, I used a template format in and initialized:

#ifndef __VECTOR3D_H__
#define __VECTOR3D_H__

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

// C Methods defined surrounded with __cplusplus & extern "C" {...}
#ifdef __cplusplus
#include <sstream>
#include <iostream>

namespace Geometric {

   template <typename T = float>
   class Vector3D { // Vector3D

     // Constructors already defined...
     // Methods already defined...
     // Etc...

   }; // The 'Vector3D' Class

     // Implemented constructors...
     // Implemented Methods...
     // Implemented Etc...

} // The 'Geometric' Namespace

#endif /* __cplusplus */
#endif /* __VECTOR3D_H__ */

When defining the Vector3D.c & Vector3D.cpp files should i use:

#include "Geometric/Vector3D.h"

// Or

#include <Geometric/Vector3D.h>

// Or does it matter...
MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Note: The Makefile is is in the root directory i.e. Raytracer file –  Nov 10 '16 at 19:02
  • This is a super-long and complex post, just to ask the simple question at the end... surely you could have Googled for this in a fraction of the time it took you to generate this SO post. You might have found, for example: http://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename Short answer: use `#include "Geometric/Vector3D.h"` – MadScientist Nov 10 '16 at 19:03
  • Well I just want to make sure the makefile is correct too. I understand the want to make sure the "INCLUDES := -I$(INC_DIR)" is correct too –  Nov 10 '16 at 19:06
  • You should ask the questions you want answers to. In general on SO people aren't going to just go through your post with a fine-toothed comb and point out everything that might be wrong with it. Your question about the makefile cannot be answered with the info provided since you don't say what directory the makefile is in or what directory you are in when you invoke `make`. The compile line will contain `-Iinc` so if you always run make from the `Raytracer` directory it will work, since `Raytracer/inc` is the right directory. Otherwise it won't work. – MadScientist Nov 10 '16 at 19:48
  • Oh, also, I'm assuming there's more to your makefile and you've not shown us the part that uses the variable `INCLUDES`, because currently you set that variable but never actually use it for anything. – MadScientist Nov 10 '16 at 19:49

0 Answers0