cygwin make - 对 INT_MAX 和 argp_usage 的 undefined reference

标签 c makefile cygwin

我自己没有编写过这个程序,也没有使用 cygwin 和 linux 的经验,但据我所知,该文件似乎包含正确的内容:

// tsim_argp.c
#include <argp.h>
#include <stdlib.h>
#include <unistd.h>  /* nice */

#include "tsim_argp.h"

包含 argp_usage 的 argp.h 也包含了包含 INT_MAX 的 limit.h 那么我到底错过了什么?我让所有其他 c 文件编译得很好,只是最后一个导致了问题。

进行对话:

...
Making all in src
make[2]: Entering directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
gcc -DHAVE_CONFIG_H -I. -I..    -std=gnu99 -pedantic -Wall -Wextra -Wmissing-pro
totypes -DRESDIR=\"/c/Users/David/Downloads/Train_Simulator/share/tsim\" -g -O2
-MT tsim-tsim_argp.o -MD -MP -MF .deps/tsim-tsim_argp.Tpo -c -o tsim-tsim_argp.o
 `test -f 'tsim_argp.c' || echo './'`tsim_argp.c
tsim_argp.c: In function 'setpriority':
tsim_argp.c:170:19: error: 'INT_MAX' undeclared (first use in this function)
   if( priority == INT_MAX ) {
                   ^
tsim_argp.c:170:19: note: each undeclared identifier is reported only once for e
ach function it appears in
...
Makefile:479: recipe for target 'tsim-tsim_argp.o' failed
make[2]: *** [tsim-tsim_argp.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
Makefile:247: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84'
Makefile:169: recipe for target 'all' failed
make: *** [all] Error 2

如果我将 limit.h 库直接包含在 tsim_argp 中,则进行对话:

...
Making all in src
make[2]: Entering directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
gcc -std=gnu99 -pedantic -Wall -Wextra -Wmissing-prototypes -DRESDIR=\"/c/Users/
David/Downloads/Train_Simulator/share/tsim\" -g -O2 -L/usr/X11R6/lib -lXaw -lXt
-lXmu -lX11 -lXext  -o tsim.exe tsim-AddToggleWidget.o tsim-DialogPopup.o tsim-f
ile.o tsim-resources.o tsim-timer.o tsim-tsim.o tsim-bitmap.o tsim-DrawingPalett
e.o tsim-Graph.o tsim-sound.o tsim-train.o tsim-BitmapDirectory.o tsim-errcheck.
o tsim-pipe.o tsim-Sprite.o tsim-tsim_argp.o  -lXt -lXmu -lXext -lXaw -lX11
tsim-tsim_argp.o: In function `parse_opt':
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:113: undefined refer
ence to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:113:(.text+0xbe): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:83: undefined refere
nce to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:83:(.text+0x10e): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:98: undefined refere
nce to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:98:(.text+0x15c): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:68: undefined refere
nce to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:68:(.text+0x1a3): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:118: undefined refer
ence to `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:118:(.text+0x294): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
tsim-tsim_argp.o:/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:103
: more undefined references to `argp_usage' follow
tsim-tsim_argp.o: In function `parse_opt':
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:103:(.text+0x2c4): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:73:(.text+0x2f4): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:88:(.text+0x324): re
location truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:127:(.text+0x354): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_usage'
tsim-tsim_argp.o: In function `parse':
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:234: undefined refer
ence to `argp_parse'
/cygdrive/c/Users/David/Downloads/tsim-0.84/src/tsim_argp.c:234:(.text+0x429): r
elocation truncated to fit: R_X86_64_PC32 against undefined symbol `argp_parse'
collect2: error: ld returned 1 exit status
Makefile:228: recipe for target 'tsim.exe' failed
make[2]: *** [tsim.exe] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84/src'
Makefile:247: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/David/Downloads/tsim-0.84'
Makefile:169: recipe for target 'all' failed
make: *** [all] Error 2

最佳答案

在 Cygwin 中,argp 看起来是一个单独的库。您需要将 -largp 添加到您的 gcc 行中。

关于cygwin make - 对 INT_MAX 和 argp_usage 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25628910/

相关文章:

C 将链表写入文件

C 编程 - 指针(带增量)

c - 写入缓冲区与直接写入文件

compilation - 如何让make只编译而不链接

c++ - 如何在 Eclipse C++ 项目中创建两个主电源

makefile - 获取包含的 Makefile 中特定于目标的变量

android - Cygwin 设置超过 100%

windows - 用于在 cygwin 中指定动态配置文件名称的命令/语法

c - 为什么 printf 自动将 %x %o %d 转换为十六进制十进制和十进制

git - 无法在 Windows 上使用 Cygwin 启动 Git GUI