2016-07-06 2 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) { 
       } 
     }; 
} 

Got две связывающие ошибки:

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), это вызывает проблемы с mingw с msys * _imp__xmlFree перечислены как отсутствующие. Попытайтесь обходить проблему *, также делая это объявление при компиляции клиентского кода. */'. Я предлагаю вам попробовать добавить статическую ссылку на libxml, что-то вроде '-DIN_LIBXML'. – Gibet

+0

где я могу установить DIN_LIBXML в Visual C++? – vico

+0

В Visual Studio вы добавляете .lib in property-> linker-> input-> дополнительные атрибуты и добавляете каталог в каталог свойств-> linker-> general-> дополнительные. Это все, что вам нужно, чтобы добавить статическую зависимость. – Gibet

ответ

0

Похоже, вы собрали libxml2 в виде статической библиотеки. В этом случае попробуйте определить макрос LIBXML_STATIC для вашего кода клиента. Другим вариантом является компиляция libxml2 в качестве динамической библиотеки, которая не требует дополнительных настроек для кода клиента.

Никогда не задавайте макрос IN_LIBXML.

Смежные вопросы