繁体   English   中英

我如何在没有源文件的情况下使用静态库(在我的情况下为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_LIBASSIMP_STATIC_LIB的路径。

编辑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 它仍然不起作用,与以前相同的错误。 我的main.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更改为

#include <Importer.hpp>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM