LNK2020:未解析的令牌 (0A00001F) __imp__xmlFree

Posted

技术标签:

【中文标题】LNK2020:未解析的令牌 (0A00001F) __imp__xmlFree【英文标题】:LNK2020: unresolved token (0A00001F) __imp__xmlFree 【发布时间】:2016-07-06 08:53:25 【问题描述】:

尝试在 CLR 表单应用程序中运行 libxml2 XML 创建文档示例:

#pragma once


#include <iconv.h>
#include <libxml\xmlmemory.h>
#include <libxml\parser.h>


#if defined(LIBXML_TREE_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
int
mainas(void)


    xmlNodePtr n;
    xmlDocPtr doc;
    xmlChar *xmlbuff;
    int buffersize;

    /*
     * Create the document.
     */
    doc = xmlNewDoc(BAD_CAST "1.0");
    n = xmlNewNode(NULL, BAD_CAST "root");
    xmlNodeSetContent(n, BAD_CAST "content");
    xmlDocSetRootElement(doc, n);

    /*
     * Dump the document to a buffer and print it
     * for demonstration purposes.
     */
    xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
    printf("%s", (char *) xmlbuff);

    /*
     * Free associated memory.
     */
    xmlFree(xmlbuff);
    xmlFreeDoc(doc);

    return (0);


#else
#include <stdio.h>

int
main(void)

    fprintf(stderr,
            "library not configured with tree and output support\n");
    return (1);

#endif



namespace createXML 

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    
    public:
        Form1(void)
        
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        
            if (components)
            
                delete components;
            
        

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        
        this->SuspendLayout();
        // 
        // Form1
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(608, 374);
        this->Name = L"Form1";
        this->Text = L"Form1";
        this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
        this->ResumeLayout(false);

            
#pragma endregion
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
                 
        ;

有两个链接错误:

1>createXML.obj : error LNK2020: unresolved token (0A00001F) __imp__xmlFree
1>createXML.obj : error LNK2001: unresolved external symbol __imp_xmlFree

问题出在哪里?

更新

添加 IN_LIBXML 后出现链接错误:

1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlversion.h(24): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(103): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(108): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(113): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(119): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(129): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(135): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(140): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(142): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(144): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(146): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(148): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(150): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(152): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(154): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(156): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(158): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(160): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(162): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml\xmlmemory.h(164): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(40): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(42): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(45): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(48): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(50): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(54): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(57): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(60): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(63): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(66): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(70): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(73): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(77): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(80): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(84): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(86): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(89): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(93): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(97): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(102): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(108): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(111): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(113): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(116): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(119): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(122): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(125): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(129): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(131): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlstring.h(133): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(30): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(32): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(34): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(36): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(42): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(46): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(50): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(54): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(57): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/dict.h(63): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(51): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(53): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(54): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(57): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(60): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(74): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(78): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(80): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(84): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(90): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(96): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(113): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(115): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(119): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(121): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(141): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(141): error C4394: 'forbiddenExp' : per-appdomain symbol should not be marked with __declspec(dllexport)
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(142): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(142): error C4394: 'emptyExp' : per-appdomain symbol should not be marked with __declspec(dllexport)
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(147): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(150): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(156): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(159): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(163): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(167): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(171): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(179): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(181): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(183): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(188): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(193): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(198): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(202): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/xmlregexp.h(206): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(597): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(603): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(606): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(609): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(614): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(619): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(622): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(630): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(632): error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
1>D:\CLibs\libxml2-2.6.30.win32\include\libxml/tree.h(632): fatal error C1003: error count exceeds 100; stopping compilation

【问题讨论】:

在哪里可以在我的 Visual C++ 中设置 DIN_LIBXML? 是的,我已经在“附加库目录”中添加了路径,例如 D:\CLibs\libxml2-2.6.30.win32\lib 但这没有帮助 设置 IN_LIBXML 后出现链接错误 - 不能与 /clr:pure 或 /clr:safe 一起使用。 UPD 中的更多详细信息 纯程序集无法导出可从本机代码调用的函数。如果要使用本机 DLL 导出,则需要使用混合模式编译,使用 /clr。另见:msdn.microsoft.com/en-us/library/85344whh.aspx 不过,这有点奇怪。 __declspec(dllexport) 只能在编译库时使用。如果您只是使用该库,则不应定义它。阅读图书馆的文档,了解如何正确使用它。 你编译libxml2是动态库还是静态库? 【参考方案1】:

看起来您将 libxml2 编译为静态库。在这种情况下,请尝试为您的客户端代码定义 LIBXML_STATIC 宏。另一种选择是将 libxml2 编译为不需要对客户端代码进行额外设置的动态库。

永远不要定义 IN_LIBXML 宏。

【讨论】:

以上是关于LNK2020:未解析的令牌 (0A00001F) __imp__xmlFree的主要内容,如果未能解决你的问题,请参考以下文章

错误 LNK2028:未解析的令牌 [重复]

LNK2019:函数“void __cdecl mainfunc(void)”中引用的未解析外部符号 _kiss_fftr_alloc

C++ LNK1120 和 LNK2019 错误:“未解析的外部符号 WinMain@16”

错误 LNK2001:未解析的外部符号

错误 LNK2001:未解析的外部符号 WINAPI [重复]

LNK2019:未解析的外部符号,但我已对函数进行了编码