-1

I have a libassimp.a file and the header files. How can I use the library?

I'm adding the header files to my project with set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${ASSIMP_INCLUDE_DIR}"). With ASSIMP_INCLUDE_DIR being ../contrib/assimp/include.

Now when I use some class in my main.cpp it gives me errors about undefined references to some funtions, because obviously I don't have the source files.

When I add the libassimp.a to my compile flags I get the following errors when using 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

I don't understand these messages. Maybe they are there because it's trying to access libassimp.a before it's actually there? Is this some kind of concurrency problem?

Anyways, if I call make again then I get different errors, namely a bunch of undefined references to things I am not using, e.g.

../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'

EDIT:

I am compiling with CMake like this:

target_link_libraries(monoRenderer [some other libraries] ${ASSIMP_STATIC_LIB})

ASSIMP_STATIC_LIB is the path to libassimp.a.

EDIT2:

I reduced my CMake file to this:

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)

The header files are in contrib/assimp/include and the libassmip.a is in contrib/assimp/lib. It still doesn't work, same errors as before. My main.cpp looks like this:

#include <assimp/Importer.hpp>
#include <cstdlib>

int main() {
    Assimp::Importer importer;
    return EXIT_SUCCESS;
}

EDIT3:

I think it has something to do with zlib, since all the errors seem to have that in common I think:

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'
gartenriese
  • 4,131
  • 6
  • 36
  • 60
  • Can you post how you compile your project? –  Feb 04 '16 at 16:21
  • You have missed the `cmake` tag. – Basile Starynkevitch Feb 04 '16 at 16:25
  • Using `CMAKE_CXX_FLAGS` directly probably not what you want. You should use `include_directories` to add the include dir. Are you using `${ASSIMP_INCLUDE_DIR}` somewhere else? – mistapink Feb 04 '16 at 16:36
  • I changed it to `include_directories` but I'm getting the same errors, must be something else. Yes, I am using it for my `ExternalProject_Add_Step` to move the headers to the right folder. – gartenriese Feb 04 '16 at 16:43
  • @mistapink: I added a minimal working example of my main.cpp and CMake file. – gartenriese Feb 04 '16 at 16:55
  • Shouldn't your `main.cpp` use `#include `? – RjOllos Feb 04 '16 at 19:44
  • @RjOllos: No, then it would say `fatal error: assimp/include/Importer.hpp: No such file or directory` – gartenriese Feb 05 '16 at 07:39
  • But does `${PROJECT_SOURCE_DIR}/contrib/assimp/include` have a `assimp` sub directory? You may need to add dependencies of assimp as well to link with your project, here zlib. – mistapink Feb 05 '16 at 08:04
  • @mistapink: Yes, adding -lz worked with my reduced example! However my original project now has another error with gtest that I hadn't have before. I don't think the errors are related to, it says that the configure step for 'gtest' doesn't work because a CMake file is missing. – gartenriese Feb 05 '16 at 08:20
  • Break it down to an MVCE and open a new question. – mistapink Feb 05 '16 at 08:25
  • @mistapink: Yes, I will, just found out that it doesn't even work now if I just compile assimp. But adding `-lz` worked to resolve the errors in this question, if you want you can put it in an answer and I'll accept it. – gartenriese Feb 05 '16 at 08:27
  • @mistapink: [Here](http://stackoverflow.com/questions/35219589/building-assimp-3-2-does-not-work-anymore) is my followup question, if you're interested. Should be reproducible this time! :D – gartenriese Feb 05 '16 at 08:45

1 Answers1

1

As you stated yourself you are encountering problems with zlib. You have to add all dependencies from your static library yourself, e.g.:

target_link_libraries(monoRenderer z)

Since you stated that your header are located in contrib/assimp/include you might want to change your include in main.cpp to

#include <Importer.hpp>
mistapink
  • 1,926
  • 1
  • 26
  • 37