我使用系統調用編寫了簡單的c程序,使用gcc編譯時它工作正常。但是,當我嘗試使用命令對memset的未定義引用
./sf.py username.c
生成shell代碼(shellforge)我有錯誤,說明
Undefined reference to memset
如何解決這個問題?這是我的代碼
#define O_CREAT 0100
#define O_WRONLY 01
#define O_APPEND 02000
#define IDLEN 100
int main(void)
{
char user_name[IDLEN]="";
char pass1[IDLEN]="";
char pass2[IDLEN]="";
int fd,a,b,c;
//to give user direction
char user[]="Please type your username and hit enter:\n";
char p1[]="Please type password and hit enter:\n";
char p2[]="Please type password and hit enter:\n";
write(1,user,sizeof(user));
a=read(0,user_name,IDLEN);
user_name[a-1]='\0';
while(1)
{
write(1,p1,sizeof(p1));
b=read(0,pass1,IDLEN);
pass1[b-1]='\0';
write(1,p2,sizeof(p2));
c=read(0,pass2,IDLEN);
pass2[c-1]='\0';
int temp=0;
while(pass1[temp] == pass2[temp])
{
if(pass1[temp] == '\0' || pass2[temp] == '\0')
{
break;
}
temp++;
}
if(pass1[temp] == '\0' && pass2[temp] == '\0')
{
break;
}else{
char error[] = "password does not match! please type your password again";
write(1,error,sizeof(error));
}
}
fd = open("user.txt",O_CREAT|O_WRONLY|O_APPEND,0666);
if(fd<0)
{
return 1;
}
char file_user[]="\nUsername:";
char file_pass[]="\nPassword:";
write(fd,file_user,sizeof(file_user)-1);
write(fd,user_name,a-1);
write(fd,file_pass,sizeof(file_pass)-1);
write(fd,pass1,b-1);
}
缺少'#include' –
EOF
包含string.h頭文件。 –
爲什麼? OP不在他的代碼中包含memset。無論如何,OP沒有'write'和'read'包含。爲什麼gcc不會爲此返回錯誤?爲什麼shellforge會爲memset返回一個錯誤,但不是這樣? –