
我嘗試在我的系統上安裝 allegro 庫。我的程式碼以及編譯程式時遇到的錯誤:
/* testprog.c */
#include <allegro.h>
void init();
void deinit();
int main() {
init();
while (!key[KEY_ESC]) {
/* put your code here */
}
deinit();
return 0;
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
Errors I'm getting:
$ gcc testprog.c -o testprog `allegro-config --cflags --libs`
testprog.c: In function ‘init’:
testprog.c:26:1: warning: format not a string literal and no format arguments [-Wformat-security]
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
$
我已按照這些連結上給出的說明安裝庫並編譯我的程式:
答案1
allegro_message()
使用格式字串輸出一則訊息printf()
。
錯誤在行中:
allegro_message(allegro_error);
將其更改為:
allegro_message("%s\n", allegro_error);