Moin,
ich sitz jetzt schon ein paar Stunden an den Problem, und auch Google/Bücher geben keine Antwort mehr her. Ich habe ein Problem mit einem Konstruktor, was mir so noch nie passiert ist.
Folgendes:
Header:
#define XSERVER_H
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <string.h>
class Xserver {
public:
void start();
void createWindow();
private:
Display *display;
Visual *visual;
int depth;
int text_x;
int text_y;
XSetWindowAttributes frame_attributes;
Window frame_window;
XFontStruct *fontinfo;
XGCValues gr_values;
GC graphical_context;
XKeyEvent event;
int string_length = strlen(Hstring);
char Hstring[] = "TestDesXservers";
};
#endif
source:
#include <stdio.h>
#include <X11/Xlib.h>
#include <string.h>
#include "../inc/Xserver.h"
void Xserver::start()
{
Xserver::display = XOpenDisplay(NULL);
Xserver::visual = DefaultVisual(display, 0);
Xserver::depth = DefaultDepth(display, 0);
}
void Xserver::createWindow()
{
Xserver::frame_attributes.background_pixel = XWhitePixel(display, 0);
Xserver::frame_window = XCreateWindow(display, XRootWindow(display, 0),
0, 0, 400, 400, 5, depth,
InputOutput, visual, CWBackPixel,
&frame_attributes);
XStoreName(display, frame_window, "atlas");
XSelectInput(display, frame_window, ExposureMask | StructureNotifyMask);
Xserver::fontinfo = XLoadQueryFont(display, "10x30");
Xserver::gr_values.font = fontinfo->fid;
Xserver::gr_values.foreground = XBlackPixel(display, 0);
Xserver::graphical_context = XCreateGC(display, frame_window,
GCFont+GCForeground, &gr_values);
XMapWindow(display, frame_window);
while(1)
{
XNextEvent(display, (XEvent *)&event);
switch(event.type)
{
case Expose:
{
XWindowAttributes window_attributes;
int font_direction, font_ascent, font_descent;
XCharStruct text_structure;
XTextExtents(fontinfo, Xserver::Hstring, Xserver::string_length,
&font_direction, &font_ascent, &font_descent,
&text_structure);
XGetWindowAttributes(display, frame_window, &window_attributes);
Xserver::text_x = (window_attributes.width - text_structure.width)/2;
Xserver::text_y = (window_attributes.height - (text_structure.ascent - text_structure.descent))/2;
XDrawString(display, frame_window, graphical_context,
Xserver::text_x, Xserver::text_y, Xserver::Hstring, Xserver::string_length);
break;
}
default:
break;
}
}
}
main:
#include <stdlib.h>
#include <stdio.h>
#include "inc/Xserver.h"
/*starting main*/
int main(int argc, char *argv[])
{
Xserver* X11 = new Xserver();
X11->start();
X11->createWindow();
return 0;
}
compilen tu ich alles mit CMake
CMakeLists.txt:
#atlas project
cmake_minimum_required(VERSION 3.5.2)
project(atlas)
set(SRC main.cpp src/Xserver.cpp inc/Xserver.h)
add_executable(atlas ${SRC})
target_link_libraries(${PROJECT_NAME} X11)
So viel zum Code.
Der Fehler ist folgender:
atlas/inc/Xserver.h:9:7: interner Compiler-Fehler: in finish_expr_stmt, bei cp/semantics.c:677
class Xserver {
Ich möchte den Standart-ctor nutzen.
Wo ist mein Fehler? Für Hilfe wär ich Dankbar, ich bin leicht am Verzweifeln.
Danke, xygnu