Home > OS >  Static library not linking correctly
Static library not linking correctly

Time:08-21

sorry to bother you.

I know this is a commonly asked question and this is probably annoying to get again but I'm just completely stuck and not sure what I'm doing wrong.

I'm following learnopengl.com and trying to add assimp to my CLion project.

I created a new project quickly just so I know nothing is interfering.

I have a folder on my C drive where I placed in assimp library.

I downloaded it by following https://github.com/assimp/assimp/blob/master/Build.md with git and doing

cd assimp
cmake CMakeLists.txt

but changing the BUILD_SHARED_LIBS to OFF

Then I build the library with visual studio 2022 Using "Release x64" and the "Visual Studio 2022 (v143)" toolset

I link to the library with CMake as below. I don't get an error message so I know that CMake finds the library. I also have the location to the library setup in the PATH.

cmake_minimum_required(VERSION 3.22)
project(lemmefixbroken)

set(CMAKE_CXX_STANDARD 20)
set(LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")

add_executable(lemmefixbroken main.cpp)

# assimp
include_directories("C:/dev/libraries/assimp/include")
find_library(ASSIMP_LOCATION NAMES "assimp-vc143-mt" REQUIRED)
message(${ASSIMP_LOCATION})
target_link_libraries(${PROJECT_NAME} "${ASSIMP_LOCATION}")

My compiler settings are as below: (Using the compiler located in Visual Studio 2022 and using the architecture amd64) I've tried all the different architectures but none work. The message returns "C:/dev/libraries/assimp/lib/Release/assimp-vc143-mt.lib" which is where its located

My code is:

#include <iostream>
#include "assimp/Importer.hpp"

int main()
{
    std::cout << "Hello, World!" << std::endl;
    Assimp::Importer import;
    
    return 0;
}

When I build the code I get this error:

"C:\Program Files\JetBrains\CLion 2022.1.1\bin\cmake\win\bin\cmake.exe" --build C:\Users\charl\CLionProjects\lemmefixbroken\cmake-build-release --target all -j 9
[1/2] Building CXX object CMakeFiles\lemmefixbroken.dir\main.cpp.obj
[2/2] Linking CXX executable lemmefixbroken.exe
FAILED: lemmefixbroken.exe 
cmd.exe /C "cd . && "C:\Program Files\JetBrains\CLion 2022.1.1\bin\cmake\win\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\lemmefixbroken.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\link.exe /nologo CMakeFiles\lemmefixbroken.dir\main.cpp.obj  /out:lemmefixbroken.exe /implib:lemmefixbroken.lib /pdb:lemmefixbroken.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console  C:\dev\libraries\assimp\lib\Release\assimp-vc143-mt.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\link.exe /nologo CMakeFiles\lemmefixbroken.dir\main.cpp.obj /out:lemmefixbroken.exe /implib:lemmefixbroken.lib /pdb:lemmefixbroken.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console C:\dev\libraries\assimp\lib\Release\assimp-vc143-mt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:lemmefixbroken.exe.manifest" failed (exit code 1120) with the following output:
assimp-vc143-mt.lib(AssbinLoader.obj) : error LNK2019: unresolved external symbol uncompress referenced in function "public: virtual void __cdecl Assimp::AssbinImporter::InternReadFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct aiScene *,class Assimp::IOSystem *)" (?InternReadFile@AssbinImporter@Assimp@@UEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAUaiScene@@PEAVIOSystem@2@@Z)
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflate referenced in function "public: unsigned __int64 __cdecl Assimp::Compression::decompress(void const *,unsigned __int64,class std::vector<char,class std::allocator<char> > &)" (?decompress@Compression@Assimp@@QEAA_KPEBX_KAEAV?$vector@DV?$allocator@D@std@@@std@@@Z)
assimp-vc143-mt.lib(unzip.obj) : error LNK2001: unresolved external symbol inflate
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateEnd referenced in function "public: bool __cdecl Assimp::Compression::close(void)" (?close@Compression@Assimp@@QEAA_NXZ)
assimp-vc143-mt.lib(unzip.obj) : error LNK2001: unresolved external symbol inflateEnd
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateSetDictionary referenced in function "public: unsigned __int64 __cdecl Assimp::Compression::decompressBlock(void const *,unsigned __int64,char *,unsigned __int64)" (?decompressBlock@Compression@Assimp@@QEAA_KPEBX_KPEAD1@Z)
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateReset referenced in function "public: unsigned __int64 __cdecl Assimp::Compression::decompressBlock(void const *,unsigned __int64,char *,unsigned __int64)" (?decompressBlock@Compression@Assimp@@QEAA_KPEBX_KPEAD1@Z)
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateInit_ referenced in function "public: bool __cdecl Assimp::Compression::open(enum Assimp::Compression::Format,enum Assimp::Compression::FlushMode,int)" (?open@Compression@Assimp@@QEAA_NW4Format@12@W4FlushMode@12@H@Z)
assimp-vc143-mt.lib(Compression.obj) : error LNK2019: unresolved external symbol inflateInit2_ referenced in function "public: bool __cdecl Assimp::Compression::open(enum Assimp::Compression::Format,enum Assimp::Compression::FlushMode,int)" (?open@Compression@Assimp@@QEAA_NW4Format@12@W4FlushMode@12@H@Z)
assimp-vc143-mt.lib(unzip.obj) : error LNK2001: unresolved external symbol inflateInit2_
assimp-vc143-mt.lib(unzip.obj) : error LNK2019: unresolved external symbol crc32 referenced in function unzReadCurrentFile
assimp-vc143-mt.lib(unzip.obj) : error LNK2019: unresolved external symbol get_crc_table referenced in function unzOpenCurrentFile3
lemmefixbroken.exe : fatal error LNK1120: 9 unresolved externals
ninja: build stopped: subcommand failed.

I've tried compiling the library more times than I would like to count. I've tried using the 2019 compiler and nothing. I still get all the same errors. I have no clue what I'm doing wrong but hopefully someone here will know. I've also tried using shared libraries with no success. I've updated Visual Studio 2022 and restarted my computer then compiling again and still nothing changes.

CodePudding user response:

As you can see in the error messages, what failed is the linking process, not the compiling process.

I think your linker could not find the assimp library's '.lib' files.

Did you specify the path to the assimp library's '.lib' files in the project setting?

You could do this in 'VC Directories' or 'Linker/Input', though I'm not sure since I'm not using my computer at the moment.

CodePudding user response:

Why you have used ${PROJECT_NAME}:

target_link_libraries(${PROJECT_NAME} "${ASSIMP_LOCATION}")

You are supposed to use target name here which is lemmefixbroken in your case. Try something like this:

target_link_libraries(lemmefixbroken 
    PRIVATE "${ASSIMP_LOCATION}"
)
  • Related