What do I need to do to link with xlib?

2019-03-17 12:14发布

I am using GCC, what switches do I need to add to link with Xlib? After searching, all I could find was -lX11, but that gave me ld: library not found for -lX11

I am using a mac (10.6), but I would not like anything that is Mac specific.

标签: c gcc x11 xlib
5条回答
一纸荒年 Trace。
2楼-- · 2019-03-17 12:22

You can usually use pkg-config to determine the flags you need to pass:

gcc my-program.c $(pkg-config --cflags --libs x11) -o my-program
查看更多
做个烂人
3楼-- · 2019-03-17 12:34
$ locate libX11
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.6.2.dylib
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.6.dylib
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.a
/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/libX11.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.6.2.0.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.6.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libX11.dylib
/usr/X11/lib/libX11.6.2.0.dylib
/usr/X11/lib/libX11.6.dylib
/usr/X11/lib/libX11.dylib
/usr/X11/lib/libX11.la

I'd try

gcc [...] -L/usr/X11/lib -lX11 [...]

to set the search path for libraries.

查看更多
男人必须洒脱
4楼-- · 2019-03-17 12:35

You also need -L/usr/X11/lib. It's not exactly Mac-specific, but you will find that the location of these libs will vary a bit from system to system.

查看更多
The star\"
5楼-- · 2019-03-17 12:39

You'd be surprised, but sometimes -L/usr/X11R6/lib -lX11 is the answer -_-.

查看更多
Evening l夕情丶
6楼-- · 2019-03-17 12:45

Ubuntu 12.10 (And probably others) require sudo apt-get install libx11-dev.

查看更多
登录 后发表回答