0

I'm attempting to use the pugiXML library to read some XML, and I can't get it to compile correctly. After moving the source files(3) into the working directory, bringing them into the project, and disabling the use of precompiled headers, I have been having a hard time trying to get it to link and build.

These are the snippets giving me problems:

// XMLAdapter.h

#pragma once
#include "pugixml.hpp"

using namespace pugi;
class XMLAdapter
{
private:
    static xml_document doc;
    static bool isReady;
    static xml_parse_result result;
public:
    static void setResource(char* resource);
    template <typename T> static T getItems(char* xpath, T (*getThings)(xpath_node_set*));
};

.

// XMLAdapter.cpp

#include "stdafx.h"
#include "XMLAdapter.h"


bool XMLAdapter::isReady = false;

void XMLAdapter::setResource(char* resource){
    XMLAdapter::result = XMLAdapter::doc.load_file(resource);
    XMLAdapter::isReady = true;
}

and the errors:

  • Error 1 error LNK2001: unresolved external symbol "private: static class pugi::xml_document XMLAdapter::doc" (?doc@XMLAdapter@@0Vxml_document@pugi@@A) C:\Users\Adam\SkyDrive\Documents\proj\ray\ray\XMLAdapter.obj ray
  • Error 2 error LNK2001: unresolved external symbol "private: static struct pugi::xml_parse_result XMLAdapter::result" (?result@XMLAdapter@@0Uxml_parse_result@pugi@@A) C:\Users\Adam\SkyDrive\Documents\proj\ray\ray\XMLAdapter.obj ray
  • Error 3 error LNK1120: 2 unresolved externals C:\Users\Adam\SkyDrive\Documents\proj\ray\Debug\ray.exe 1 1 ray

I'm fairly new to C++, so any advice would be welcome;

AdamSpurgin
  • 951
  • 2
  • 8
  • 28
  • Where are the other statics ? I don't see them in this source file; only `isReady` seems to be both declared *and* defined. – WhozCraig Feb 23 '14 at 02:06
  • Do they all need to be defined at compile-time? – AdamSpurgin Feb 23 '14 at 02:19
  • They're class variables (i.e. not instance variables). The need to be defined *somewhere* if they're referenced by *anything*, and they are in this case. You can see how `isReady` is accounted for above the `setResource` member in the .cpp file. The same must be so for the other statics. – WhozCraig Feb 23 '14 at 02:29
  • Ah, I see. I assumed it worked like C did and threw garbage in it if left alone. – AdamSpurgin Feb 23 '14 at 02:51

0 Answers0