'Unable to link libclang with cmake on VS2017

A while ago I wrote a code generation program to use in my 3D game engine. I added a target to my cmake files, linked libclang with it as I'm using that for parsing the code, and it all worked fine. Recently I added another dependency to my project, which in turn depends on SDL2.

After a lot of struggle I finally managed to get that to work, but suddenly the code generation project would no longer compile, even though I had literally not touched it in a few months. It fails to link, and starts giving errors about undefined symbols, even though I clearly specify the .lib file to link to and give it the correct path. Cmake files for my project are here.

I am using Cmake GUI on windows, generator VS2017 (x64), platform toolset LLVM.

Any insights on this issue are greatly appreciated.

Update: The exact errors I'm getting are simply

1>C:\Program Files (x86)\LLVM\bin\lld-link.exe : error : undefined symbol: __imp_clang_getTranslationUnitCursor
1>>>> referenced by C:\Users\michi_000\Desktop\C++\SaturnEngine\CodeGen\Serialization\main.cpp:128
1>>>>               SerializationCodeGen.dir\Editor\main.obj:(?get_cursor@TranslationUnit@@QEAA?AUCXCursor@@XZ)

For each libclang function I call.



Solution 1:[1]

The issue has been solved. The problem was that my clang installation provided no import library for clang, and I was linking a static library instead. The headers expected an import library which caused it to fail. I generated the import library from the dll and now it works fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MivVG