下载源码
编译安装源码
$ ./configure --prefix=/opt/armlib_mipsel/libtar --host=mipsel-openwrt-linux CC=mipsel-openwrt-linux-gcc
$ make
$ make install
全过程问题记录
$ make
.libs/basename.o: could not read symbols: File in wrong format
collect2: error: ld returned 1 exit status
Makefile:79: recipe for target 'libtar.la' failed
make[2]: *** [libtar.la] Error 1
make[2]: Leaving directory '/opt/armsrc/libtar-6d0ab4c/lib'
Makefile:445: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/opt/armsrc/libtar-6d0ab4c'
Makefile:361: recipe for target 'all' failed
make: *** [all] Error 2
问题:编译工具链不匹配,由于我之前用其他工具链编译过。执行make clean后再make
$ make clean
$ make
扩展内容
使用libtar压缩与解压,例子
//压缩
int tarDirToFile(char *srcDir,char *tarName)
{
TAR *pTar;
int r = -1;
char extractTo[] = ".";
if(srcDir==NULL||tarName==NULL){
return -1;
}
r = tar_open(&pTar, tarName, NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU);
if (-1 == r){
tarLog("tar_open failed, reason: %s\n",strerror(errno));
return -1;
}
tar_append_tree(pTar, srcDir, extractTo);
close(tar_fd(pTar));
tarLog("tar -cvf %s %s\r\n",tarName,srcDir);
return 0;
}
//解压
int mgUtarToDir(char *tarName,char *path)
{
TAR *pTar;
int r = -1;
r = tar_open(&pTar, tarName, NULL, O_RDONLY, 0644, TAR_GNU);
if(r == -1)
{
tarLog("tar_open failed, reason: %s\n",strerror(errno));
return -1;
}
tar_extract_all(pTar, path);
tar_close(pTar);
return 0;
}