编译共享对象时出错:未检测到C++类定义

Error when compiling shared object: C++ class definition not being detected

本文关键字:检测 C++ 定义 共享 对象 出错 编译      更新时间:2023-10-16

我正在尝试编译一个共享库,该库将用作我正在编写的一些测试软件的插件,该软件将检查机器人导航算法的可行性。测试软件加载共享对象,该共享对象包含表示导航算法的实现的对象的定义,以及生成所述对象的工厂方法。然后,软件使用这个对象来测试算法在已知条件下的可行性。简而言之,在移交统治权之前,该软件将为算法提供一个起点和对课程表示的参考。但这一切都不重要。

现在,我正试图编译一个存根库,只是为了检查/调试共享对象加载机制。以下是我正在使用的头文件:

课程.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.hp:

/************************************
* 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_ */

下面是我目前使用的".cpp"文件:

#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 destructorn";
}
//*************************
// Navigation Methods:
//*************************
void NaviAlgorithm::startNavigation(){
cout << "Navigation started;n";
}
void NaviAlgorithm::startNavigationWithStepThrough(){
cout << "Navigation started;n";
}

};

我的问题是,每当我试图构建共享对象时,编译器总是为NaviAlgorithm.hpp和NaviAlgoritim.cpp都会给我错误"Course not name a type"。我缺少什么吗?该程序作为一个整体,只在Linux上运行。如有任何建议,我们将不胜感激。

在NaviAlgorithm.hpp文件中,

namespace LunarBot{
#include "Course.hpp"

将其更改为如下:-

#include "Course.hpp"
namespace LunarBot{

否则,您将在名称空间LunarBot中创建新的名称空间LunarBot。