前提・実現したいこと
現在、質問にあるようにXLibを使用したアプリケーションを作ろうとしています。
ネットを参考にして、プログラムを記述し終わり、コンパイルをしようとしたところ、
エラーが発生しました。
発生している問題・エラーメッセージ
/tmp/cc96gk9h.o: 関数 `main' 内: test.c:(.text+0x10): `XOpenDisplay' に対する定義されていない参照です test.c:(.text+0xdc): `XCreateSimpleWindow' に対する定義されていない参照です test.c:(.text+0xf0): `XSelectInput' に対する定義されていない参照です test.c:(.text+0xfc): `XMapWindow' に対する定義されていない参照です test.c:(.text+0x10c): `XNextEvent' に対する定義されていない参照です test.c:(.text+0x164): `XFillRectangle' に対する定義されていない参照です test.c:(.text+0x1b0): `XDrawString' に対する定義されていない参照です test.c:(.text+0x1cc): `XCloseDisplay' に対する定義されていない参照です collect2: error: ld returned 1 exit status
該当のソースコード
C
1#include <X11/Xlib.h> 2#include <stdio.h> 3#include <stdlib.h> 4#include <string.h> 5 6int main() 7{ 8 Display *d; // 構造体のポインタ 9 int s; 10 Window w; 11 XEvent e; 12 13 /* サーバーとのコネクションを開く */ 14 d = XOpenDisplay( NULL ); 15 if( d == NULL ){ 16 printf( "Can't open display\n" ); 17 exit( -1 ); 18 } 19 20 s = DefaultScreen( d ); 21 22 /* ウィンドウ作成 */ 23 w = XCreateSimpleWindow( d, RootWindow( d, s ), 10, 10, 100, 100, 1, BlackPixel( d, s ), WhitePixel( d, s ) ); 24 /* 受け付けるイベントの種類を選択 */ 25 XSelectInput( d, w, ExposureMask | KeyPressMask ); 26 /* ウィンドウを可視化 */ 27 XMapWindow( d, w ); 28 29 /* イベントループ */ 30 while( 1 ){ 31 XNextEvent( d, &e ); 32 /* ウィンドウの描画と再描画 */ 33 if( e.type == Expose ){ 34 XFillRectangle( d, w, DefaultGC( d, s ), 20, 20, 10, 10 ); 35 XDrawString( d, w, DefaultGC( d, s ), 50, 50, "Hello World!", strlen( "Hello World!" ) ); 36 } 37 38 /* キーが押されたら終了 */ 39 if( e.type == KeyPress ) break; 40 } 41 42 /* サーバーとのコネクションを閉じる */ 43 XCloseDisplay( d ); 44 45 return 0; 46} 47
試したこと
/usr/include/X11にXlib.hがあることを確認
gccのオプションを調べて、パスが存在することも確認
補足情報(FW/ツールのバージョンなど)
gcc6.3.0
コンパイル時のコマンド(ここが違うとかこうしたらいいとかあったら教えてください)
cmd
1gcc -Wall test.c(ソースファイル名)
回答1件
あなたの回答
tips
プレビュー