为什么我在Eclipse CDT上得到这个错误
Why I am getting this error on Eclipse CDT?
我对c++比较陌生,我为eclipse安装了CDT Plugin,以便在我的Ubuntu机器上进行开发。我是一名Java程序员,我正在努力使c++代码正确工作。
我创建了一个这样的类:RandomMapGenerator.hpp:
#ifndef RANDOMMAPGENERATOR_HPP_
#define RANDOMMAPGENERATOR_HPP_
class RandomMapGenerator {
public:
bool generateMap (std::vector<sf::ConvexShape> &polygonList, const char* name, unsigned int width,
unsigned int height, int seed, unsigned int frec, unsigned int dist, bool log, bool deleteOnFinish);
private:
bool loadMap (std::vector<sf::ConvexShape> &polygonList, const char* name, unsigned int &width,
unsigned int &height, bool log);
// Convierte 4 bytes a un int de 32 bits siendo b1 el MSB
unsigned int bytesToInt (unsigned char b1, unsigned char b2, unsigned char b3, unsigned char b4){
return ( b4 | (b3<<8) | (b2<<16) | (b1<<24) );
}
// Convierte 2 bytes a un int de 32 bits siendo b1 el MSB
unsigned int bytesToInt (unsigned char b1, unsigned char b2){
return ( b2 | (b1<<8) );
}
};
#endif /* RANDOMMAPGENERATOR_HPP_ */
RandomMapGenerator.cpp:
#include "RandomMapGenerator.hpp"
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <stdio.h>
bool RandomMapGenerator::generateMap (std::vector<sf::ConvexShape>& polygonList, const char* name, unsigned int width,
unsigned int height, int seed, unsigned int frec, unsigned int dist, bool log, bool deleteOnFinish) {
// Nombre del archivo binario generado
const std::string fileName = std::string(name, 0, 20) + ".map";
std::ostringstream command;
// Ejecuto el .jar que genera el archivo
command << "java -jar MapGenerator.jar" << " -w " << width << " -h " << height
<< " -d " << dist << " -s " << seed << " -f " << frec
<< " -b " << name << (log ? " -l " : "");
// http://stackoverflow.com/questions/1374468/c-stringstream-string-and-char-conversion-confusion
const std::string &cmd = command.str();
system(cmd.c_str());
// Genero los polígonos en base al archivo binario generado
bool result = loadMap(polygonList, fileName.c_str(), width, height, log);
// Borro el archivo .map si asi se especifico
if(deleteOnFinish) remove(fileName.c_str());
return result;
}
bool RandomMapGenerator::loadMap(std::vector<sf::ConvexShape>& polygonList, const char* name, unsigned int& width,
unsigned int& height, bool log) {
long int fileSize;
unsigned int polygonsNumber;
char *memBuffer;
std::ifstream file (name, std::ios::in | std::ios::binary | std::ios::ate);
std::ofstream logFile ("log_c.txt");
if (file.is_open() && logFile.is_open()) {
if(log) logFile << "Reserving memory" << std::endl;
fileSize = file.tellg(); // Tamaño del archivo en bytes
memBuffer = new char[fileSize]; // Array del tamaño del archivo
file.seekg (0, std::ios::beg); // Voy al comienzo del archivo
file.read(memBuffer, fileSize); // Copio el archivo a RAM
width = bytesToInt(memBuffer[0],memBuffer[1],memBuffer[2],memBuffer[3]);
height = bytesToInt(memBuffer[4],memBuffer[5],memBuffer[6],memBuffer[7]);
polygonsNumber = bytesToInt(memBuffer[8],memBuffer[9],memBuffer[10],memBuffer[11]);
if(log) logFile << "Size: " << fileSize/1000 << "Kb" << std::endl;
if(log) logFile << "Cantidad de poligonos: " << polygonsNumber << std::endl;
if(log) logFile << "Ancho: " << width << std::endl;
if(log) logFile << "Alto: " << height << std::endl;
// Reservo para la cantidad de poligonos y comienzo a leer
polygonList.reserve(polygonsNumber);
unsigned int pointCount;
unsigned int x,y,r,g,b,n;
for(n = 12; n < fileSize-16;){
// Cantidad de puntos del polígono
if(log) logFile << "n: " << n << std::endl;
pointCount = bytesToInt(memBuffer[n], memBuffer[n+1]);
n += 2;
// Leo las coordenadas (x,y) de cada punto siendo cada una de 4 bytes
sf::ConvexShape mPolygon;
mPolygon.setPointCount(pointCount);
if(log) logFile << "pointCount: " << pointCount << std::endl;
for(unsigned int i = 0; i < pointCount; ++i){
x = bytesToInt(memBuffer[n], memBuffer[n+1], memBuffer[n+2], memBuffer[n+3]);
n += 4;
y = bytesToInt(memBuffer[n], memBuffer[n+1], memBuffer[n+2], memBuffer[n+3]);
n += 4;
mPolygon.setPoint(i, sf::Vector2f(x,y));
if(log) logFile << std::dec << "(" << x << "," << y << ")" << std::endl;
}
// Leo el color del poligono siendo cada componente de 2 bytes
r = bytesToInt(memBuffer[n], memBuffer[n+1]); n += 2;
g = bytesToInt(memBuffer[n], memBuffer[n+1]); n += 2;
b = bytesToInt(memBuffer[n], memBuffer[n+1]); n += 2;
if(log) logFile << "R: " << r << " G: " << g << " B: " << b << std::endl << std::endl;
// Agrego el poligono a la lista
mPolygon.setFillColor(sf::Color(r,g,b,255));
polygonList.push_back(mPolygon);
}
file.close();
logFile.close();
delete memBuffer;
if(log) logFile << "Terminado - n: " << n << std::endl;
return true;
}
else {
std::cout << "Unable to open file" << std::endl;
return false;
}
}
Main.cpp
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <AdvancedView.hpp>
#include <RandomMapGenerator.hpp>
using namespace std;
using namespace sf;
#define seed 80
int main() {
std::vector<sf::ConvexShape> list;
unsigned int screenWidth = 500;
unsigned int screenHeight = 500;
RandomMapGenerator map;
map.generateMap(list, "prueba", screenWidth, screenHeight, seed, 5, 3, true, false);
sf::RenderWindow mWindow(sf::VideoMode(screenWidth,screenHeight), "Cave Doom");
mWindow.clear();
for(vector<ConvexShape>::iterator it = list.begin(); it < list.end(); ++it){
mWindow.draw(*it);
}
mWindow.display();
return 0;
}
在generateMap()
的main.cpp中,我得到这个错误
未定义的引用`RandomMapGenerator::generateMap(std::vector>&, char const*, unsigned int,Unsigned int, int, Unsigned int, Unsigned int, bool, bool)'
我正在传递正确类型的参数,为什么我得到这个错误?我试着:
- 清洁项目
- 重启Eclipse 重建索引
RandomGenerator.hpp
和RandomGenerator.cpp
与main.cpp
不在同一文件夹中,但我已将该文件夹添加到构建路径中。
我将存放文件的文件夹添加到Eclipse项目的源文件夹列表中,现在它可以工作了!
相关文章:
- C++ 运行时链接器错误 (liblog4cpp.so.5) Eclipse
- 在 Eclipse: "error: no match for 'operator='" 中获取错误消息
- 在 eclipse 中,将宏重定义视为错误而不是警告
- 如何摆脱导入的 make 项目中的 Eclipse 索引器"Type std::... could not be resolved"错误
- Eclipse/CDT_C++给出"语义错误_"类型XXX无法解决"。项目运行
- 我必须构建才能摆脱 Eclipse 中的错误吗?
- Eclipse 构建错误在默认的 hello world 上
- Eclipse:错误:初始化模式失败(无法连接到目标)
- Eclipse (C++) 的未定义引用错误
- Eclipse CDT 将 static_assert(cond) 突出显示为语法错误
- Eclipse错误突出显示使用自动C
- 新的 C++14 位分隔符处"Bad Character" Eclipse Oxygen 错误
- 在 CentOS 7 上通过 devtoolset-4 安装的 Eclipse CDT 使用了错误版本的 gcc/g++
- Eclipse显示出错误,但GCC编译了罚款
- 我正在尝试在Eclipse中构建一个C 项目,但是即使在使用MINGW路径设置路径变量之后,也会获得构建错误
- mingwCC 编译错误 (Eclipse Juno)
- c++:奇怪的共享库错误- eclipse
- 执行格式错误Eclipse CDT
- 未解析的包含错误eclipse
- 即使在构建后仍然"Binary Not Found"错误(Eclipse OSX Mtn. Lion)