我已经包含了标题netdb.h,包含在哪里getaddrinfo,但是gcc发出了这个警告:
warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
gcc -m32 -static -s -O2 -std=c99 -D_POSIX_C_SOURCE=200112L myprogram.c
Run Code Online (Sandbox Code Playgroud)
如何静态编译丢失的文件?
可能的解决方案:
可能是glibc安装缺少静态编译所需的相应目标文件.如果是这种情况,请创建相应的目标文件并在编译时链接它.
尝试EGLIBC而不是glibc.
我成功地用dietlibc编译了我的程序,它编译时没有任何错误加上得到的二进制文件比glibc制作的要小得多.
我想提供共享库以及我的程序,而不是由于版本差异而使用目标系统.
ldd 说我的程序使用这些共享库:
linux-gate.so.1 => (0xf7ef0000)**(made by kernel)**
libc.so.6 => /lib32/libc.so.6 (0xf7d88000)**(libc-2.7.so)**
/lib/ld-linux.so.2 (0xf7ef1000)**(ld-2.7.so)**
Run Code Online (Sandbox Code Playgroud)
我通过编译成功链接了ld-xxx.so:
gcc -std=c99 -D_POSIX_C_SOURCE=200112L -O2 -m32 -s -Wl,-dynamic-linker,ld-2.7.so myprogram.c
Run Code Online (Sandbox Code Playgroud)
但我没有成功的链接libc-xxx.so.我怎样才能做到这一点 ?
C99中是否需要功能声明/原型?
我目前正在头文件中定义我的函数,并在主文件中定义#include-ING.在C99中可以吗?
为什么大多数程序员在main()之前声明/原型化函数并在main()之后定义它?是不是更容易在main之前定义它们并避免所有的声明/原型?
header.h文件的内容:
int foo(int foo)
{
// code
return 1;
}
Run Code Online (Sandbox Code Playgroud)
主文件内容:
#include <stdio.h>
#include "header.h"
int main(void)
{
foo(1);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我想在我的Debian lenny桌面而不是glibc上使用OpenBSD的malloc,realloc和free实现.
他们只是简单地替换:他们会在我的Linux桌面上工作吗?
我需要哪些文件以及哪些OpenBSD软件包包含它们?
理论上两种方法中哪一种更快,为什么?(指向字符串的指针必须是常量.)
destination [count]和*destination ++之间的确切区别是什么?目的地[count]是否会在每次通话时从0移动到计数?*destination ++只是在每次通话时加1吗?
char *const string = "Hello world!";
char *destination = malloc(strlen(string) + 1);
int count = 0;
while(string[count] != '\0')
{
destination[count] = string[count];
count++;
}
char *const string = "Hello world!";
char *destination = malloc(strlen(string) + 1);
char *ptr = string;
while(*ptr != '\0')
{
*destination++ = *ptr++;
}
Run Code Online (Sandbox Code Playgroud) 如果在Linux上执行,一个非常小/简单的命令行程序,在符合标准的C99中编程,并在FreeBSD上静态编译是否有效?
(我会自己测试一下,但我目前没有单独的硬盘来测试Linux.)
我找到了这个,但它假设这些单词是空格分隔的.
result="abcdefADDNAME25abcdefgHELLOabcdefgADDNAME25abcdefgHELLOabcdefg"
for word in $result
do
if echo $word | grep -qi '(ADDNAME\d\d.*HELLO)'
then
match="$match $word"
fi
done
Run Code Online (Sandbox Code Playgroud)
POST编辑
为了清晰起见重新命名:
data="abcdefADDNAME25abcdefgHELLOabcdefgADDNAME25abcdefgHELLOabcdefg"
for word in $data
do
if echo $word | grep -qi '(ADDNAME\d\d.*HELLO)'
then
match="$match $word"
fi
done
echo $match
Run Code Online (Sandbox Code Playgroud)
原来左边所以评论询问result继续有意义.