尝试在CLR表单应用程序中运行libxml2 XML create document sample:
#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 :(得分:0)
看起来您将 libxml2 编译为静态库。在这种情况下,请尝试为客户端代码定义LIBXML_STATIC
宏。另一种选择是将 libxml2 编译为动态库,不需要对客户端代码进行额外设置。
不要定义IN_LIBXML
宏。