我正在尝试根据Alpine 3.7基本映像构建的docker容器中编译程序。该程序使用class
,并将其包括为argp.h
。我已经安装了argp-standalone并验证了它正在将其安装到映像中。文件#include <argp.h>
位于argp.h
中,但是当我使用以下命令编译程序时:
usr/include
我收到以下错误:
gcc -W -Wall -Wextra -I/usr/include -c -o progname.o progname.c
gcc -largp -o progname progname.o
我有:
- 确保图像上的
progname.o: In function `parse_opt': progname.c:(.text+0x4c9): undefined reference to `argp_failure' progname.c:(.text+0x50f): undefined reference to `argp_failure' progname.c:(.text+0x555): undefined reference to `argp_failure' progname.c:(.text+0x59b): undefined reference to `argp_failure' progname.c:(.text+0x5ce): undefined reference to `argp_error' progname.c:(.text+0x5f4): undefined reference to `argp_error' progname.o: In function `main': progname.c:(.text+0x1397): undefined reference to `argp_parse' collect2: error: ld returned 1 exit status make: *** [Makefile:9: progname] Error 1
版本实际上包括argp.h
,argp_failure
和argp_parse
函数。 - 试图将
argp_error
移至计算机上的不同位置(例如,移至正在进行编译的同一目录中,移至argp.h
中) - 尝试使用
/usr/lib
和-l
进行编译。
映像中还安装了相关的软件包-L
,build-base
和make
。
在Ubuntu映像上编译时,即使没有gcc
和-largp
标志,这些相同的命令也可以正常工作。 Alpine图片中可能会发生什么不同的事情,从而导致此工作不起作用?
修改
根据@Pablo的评论,我现在将其编译如下:
-I/usr/include
在确认静态库gcc -W -Wall -Wextra -I/usr/include -L/usr/lib -c -o progname.o progname.c
gcc -largp -o progname progname.o
位于libargp.a
中之后。但是,相同的问题仍然存在。
编辑2
按以下方式编译(并再次按照@Pablo的建议)已解决我遇到的错误:
/usr/lib
但是,我仍然很好奇为什么使用完全相同的库和指令,当在Ubuntu映像中编译而没有问题时,却无法在Alpine映像中编译。