我的 git 存储库中有以下文件夹 - https://github.com/ryu577/base/tree/master/numerical/c/NumericalRecipiesCode/lib
在安装了 cygwin 的 Windows 计算机上,我可以在该目录中运行 make,这会触发命令 -
gcc -o ../bin/lib/tst_libfns ../obj/nrutil.o ../obj/fileio.o ../obj/tst_libfns.o -I ../include -lm
这会将 tst_libfns.o 和 fileio.o 放入 obj 目录中。
现在,我将此存储库拉到我的 ubuntu 机器中并尝试了同样的操作。但是,当在那里生成相同的命令时,它会给出以下错误:
gcc -o ../bin/lib/tst_libfns ../obj/nrutil.o ../obj/fileio.o ../obj/tst_libfns.o -I../include -lm
../obj/fileio.o:fileio.c:(.text+0x52): undefined reference to `__getreent'
../obj/tst_libfns.o:tst_libfns.c:(.text+0x10): undefined reference to `__main'
collect2: error: ld returned 1 exit status
make: *** [../bin/lib/tst_libfns] Error 1
我是否遗漏了一些明显的东西?
最佳答案
我刚刚想通了。我已经通过 obj 目录中的 git 拉入了 .o 文件,并且 gcc 以某种方式尝试使用现有文件(已在 Cygwin + Windows 中生成)。不知何故,那些 .o 文件似乎与 linux 不兼容。当我删除它们并再次运行 make 命令时,会重新生成 .o 文件。我想这个故事的寓意是 Windows 中 GCC 生成的二进制文件和可执行文件与 Linux 不兼容(我猜反之亦然)。
关于c - makefile 在 Windows 上适用于 cygwin,但不适用于 ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36672375/