Pierwszy problem jest z allegro.
Biblioteki do allegro znajdują się u mnie w katalogu /usr/lib , mam tam skompilowane biblioteki allegro z końcówką .so
Dobra kompilują program z allegro.
Mam mój program main.c wchodzę do tego katalogu /home/donmatteo/mojprogram/ tutaj mam program main.c kompiluję następująco g++ main.c -l allegro , program kompiluje mi się! ale jeszcze z otworzeniem tego pliku jest problem... Po kompilacji tworzy mi się w tym katalogu plik a.out, więc otwieram ./a.out ale wyskakuje error nie falied to initialize allegro! ,Jeszcze po kompilacji muszę allegro podlinkować ? Jak?
Dobra to jest błąd kod błędu pochodzący bezpośrednio z programu który kompilowałem:
#include <stdio.h>
#include <allegro5/allegro.h>
const float FPS = 60;
const int SCREEN_W = 640;
const int SCREEN_H = 480;
const int BOUNCER_SIZE = 32;
int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;
ALLEGRO_BITMAP *bouncer = NULL;
float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0;
float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0;
bool redraw = true;
if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
if(!al_install_mouse()) {
fprintf(stderr, "failed to initialize the mouse!\n");
return -1;
}
timer = al_create_timer(1.0 / FPS);
if(!timer) {
fprintf(stderr, "failed to create timer!\n");
return -1;
}
display = al_create_display(SCREEN_W, SCREEN_H);
if(!display) {
fprintf(stderr, "failed to create display!\n");
al_destroy_timer(timer);
return -1;
}
bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE);
if(!bouncer) {
fprintf(stderr, "failed to create bouncer bitmap!\n");
al_destroy_display(display);
al_destroy_timer(timer);
return -1;
}
al_set_target_bitmap(bouncer);
al_clear_to_color(al_map_rgb(255, 0, 255));
al_set_target_bitmap(al_get_backbuffer(display));
event_queue = al_create_event_queue();
if(!event_queue) {
fprintf(stderr, "failed to create event_queue!\n");
al_destroy_bitmap(bouncer);
al_destroy_display(display);
al_destroy_timer(timer);
return -1;
}
al_register_event_source(event_queue, al_get_display_event_source(display));
al_register_event_source(event_queue, al_get_timer_event_source(timer));
al_register_event_source(event_queue, al_get_mouse_event_source());
al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_start_timer(timer);
while(1)
{
ALLEGRO_EVENT ev;
al_wait_for_event(event_queue, &ev);
if(ev.type == ALLEGRO_EVENT_TIMER) {
redraw = true;
}
else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
break;
}
else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES ||
ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY) {
bouncer_x = ev.mouse.x;
bouncer_y = ev.mouse.y;
}
else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
break;
}
if(redraw && al_is_event_queue_empty(event_queue)) {
redraw = false;
al_clear_to_color(al_map_rgb(0,0,0));
al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0);
al_flip_display();
}
}
al_destroy_bitmap(bouncer);
al_destroy_timer(timer);
al_destroy_display(display);
al_destroy_event_queue(event_queue);
return 0;
}
Ale dlaczego ten ekranik nie chce mi się otworzyć, a program zwraca ten błąd?
Problem z opengl też jest z kompilacją. Na tym etapie się zatrzymałem, Polecenie wygląda następująco;
g++ -o keyboardAndMouse.cpp main.cpp -I /usr/include/x86_64-linux-gnu/qt5/QtCore -I /usr/include/x86_64-linux-gnu/qt5 -I /usr/include/x86_64-linux-gnu/qt5/QtXml -I /usr/include/x86_64-linux-gnu/qt5/QtOpenGL -I /usr/include/x86_64-linux-gnu/qt5/QtGui -lQGLVieweL -l GL -lQtOpenGL -lQtGui -l/usr/include/x86_64-linux-gnu/qt5/QtCore/ -I /usr/include/x86_64-linux-gnu/qt5/QtWidgets/
No i wynik polecenia:
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qnamespace.h:37:0,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs.h:41,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:40,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/QObject:1,
from /usr/include/QGLViewer/keyFrameInterpolator.h:26,
from /usr/include/QGLViewer/camera.h:26,
from /usr/include/QGLViewer/qglviewer.h:26,
from keyboardAndMouse.h:1,
from main.cpp:1:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1087:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
# error "You must build your code with position independent code if Qt was built with -reduce-
^
sprawdziłem że plik qglobal.h znalazłem w katalogu /usr/lib i również nie moę tego po prostu skompilować.