2016-07-06 45 views
-2

試圖運行的libxml2 XML在CLR窗體應用程序創建的文件樣本:LNK2020:無法解析令牌(0A00001F)__imp__xmlFree

#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 

在哪裏的問題?

UPD

加入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 
+0

聽起來像靜態/動態鏈接有問題嗎?你會發現,在libexport.h'/ * * 如果定義(IN_LIBXML)這引發了與MSYS * _imp__xmlFree列爲失蹤MinGW的問題。嘗試解決問題 *在編譯客戶端代碼時也通過聲明。 * /'。我建議你嘗試添加一個靜態鏈接到libxml,就像'-DIN_LIBXML'。 – Gibet

+0

我可以在我的Visual C++中設置DIN_LIBXML? – vico

+0

在Visual Studio中,您可以在property-> linker-> input-> additional depencies中添加.lib,並在property-> linker-> general->其他目錄中添加目錄。這就是您需要添加靜態依賴關係的全部內容。 – Gibet

回答

0

看起來你編譯的libxml2作爲靜態庫。在這種情況下,請嘗試爲您的客戶端代碼定義LIBXML_STATIC宏。另一種選擇是將libxml2編譯爲動態庫,該庫不需要額外的客戶端代碼設置。

永遠不要定義IN_LIBXML宏。