C++ Linux下如何使用libtar
我已经下载并安装了libtar。 我已正确添加头文件( #include
)。 我使用 KDevelop,当我开始输入函数 tar_append_tree 和 tar_open 时,它会自动识别它们。 我将 cmake 与 KDevelop 结合使用(作为创建新项目时的一个选项),到目前为止,所有需要链接的内容(pthreads、共享内存和数学)我所要做的就是在 CMAKE_EXE_LINKER_FLAGS 中添加适当的标志。我知道 libtar 需要 -ltar 才能工作,但我仍然得到:对 tar_open 的未定义引用,对 tar_append_tree 的未定义引用。 有人可以帮忙吗?我不知道有任何其他 tar 库,并且我确实需要在压缩之前在 tarball 中组织数千个 xml 文件。
编辑:我现在发现 libarchive 应该比 libtar 好得多。然而我在这里遗漏了一些东西。我如何明确告诉 KDevelop/Cmake 如何链接这些库? libarchive 没有链接标志(至少我在谷歌上找不到),当我尝试编译时,我再次得到对导入函数的未定义引用。
谢谢你!
I have downloaded and installed libtar.
I have added the header file correctly ( #include <libtar.h>
).
I use KDevelop, which automatically recognizes the functions tar_append_tree and tar_open when I start typing them.
I use cmake with KDevelop (as an option when creating a new project), and so far everything that needed linking (pthreads,shared memory and math) all I had to do was add the appropriate flag in CMAKE_EXE_LINKER_FLAGS. I know that libtar needs -ltar in order to work, but I still get: undefined reference to tar_open , undefined reference to tar_append_tree.
Can anyone please help ? I am not aware of any other tar library, and I really need to organize thousands of xml files in a tarball prior to compressing.
edit: I have now found libarchive which is supposed to be much better than libtar. However I am missing something here. How do I explicitly tell KDevelop/Cmake how to link with those libraries ? There is no link flag for libarchive (at least not one I could find on google) and again when I try to compile I get undefined references to the imported functions.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确信解决方案不止一种,但这是我的。 创建了两个文件
/usr/lib/pkgconfig 中的
cmake/Modules/
libtar.pc
FindLIBTAR.cmake
FindLIBTAR.cmake
libtar.pc
FindLIBTAR.cmake
使用 pkgconfig 查找libtar
库和libtar.pc< pkgconfig 使用 /code> 来查找库。如果您不想将 cmake 文件放在项目目录中,则可以将 cmake 文件放在 CMake 放置所有查找文件的同一位置 (
/usr/share/cmake/Modules/
)。如果您确实将其保留在项目文件夹中,则需要通过以下方式将其添加到CMAKE_MODULE_PATH
中:I'm sure there is more than one solution, but here is mine. I created two files
FindLIBTAR.cmake
in my project's folder undercmake/Modules/
libtar.pc
in/usr/lib/pkgconfig
FindLIBTAR.cmake
libtar.pc
The
FindLIBTAR.cmake
uses pkgconfig to find thelibtar
library andlibtar.pc
is used by pkgconfig to find the library. You can place the cmake file in the same place where CMake places all find files (/usr/share/cmake/Modules/
) if you don't want to put it in your project's directory. If you do keep it in your project's folder, you will need to add that toCMAKE_MODULE_PATH
via: