我正在尝试用一个简单的“Hello world”类型的应用程序编译这个库(MinilibX),但是我得到以下错误:
$ make -C mlx
$ gcc main.c -I. -Lmlx -lmlx ./mlx/libmlx_Darwin.a -framework OpenGL -framework Appkit
Undefined symbols for architecture arm64:
"_XChangeWindowAttributes", referenced from:
_mlx_int_set_win_event_mask in libmlx.a(mlx_int_set_win_event_mask.o)
"_XCreateColormap", referenced from:
_mlx_init in libmlx.a(mlx_init.o)
"_XCreateGC", referenced from:
_mlx_new_window in libmlx.a(mlx_new_window.o)
"_XCreateWindow", referenced from:
_mlx_new_window in libmlx.a(mlx_new_window.o)
"_XGetVisualInfo", referenced from:
_mlx_int_get_visual in libmlx.a(mlx_int_get_visual.o)
"_XGetWMNormalHints", referenced from:
_mlx_int_anti_resize_win in libmlx.a(mlx_int_anti_resize_win.o)
"_XInternAtom", referenced from:
_mlx_init in libmlx.a(mlx_init.o)
"_XMapRaised", referenced from:
_mlx_new_window in libmlx.a(mlx_new_window.o)
"_XNextEvent", referenced from:
_mlx_loop in libmlx.a(mlx_loop.o)
"_XOpenDisplay", referenced from:
_mlx_init in libmlx.a(mlx_init.o)
"_XPending", referenced from:
_mlx_loop in libmlx.a(mlx_loop.o)
"_XPutBackEvent", referenced from:
_mlx_int_wait_first_expose in libmlx.a(mlx_int_wait_first_expose.o)
"_XSetWMNormalHints", referenced from:
_mlx_int_anti_resize_win in libmlx.a(mlx_int_anti_resize_win.o)
"_XSetWMProtocols", referenced from:
_mlx_new_window in libmlx.a(mlx_new_window.o)
"_XShmPixmapFormat", referenced from:
_mlx_int_deal_shm in libmlx.a(mlx_init.o)
"_XShmQueryVersion", referenced from:
_mlx_int_deal_shm in libmlx.a(mlx_init.o)
"_XStoreName", referenced from:
_mlx_new_window in libmlx.a(mlx_new_window.o)
"_XSync", referenced from:
_mlx_loop in libmlx.a(mlx_loop.o)
"_XWindowEvent", referenced from:
_mlx_int_wait_first_expose in libmlx.a(mlx_int_wait_first_expose.o)
"_XkbKeycodeToKeysym", referenced from:
_mlx_int_param_KeyPress in libmlx.a(mlx_int_param_event.o)
_mlx_int_param_KeyRelease in libmlx.a(mlx_int_param_event.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
海湾合作委员会:
$ gcc -v
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
我不知道我是否链接错误,或者版本/编译器之间是否存在冲突(据我所知,minilibx 使用 GCC)...
这里是一个最小复制:https://github.com/herbievine/42/tree/so_long/so_long
运行:
git clone https://github.com/herbievine/42.git -b so_long
cd 42/so_long
git clone https://github.com/42Paris/minilibx-linux.git mlx
make
喜欢@n.m。建议,将我的代码与 X11 链接解决了这个问题。
我的 Makefile 看起来像这样:
MLX_DIR = ./mlx
MLX_LIB = $(MLX_DIR)/libmlx_$(UNAME).a
MLX_FLAGS = -Lmlx -lmlx -framework OpenGL -framework AppKit
# added this line
X11_FLAGS = -L/usr/X11/lib -lXext -lX11
SRCS = \
main.c \
OBJS = $(SRCS:.c=.o)
all: $(MLX_LIB) $(NAME)
.c.o:
$(CC) $(CFLAGS) -Imlx -c -o $@ $<
$(NAME): $(OBJS) # link here
$(CC) $(CFLAGS) $(MLX_FLAGS) $(X11_FLAGS) -o $(NAME) $(OBJS)
$(MLX_LIB):
@make -C $(MLX_DIR)