makefile 在 windows 上与 cygwin 一起工作,但在 ubuntu 上不工作

makefile works with cygwin on windows but not ubuntu

我的 git 存储库中有以下文件夹 - https://github.com/ryu577/base/tree/master/numerical/c/NumericalRecipiesCode/lib

在安装了 cygwin 的 windows 机器上,我可以 运行 在该目录中创建,这会触发命令 -

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 文件。我想这个故事的寓意是 GCC 在 Windows 中生成的二进制文件和可执行文件与 Linux 不兼容(我猜反之亦然)。