Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

codeblocks - header richtig einbinden?

Empfohlene Antworten

Veröffentlicht

Hallochen,

ich programmiere eigentlich nur unter linux, aber ich muss für ein Projekt unter Windows arbeiten. Nun habe ich ein Problem beim Verwenden eigener Header-Dateien. Ich habe mir ein Projekt erstellt, unter "build options" -> "search directories" für Compiler und Linker jeweils den Pfad angegeben, in dem die beiden header bitmap.h und texture.h mit den zugehörigen .c files liegen und diese Dateien auch noch dem Projekt hinzugefügt. Ich hab mir einige Beschreibungen im Netz angesehen, bei mir scheint nichts davon zu funktionieren. Die Fehler beziehen sich dabei alle auf die bitmap.c ("was not declared in this scope" zu 90%) Ich verwende für das Projekt den GNU-gcc Compiler. Die bitmap.h wird von der texture.h inkludiert.

Hier mal die bitmap.c


#include "bitmap.h"

void *LoadDIBitmap(char *filename, BITMAPINFO **info) /* BITMAPINFO kennt er schonmal nicht */
{ // den Rest aus dem header auch nicht
FILE *fp; /* Open file pointer */
void *bits; /* Bitmap pixel bits */
long bitsize, /* Size of bitmap */
infosize; /* Size of header information */
BITMAPFILEHEADER header; /* File header */
...
[/PHP]

und die bitmap.h

[PHP]
#ifndef _BITMAP_H
#define _BITMAP_H
//File: Bitmap.h
//Written by: Mark Bernard
//on GameDev.net: Captain Jester
//e-mail: mark.bernard@rogers.com
//Please feel free to use and abuse this code as much
//as you like. But, please give me some credit for
//starting you off on the right track.
//
//The file Bitmap.cpp goes along with this file
//
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

const short BITMAP_MAGIC_NUMBER=19778;
const int RGB_BYTE_SIZE=3;

#pragma pack(push,bitmap_data,1)

typedef struct tagRGBQuad {
char rgbBlue;
char rgbGreen;
char rgbRed;
char rgbReserved;
} RGBQuad;

typedef struct tagBitmapFileHeader {
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
} BitmapFileHeader;

typedef struct tagBitmapInfoHeader {
unsigned int biSize;
int biWidth;
int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
int biXPelsPerMeter;
int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
} BitmapInfoHeader;

#pragma pack(pop,bitmap_data)

class Bitmap {
public:
//variables
RGBQuad *colours;
char *data;
bool loaded;
int width,height;
unsigned short bpp;
string error;
//methods
Bitmap(void);
Bitmap(char *);
~Bitmap();
bool loadBMP(char *);
private:
//variables
BitmapFileHeader bmfh;
BitmapInfoHeader bmih;
int byteWidth; //the width in bytes of the image
int padWidth; //the width in bytes of the added image
unsigned int dataSize; //size of the data in the file
//methods
void reset(void);
bool convert24(char *); //convert to 24bit RGB bottom up data
bool convert8(char *); //convert to 24bit RGB bottom up data
};

#endif //_BITMAP_H

Also unter Linux ist das definitiv einfacher, einfach die header inkludieren und dem gcc alle .c-Dateien mitgeben ...

Weiß jemand wo das Problem liegt?

  • Autor

Verstehe, ich hatte aber auch schon versucht den Compiler zu ändern. Mit einem C++-Compiler hat es aber nicht mehr funktioniert. Muss ich also ein neues c++-Projekt erstellen, damit ich meine bitmap.h verwenden kann?

Mit einem C++-Compiler hat es aber nicht mehr funktioniert.
Siehe dazu meine Signatur.

Muss ich also ein neues c++-Projekt erstellen, damit ich meine bitmap.h verwenden kann?
Unter anderem. Ist dir klar, dass zu dieser bitmap.h eine bitmap.cpp gehört, in der die Methoden definiert werden? Für sich allein ist die Headerdatei nutzlos.
  • Autor
Siehe dazu meine Signatur.

Wie Recht du hast^^

Egal welchen Compiler ich nehme:


"Prog - Debug" uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...

Das passiert auch, wenn ich einfach ein neues Glut-Projekt unter codeblocks anlege und gleich einen c++-Compiler nehme. Nichtmal der Beispiel-Code lässt sich übersetzen.

Ist dir klar, dass zu dieser bitmap.h eine bitmap.cpp gehört, in der die Methoden definiert werden? Für sich allein ist die Headerdatei nutzlos.

Ja, da hab mich mich auch erst gewundert. Ich hab eine BITMAP.cpp.C und eine BITMAP.C mit dem selben Inhalt, nur C-Code. Die Dateien hat mein Prof als Beispiel an uns weitergegeben, diese Konstellation hat bei ihm unter Visual Studio funktioniert. Leider habe ich keine Idee wie ich das unter CodeBlocks anstelle, oder ob das überhaupt funktionieren kann. Vielleicht such ich mir einfach ein anderes Beispiel zum Laden von Texturen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.