在 Visual Studio 中尝试 link libclang 时出现链接错误
Linking errors when trying to link libclang in Visual Studio
我想做的是构建这个库:
https://github.com/AustinBrunkhorst/CPP-Reflection
一切顺利,直到我链接到发生这种情况的 libclang:
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_CXXMethod_isStatic
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorType
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_Cursor_getMangling
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCXXAccessSpecifier
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_Cursor_getStorageClass
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorSpelling
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_visitChildren
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getTypedefDeclUnderlyingType
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorDisplayName
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_CXXMethod_isConst
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_isCursorDefinition
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorLexicalParent
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorResultType
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_isConstQualifiedType
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getNumArgTypes
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getTypeDeclaration
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getTypeSpelling
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getArgType
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getCanonicalType
1>MetaUtils.obj : error LNK2001: unresolved external symbol __imp_clang_disposeString
1>MetaUtils.obj : error LNK2001: unresolved external symbol __imp_clang_getCString
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_getTranslationUnitCursor
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_createTranslationUnitFromSourceFile
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_createIndex
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_disposeIndex
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_disposeTranslationUnit
我正在构建 64 位版本,并且我也在 64 bit/release 模式下从源手动构建 llvm/clang。
我不知道这是否重要 (?),但我正在使用来自 github 的 clang 主分支。考虑到链接阶段之前一切都过去了,我认为,master 分支应该没问题。
我正在使用 Visual Stduio 2015。
在项目选项中,我添加了附加库目录以指向 clang 具有 *.lib 文件的位置。
除了在 Linker ->additional library directories
中指定它们的路径外,您还需要在属性对话框的 Linker->Input->Additional Dependencies
部分中明确列出要链接到的特定 .lib
文件。
此外,请再次检查您的 lib 文件的路径和版本是否正确(x86 与 x64)。
在没有 lib 文件的情况下,链接器无法将名称(符号)解析为其实现,因此出现 unresolved symbol
链接器错误。
如果您有兴趣进一步了解,这里有一个很好的资源 - http://www.lurklurk.org/linkers/linkers.html
我想做的是构建这个库: https://github.com/AustinBrunkhorst/CPP-Reflection 一切顺利,直到我链接到发生这种情况的 libclang:
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_CXXMethod_isStatic
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorType
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_Cursor_getMangling
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCXXAccessSpecifier
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_Cursor_getStorageClass
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorSpelling
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_visitChildren
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getTypedefDeclUnderlyingType
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorDisplayName
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_CXXMethod_isConst
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_isCursorDefinition
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorLexicalParent
1>Cursor.obj : error LNK2001: unresolved external symbol __imp_clang_getCursorResultType
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_isConstQualifiedType
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getNumArgTypes
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getTypeDeclaration
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getTypeSpelling
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getArgType
1>CursorType.obj : error LNK2001: unresolved external symbol __imp_clang_getCanonicalType
1>MetaUtils.obj : error LNK2001: unresolved external symbol __imp_clang_disposeString
1>MetaUtils.obj : error LNK2001: unresolved external symbol __imp_clang_getCString
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_getTranslationUnitCursor
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_createTranslationUnitFromSourceFile
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_createIndex
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_disposeIndex
1>ReflectionParser.obj : error LNK2001: unresolved external symbol __imp_clang_disposeTranslationUnit
我正在构建 64 位版本,并且我也在 64 bit/release 模式下从源手动构建 llvm/clang。 我不知道这是否重要 (?),但我正在使用来自 github 的 clang 主分支。考虑到链接阶段之前一切都过去了,我认为,master 分支应该没问题。
我正在使用 Visual Stduio 2015。
在项目选项中,我添加了附加库目录以指向 clang 具有 *.lib 文件的位置。
除了在 Linker ->additional library directories
中指定它们的路径外,您还需要在属性对话框的 Linker->Input->Additional Dependencies
部分中明确列出要链接到的特定 .lib
文件。
此外,请再次检查您的 lib 文件的路径和版本是否正确(x86 与 x64)。
在没有 lib 文件的情况下,链接器无法将名称(符号)解析为其实现,因此出现 unresolved symbol
链接器错误。
如果您有兴趣进一步了解,这里有一个很好的资源 - http://www.lurklurk.org/linkers/linkers.html