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
我正在使用GCC,我需要添加哪些开关才能与Xlib链接?搜索之后,我找到的只是-lX11,但这给了我ld:找不到-lX11的库
I am using a mac (10.6), but I would not like anything that is Mac specific.
我正在使用mac(10.6),但我不喜欢Mac特有的任何东西。
5 个解决方案
#1
33
You can usually use pkg-config
to determine the flags you need to pass:
您通常可以使用pkg-config来确定需要传递的标志:
gcc my-program.c $(pkg-config --cflags --libs x11) -o my-program
#2
4
$ 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.
设置库的搜索路径。
#3
3
You'd be surprised, but sometimes -L/usr/X11R6/lib -lX11
is the answer -_-.
你会感到惊讶,但有时-L / usr / X11R6 / lib -lX11就是答案-_-。
#4
2
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.
你还需要-L / usr / X11 / lib。它不完全是特定于Mac的,但您会发现这些库的位置会因系统而异。
#5
1
Ubuntu 12.10 (And probably others) require sudo apt-get install libx11-dev
.
Ubuntu 12.10(可能还有其他)需要sudo apt-get install libx11-dev。
#1
33
You can usually use pkg-config
to determine the flags you need to pass:
您通常可以使用pkg-config来确定需要传递的标志:
gcc my-program.c $(pkg-config --cflags --libs x11) -o my-program
#2
4
$ 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.
设置库的搜索路径。
#3
3
You'd be surprised, but sometimes -L/usr/X11R6/lib -lX11
is the answer -_-.
你会感到惊讶,但有时-L / usr / X11R6 / lib -lX11就是答案-_-。
#4
2
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.
你还需要-L / usr / X11 / lib。它不完全是特定于Mac的,但您会发现这些库的位置会因系统而异。
#5
1
Ubuntu 12.10 (And probably others) require sudo apt-get install libx11-dev
.
Ubuntu 12.10(可能还有其他)需要sudo apt-get install libx11-dev。