Reputation: 5
I'm trying to compile a shared library that will be used as a plugin to some testing software I am writing that will check the viability of navigational algorithms for a robot. The testing software loads a shared object containing the definition of an object representing an implementation of a navigation algorithm, as well as a factory method to generate said object. The software then uses this object to test the algorithm's viability under known conditions. In a nutshell, the software is going to give the algorithm a starting point and a reference to a representation of the course before handing over the reigns. But all this is beside the point.
Right now, I am trying to compile a stub library just to check/debug the shared object loading mechanisms. Below are the header files I am using:
Course.hpp:
/*********************************
* Filename: Course.hpp
* Purpose: Defines and clarifies
* ALL data of or relating to the
* physical course. itself.
*
* NOTE: The default number of obstacles is 3.
*/
#ifndef COURSE_HPP_
#define COURSE_HPP_
namespace LunarBot{
#define COURSE_ROWS 388
#define COURSE_COLUMNS 738
typedef char MapPoint; /*Container for flags. 8-bit for size*/
/*By this, the total size of our array will be about 279.63 KB*/
//Simple structure for representing map coordinates:
typedef struct{
int x;
int y;
}MapAddr;
/*Define Obstacle Base Class:*/
#define OBSTACLE_TYPE_CRATER 0x00
#define OBSTACLE_TYPE_ROCK 0x01
class Obstacle {
//Class fields:
public: MapPoint currCourse[COURSE_ROWS][COURSE_COLUMNS];
//Class Methods:
public:
//Constructor:
Obstacle(MapPoint ourCourse[COURSE_ROWS][COURSE_COLUMNS]);
//Destructor:
~Obstacle();
};
/*Define Course:*/
class Course{
//Class fields:
public: MapPoint ourCourse[COURSE_ROWS][COURSE_COLUMNS];
private: //Unknown, as of this point.
Obstacle allObstacles[];
//Class methods:
public:
//Constructor:
Course(bool fullAuto);
Course(bool fullAuto, int numObstacles);
//Destructor:
~Course();
private:
//Initialization Methods:
void initializeObstacles(int); //Randomly place as many obstacles as possible up to the number requested.
MapAddr randomizeStartPoint();
};
}// end namespace LunarBot
#endif /* COURSE_HPP_ */
NaviAlgorithm.hpp:
/************************************
* Filename: NaviAlgorithm.hpp
* Purpose: This file defines the
* NaviAlgorithm class which must
* be subclassed by ALL classes
* representing different and diverse
* navigation algorithms.
*
* This class declares two very important functions,
* "startNavigation()" and "startNavigationWithStepThrough()".
*
* Both perform the same navigational tasks. The difference lies
* in when and what type of output is sent to the console.
*
* "startNavigation()", after being called. Outputs nothing to the
* console until the simulated robot has successfully completed its task.
* When this occurs, the measured completion time is displayed.
*
* "startNavigationWithStepThrough()", as the name suggests, allows
* the user to step through each stage as the robot navigates its way
* around the simulated course. Output occurs at certain points during the
* simulation. When these points occur is dependent on the algorithm implemented.
* What is standardized, to an extent, however, is WHAT is output.
*
* This function will ALWAYS output ANY AND ALL related environmental variables
* (locations of nearby obstacles, time elapsed since last output, etc.). As
* a rule of thumb, if you can't determine the algorithm's effectiveness without something, make sure
* you know what that something is. For you and for us that means include it in the periodic series of outputs.
* For your convenience, a virtual function for that purpose has been provided.
*
************************************/
#ifndef NAVIALGORITHM_HPP_
#define NAVIALGORITHM_HPP_
namespace LunarBot{
#include "Course.hpp"
#define ROBOT_POSITION_FLAG 0x80
class NaviAlgorithm{
//Class Fields:
public: Course* currentCourse;
private: char** argsArray;
//Class Methods:
public:
//Constructor:
NaviAlgorithm(Course* c);
NaviAlgorithm(Course* c, char** args); //A mechanism is in place that you may provide arguments to your algorithm from the command line, if you like.
//Begin Simulation Sequence:
virtual void startNavigation();
virtual void startNavigationWithStepThrough();
//Destructor:
virtual ~NaviAlgorithm();
};
/*Factory Method:*/
extern "C" NaviAlgorithm* createAlgorithmObject(Course* c){
return new NaviAlgorithm(c);
}
}
#endif /* NAVIALGORITHM_HPP_ */
And, here are the ".cpp" files I am currently using:
#include "NaviAlgorithm.hpp"
#include <cstdlib>
#include <iostream>
using std::cout;
namespace LunarBot{
//************************
// Function Definitions:
//************************
//************************
// Constructors:
//************************
NaviAlgorithm::NaviAlgorithm(Course* course){
currentCourse = course;
argsArray = NULL;
}
NaviAlgorithm::NaviAlgorithm(Course* course, char** args){
currentCourse = course;
argsArray = args;
}
//*************************
// Destructor:
//*************************
NaviAlgorithm::~NaviAlgorithm(){
cout << "Default destructor\n";
}
//*************************
// Navigation Methods:
//*************************
void NaviAlgorithm::startNavigation(){
cout << "Navigation started;\n";
}
void NaviAlgorithm::startNavigationWithStepThrough(){
cout << "Navigation started;\n";
}
};
My problem is that whenever I try to build the shared object, the compiler always gives me the error "Course does not name a type" for both NaviAlgorithm.hpp and NaviAlgorithm.cpp. Is there something I am missing? The program, as a whole, is being built to run on Linux only. Any suggestions would be appreciated.
Upvotes: 0
Views: 3176
Reputation: 361
In file NaviAlgorithm.hpp,
namespace LunarBot{
#include "Course.hpp"
Change this to as below:-
#include "Course.hpp"
namespace LunarBot{
Otherwise you are creating new namespace LunarBot inside namespace LunarBot.
Upvotes: 1