我正在尝试为net-tools-1.60构建静态二进制文件,因此它们可以在任何系统上自行运行。我从SourceForge下载了net-tools的源代码并应用了3个补丁。然后我用// example data set
var data = new List<Person> {
new Person{FirstName="John", LastName="Smith"},
new Person{FirstName="Jane", LastName="Doe"}
};
data.WhereLike(x=>x.FirstName, "John", "%"); // returns John Smith
data.WhereLike(x=>x.FirstName, "J%", "%"); // returns John Smith and Jane Smith
成功编译。编译后的二进制文件显示为“静态链接”,有些工作,但有些得到“分段错误”。主要是 arp 和路径不起作用。我也试过make SHARED=0 CC='gcc -static'
,但结果二进制文件仍显示“动态链接”。
这是在Ubuntu 16.04上使用4.4.0-64通用内核。任何想法如何使这个工作?
警告
LDFLAGS="--static" make -j 4
崩溃
requires at runtime the shared libraries from the glibc version used for linking
/home/user/Desktop/net-tools-1.60/lib/inet.c:404: warning: Using 'setprotoent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/user/Desktop/net-tools-1.60/lib/inet.c:414: warning: Using 'endprotoent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/user/Desktop/net-tools-1.60/lib/inet.c:386: warning: Using 'getservent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/user/Desktop/net-tools-1.60/lib/inet.c:385: warning: Using 'setservent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/user/Desktop/net-tools-1.60/lib/inet.c:403: warning: Using 'endservent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
GDB
user@ubuntu:~/Desktop/net-tools-1.60$ file arp
arp: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=fc19dbe5121b2a3eb7aee3e6e0fc8de7490d6263, not stripped
user@ubuntu:~/Desktop/net-tools-1.60$ ./arp
Segmentation fault (core dumped)
更新 所以我只是在较旧的Ubuntu 11.10 32bit上构建了这些工具。生成的二进制文件在我的Ubuntu 16.04 64bit上运行正常。我认为16.04可能存在错误。
答案 0 :(得分:1)
已编译的二进制文件显示为&#34;静态链接&#34;和一些工作,但有些得到&#34;分段错误&#34;
这是预期结果(假设崩溃发生在系统构建之外的系统上)。
与流行的看法相反,Linux上的完全 - 静态库 可移植性比动态链接库少。
您应该收到如下链接时间警告:
warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
<强>更新强>
在构建程序的同一系统上不会出现崩溃。此崩溃看起来像GLIBC bug。
最终结果是相同的:不要静态链接;没有好处会出来。