[SOLVED] Issues With Visual Studio and Project Items

Started by
11 comments, last by EnigmaticCoder 14 years, 1 month ago
When I started my current project, I used Windows and Visual Studio, but then I started using Ubuntu almost exclusively. I continued making the game on Linux, but since the game is cross platform and has been changed quite a bit, I wanted to test the Windows build (the Linux build works fine). I updated my Windows working copy and added existing items into the project. But when I built the project, it complained about an identifier 'Rectangle,'* even though I added Rectangle.h to the project. To be sure, the header was included before Rectangle was used. Normally, when I have a problem like this in Visual Studio, instead of adding an existing item, I add a new one and copy/paste the code from the existing file, but this time, I didn't want to it that way because it might cause problems with subversion. What's more is that I excluded Renderer.h from my project, and when I built it, the compiler said there's an error in Renderer.h! What should I do? *Error code is C2061 [Edited by - EnigmaticCoder on March 5, 2010 10:11:33 PM]
--------------------Enigmatic Coding
Advertisement
The .h files are only in the project to make them easily accessible.

Only the .cpp files and project settings _should_ matter when building. If a .cpp file include Renderer.h, then it'll be compiled as well independently of whether or not it's in the project.

I don't know what's causing your problem though.
Quote:
What should I do?

Paste the code of the .cpp file being compiled when the error occurs.

Quote:
What's more is that I excluded Renderer.h from my project, and when I built it, the compiler said there's an error in Renderer.h!

VS (and most build systems) does not set headers to the compiler. Only source files are sent; the headers are picked up by the preprocessor.
Quote:Original post by jpetrie
Paste the code of the .cpp file being compiled when the error occurs.


The errors are being thrown in Renderer.h:

/* *	Copyright John Miner 2009 * *	Renderer.h *	 */#ifndef RENDERER_H_#define RENDERER_H_#include <map>#include <string>#include <vector>#include "SDL.h"#include "SDL_opengl.h"#include "SDL_image.h"#include "Globals.h"#include "Image.h"#include "TileSheet.h"#include "SpriteSheet.h"#include "Sprite.h"#include "ScreenState.h"#include "Level.h"#include "Color.h"#include "Map.h"#include "Cursor.h"#include "Rectangle.h"#include "ImageSheet.h"class Cursor;class Renderer {private:    SDL_Surface *screen;    //Instead of duplicating the Sheet code just use    //Sheet instead of making a similar class called Image    std::map<std::string, ImageSheet> images;    std::map<std::string, TileSheet> tileSheets;    std::vector<SpriteSheet> spriteSheets;    Renderer(); //I don't want to construct this object without a screen state    //Utility    int convertToTileIndex(double coordinate, const int &tileSize, const int OFFSET, int uBound);    void getSheetCoordinates(const Map &map, int tileNum, int &rowIndex, int &colIndex);    void getStartIndexes(const Map &map, int x, int y, int &rowIndex, int &colIndex);    void getEndIndexes(const Map &map, ScreenState screenState, int levelRow, int levelCol, int &endLevelRow, int &endLevelCol);    bool validateBoundaries(const Map &map, int row, int col);    bool getNextLowest(int &currentZ, const std::map<std::string, Image> &images);    void setOpenGlState(const ScreenState &screenState);    public:    Renderer(ScreenState &screenState, int screenBPP);    ~Renderer();    void initialize(ScreenState &screenState, int screenBPP);    GLuint loadOpenGlTexture(SDL_Surface *surface) const;    void loadImage(const std::string &fileName, double sheetWidth, double sheetHeight, double imageWidth, double imageHeight);    void loadTileSheet(const std::string &fileName, double sheetWidth, double sheetHeight,            int tileDimensions, Color colorKey = NULL_COLOR); //Think about an alpha channel instead    void loadSpriteSheet(char *fileName, double sheetWidth, double sheetHeight,            double spriteWidth, double spriteHeight, Color colorkey = NULL_COLOR);    void eraseImage(std::string filePath);    void freeImage(std::string filePath);    void freeAllImages();    void freeTileSheet(const std::string &filePath);    void freeAllTileSheets();    void freeSpriteSheet(int index);    void freeAllSpriteSheets();    void freeAllSurfaces();    void addImage(const std::string &filePath, SDL_Surface *sheet, double sheetWidth, double sheetHeight, double imageWidth, double imageHeight);    void drawImage(const std::string &filePath, double x, double y);    void drawTile(const Tile &tile, double x, double y);    void drawSprite(const Sprite &sprite, double x, double y);    void drawCursor(const Cursor &cursor, double x, double y);    void drawLayer(const Map &map, int layer, int row, int col, int levelRow,            int levelCol, double modifiedX, double modifiedY);    void drawScreen(ScreenState &screenState, const Level &level, const Map &map, const Map &tunnelMap,            const std::vector<Sprite> &sprites, const Player &player,            const std::map<std::string, Image> &images, const Cursor &cursor, int cameraX, int cameraY);    void drawScreen(); //Wapper around SDL_Flip    void applySdlSurface(int x, int y, SDL_Surface *source, SDL_Surface *destination) const;    void applySurface(int x, int y, int imageWidth, int imageHeight, double sheetWidth, double sheetHeight, const GLuint &texture, Rectangle *clipRegion = NULL) const;    bool spriteOnScreen(Sprite sprite, double topLeftX, double topLeftY, int screenWidth, int screenHeight);    void getSpriteOnScreenCoordinates(Sprite sprite, double topLeftX, double topLeftY, double &drawPositionX, double &drawPositionY);};#endif
--------------------Enigmatic Coding
Paste the code of the .cpp file being compiled when the error occurs. You can see this in the build log.

You will probably also need to provide the source for all the headers included by that file, but since that appears to be quite a lot, hopefully the problem will become apparent from just the initial code (I'm actually only interested in the headers included from the .cpp file).

Also, indicate the line that the error occurs on in Renderer.h

You almost certainly have a circular include problem, probably stemming from your use of Globals.h or one of the other includes from the original .cpp forming a TU where the Rectangle class is defined after it is first used.
I'm having trouble posting it. Is the site slow right now?
--------------------Enigmatic Coding
Is there a maximum post length or code in source tag length?
--------------------Enigmatic Coding
You might be running into some obscure bug where source code gets misformatted and messes up your post.
I posted the code to **snip**.

[Edited by - EnigmaticCoder on March 6, 2010 6:19:36 PM]
--------------------Enigmatic Coding
Looks like it's almost certainly an inclusion order issue. You can have Visual Studio emit the preprocessed code (look in the project options) or you can manually trace the inclusion graph to see how Rectangle is getting used before it is defined.

You also don't even need to be including the header, it looks like you could just forward-declare Rectangle.

This topic is closed to new replies.

Advertisement