Mic*_*ael -2 c git macos linker gcc
git 的第一个版本出现于 2005 年。出于好奇和学习的目的,我试图让它运行。源代码在这里。文件很少,所以看起来很合理,但是由于缺乏 C 细节知识,我陷入了困境。
哪些分步说明可以让它在macOS(最好)或 FreeBSD 上运行,并根据需要修改文件?
使用macOS Big Sur:
Makefile,更改install $(PROG) $(HOME)/bin/为install $(PROG) ./bin/cache.h,添加行#include <string.h>和#include <unistd.h>。brew install opensslln -s ../opt/openssl/include/openssl .make install结果:错误和警告墙,包括"no member named 'st_ctim' in 'struct stat'","no member named 'st_mtim' in 'struct stat'"等等。
使用FreeBSD 12:
Makefile,更改install $(PROG) $(HOME)/bin/为install $(PROG) ./bin/cache.h,添加行#include <string.h>和#include <unistd.h>。make install链接器错误:
/usr/local/bin/ld: read-cache.o:cache.h:64: multiple definition of `sha1_file_directory'; update-cache.o:cache.h:64: first defined here
/usr/local/bin/ld: read-cache.o:cache.h:65: multiple definition of `active_cache'; update-cache.o:cache.h:65: first defined here
/usr/local/bin/ld: read-cache.o:cache.h:66: multiple definition of `active_nr'; update-cache.o:cache.h:66: first defined here
/usr/local/bin/ld: read-cache.o:cache.h:66: multiple definition of `active_alloc'; update-cache.o:cache.h:66: first defined here
/usr/local/bin/ld: update-cache.o: undefined reference to symbol 'SHA1_Init@@OPENSSL_1_1_0'
/usr/local/bin/ld: /lib/libcrypto.so.111: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
*** Error code 1
Run Code Online (Sandbox Code Playgroud)
我遇到了困难,因为我注意到我对 C 和 gcc 的了解太有限,无法继续。有哪些指示可以使其适用于 macOS(最好)或 FreeBSD(否则)?
几乎可以肯定,Git 的原始版本仅针对 Linux,而不针对任何其他系统。因此,可移植性问题可能没有得到解决。
\n这至多是您问题的部分解决方案 \xe2\x80\x94 它应该可以帮助您解决您发现的问题的一个方面。
\n你说:
\n\n\n结果:错误和警告墙,包括“
\nno member named 'st_ctim' in 'struct stat'”、“no member named 'st_mtim' in 'struct stat'”等。
该功能需要定义 macOS 特定的宏:
\n/* To get the 64-bit inode structure with struct timespec elements on Mac OS X */\n#define _DARWIN_USE_64_BIT_INODE\nRun Code Online (Sandbox Code Playgroud)\n结构元素的名称与 POSIX 不一致。在我的代码中,我使用:
\n#define ST_ATIME st_atimespec\n#define ST_BTIME st_birthtimespec\n#define ST_CTIME st_ctimespec\n#define ST_MTIME st_mtimespec\nRun Code Online (Sandbox Code Playgroud)\nPOSIX 变体使用(文件生成时间不是 POSIX 的一部分):
\n#define ST_ATIME st_atim\n#define ST_CTIME st_ctim\n#define ST_MTIME st_mtim\nRun Code Online (Sandbox Code Playgroud)\n对于 macOS 和 POSIX 兼容系统以外的系统,我使用这些(并且成员的类型是time_t,而不是struct timespec):
#define ST_ATIME st_atime\n#define ST_CTIME st_ctime\n#define ST_MTIME st_mtime\nRun Code Online (Sandbox Code Playgroud)\n这是问题的一部分 \xe2\x80\x94 你还必须找到哪里st_ctim使用 etc 的位置并修改代码以处理可移植性问题。例如,一段代码如下:
struct stat *sb;\n\n \xe2\x80\xa6\n\n case 'a':\n pr_format_date(sb->ST_ATIME);\n break;\n case 'c':\n pr_format_date(sb->ST_CTIME);\n break;\n case 'm':\n pr_format_date(sb->ST_MTIME);\n break;\nRun Code Online (Sandbox Code Playgroud)\n被调用的函数被传递 a Time *,其中代码具有以下效果之一:
typedef struct timespec Time;\ntypedef time_t Time;\nRun Code Online (Sandbox Code Playgroud)\n函数体对于何时Timeis astruct timespec和何时 is a具有不同的代码time_t。
| 归档时间: |
|
| 查看次数: |
167 次 |
| 最近记录: |