我正在用Android 5(Lollipop)中的Termux用C程序中的GNU readline库编写一个简单的shell程序。 我在编译以下代码时遇到链接器错误。在Android 9'Termux中,相同的代码也可以正常工作。我还验证了readline开发包。
int main(int argc, char** argv)
{
char* buf;
while ((buf = readline("$ ")) != NULL) {
if (strlen(buf) > 0) {
add_history(buf);
}
printf("echo [%s]\n", buf);
free(buf);
}
return 0;
}
编译为:
$ cc -lreadline rl.c
这是链接器错误
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libreadline.so: undefined reference to `malloc@LIBC'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libreadline.so: undefined reference to `fprintf@LIBC'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libreadline.so: undefined reference to `read@LIBC'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libreadline.so: undefined reference to `getenv@LIBC'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libreadline.so: undefined reference to `rename@LIBC'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libreadline.so: undefined reference to `sigdelset@LIBC'
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)