
システムに 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);