静态编译的openssh不工作
linux吧
全部回复
仅看楼主
level 8
pqy330 楼主
我搞了个内核+busybox的基本系统,想给他加上ssh,因为连glibc都没有,所以最开始的想法当然是静态编译openssh了,但是发现不能用,输入ssh只是丢出一句“No user exists for uid 0”,google“No user exists for uid”,竟然没有任何匹配,难以置信。于是在openssh源码目录搜索“No user exists for uid”,发现打印这句话的原因是调用getpwuid(getuid())时返回NULL。
于是搞了这么个测试代码:
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main(){
struct passwd* pw;
uid_t u;
u=getuid();
printf("%u\n",u);
pw = getpwuid(getuid());
if(pw == NULL)
printf("pw is NULL pointer.\n");
else
printf("pw isnot NULL pointer.\n");
return 0;
}
发现当我动态链接时,打印的是“pw isnot NULL pointer.",改为静态链接时,打印的却是”pw is NULL pointer.",并且静态编译会有警告:Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking。
如果我一定要静态链接,那应该怎么搞?
2014年05月20日 02点05分 1
level 11
不用glibc?
2014年05月20日 02点05分 2
追求极致精简嘛。
2014年05月20日 04点05分
回复 pqy330 :我是说别用glibc,用其它的试试。
2014年05月20日 04点05分
level 1
哥们 解决问题了吗?
我正好也碰到类似的问题,装了个strace , strace ssh,查看调用 库,结果发现libnss_file没有,拷到Lib下再运行ssh就ok 了。
看你这个情况差不多。
2015年07月11日 12点07分 4
level 9
  失去的东西,其实从来未曾真正地属于你,也不必惋惜。
2015年07月11日 16点07分 5
level 14
警告:在静态链接的应用程序中使用'getpwuid'要求在运行时提供来自链接时所使用的glibc版本的共享库……
好像意思是静态链接对'getpwuid'不管用,运行时还是要提供原版本的glibc……
2015年07月11日 16点07分 6
1