如何在没有源文件的情况下使用静态库(在我的例子中是 assimp)
How do I use a static library (in my case assimp) without the source files
我有一个libassimp.a文件和头文件。如何使用图书馆?
我正在使用set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${ASSIMP_INCLUDE_DIR}")
将头文件添加到我的项目中。随着ASSIMP_INCLUDE_DIR是../contrib/assimp/include.
现在,当我在main中使用某个类时.cpp它会给我一些关于对某些功能的未定义引用的错误,因为显然我没有源文件。
当我将 libassimp.a 添加到我的编译标志时,我在使用 make 时出现以下错误:
make[3]: *** No rule to make target `../contrib/assimp/lib/libassimp.a',
...
main.cpp:7:32: fatal error: assimp/Importer.hpp: No such file or directory
....
Linking CXX static library libassimp.a
我不明白这些信息。也许他们在那里是因为它试图在它实际存在之前访问libassimp.a?这是某种并发问题吗?
无论如何,如果我再次调用make
,则会出现不同的错误,即对我没有使用的东西的大量未定义的引用,例如
../contrib/assimp/lib/libassimp.a(AssbinLoader.cpp.o): In function `Assimp::AssbinImporter::InternReadFile(std::string const&, aiScene*, Assimp::IOSystem*)':
AssbinLoader.cpp:(.text+0x2a49): undefined reference to `uncompress'
编辑:
我用CMake编译是这样的:
target_link_libraries(monoRenderer [some other libraries] ${ASSIMP_STATIC_LIB})
ASSIMP_STATIC_LIB
是通往libassimp.a的道路。
编辑2:
我将我的 CMake 文件简化为:
cmake_minimum_required(VERSION 2.8.12)
project(monoRenderer)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
file(GLOB_RECURSE CXX_SRCS src/*.cpp)
file(GLOB_RECURSE C_SRCS src/*.c)
file(GLOB_RECURSE HPP_HDRS src/*.hpp)
file(GLOB_RECURSE H_HDRS src/*.h)
set(SRCS "${C_SRCS};${CXX_SRCS}")
set(HDRS "${H_HDRS};${HPP_HDRS}")
include_directories(${PROJECT_SOURCE_DIR}/contrib/assimp/include)
add_executable(monoRenderer ${SRCS} ${HDRS})
target_link_libraries(monoRenderer ${PROJECT_SOURCE_DIR}/contrib/assimp/lib/libassimp.a)
头文件在contrib/assimp/include
中,libassmip.a 在contrib/assimp/lib
中。它仍然不起作用,与以前相同的错误。我的主.cpp看起来像这样:
#include <assimp/Importer.hpp>
#include <cstdlib>
int main() {
Assimp::Importer importer;
return EXIT_SUCCESS;
}
编辑3:
我认为这与 zlib 有关,因为我认为所有错误似乎都有共同点:
undefined reference to `uncompress'
undefined reference to `inflateInit2_'
undefined reference to `inflate'
undefined reference to `inflateEnd'
undefined reference to `inflateReset'
undefined reference to `inflateSetDictionary'
undefined reference to `get_crc_table'
undefined reference to `crc32'
正如你自己所说,你遇到了zlib的问题。您必须自己添加静态库中的所有依赖项,例如:
target_link_libraries(monoRenderer z)
由于您声明标题位于contrib/assimp/include
您可能希望将包含main.cpp
更改为
#include <Importer.hpp>
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- cmake在我的项目中所需的所有静态库都不成功
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 为什么我的for循环不能正确获取argv
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 0-1背包代码中的错误.我的代码中有什么错误
- 当我的阵列太大时出现分段错误
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 为什么二进制搜索在我的测试中不起作用
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- OpenGL在启用深度测试时不会丢弃我的碎片
- 为什么我的 std::ref 无法按预期工作?
- clang整洁10忽略了我的NOLINT命令
- 如何在没有源文件的情况下使用静态库(在我的例子中是 assimp)