build trouble with simple xerces code

Hi folks,

I'm new to C++, although quite proficient in MATLAB. Gone through tutorials, done hello world and variations...

But.. I'm trying to write some code to use Xerces C++ XML parser source, but am getting conflicting feedback whether the include file is found or not in the include path. I'm using NetBeans 7 IDE, updated today.

What I've done so far is download Xerces, extract to '/usr/local/include/xerces-c-3.1.1' and ran ./configure. Also, I added '/usr/local/include/xerces-c-3.1.1/src' to NetBeans' tools>options>code assistance>C++>Include folders.

Here's my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <xercesc/util/PlatformUtils.hpp>
using namespace xercesc;

int main(int argc, char* argv[])
{
  try {
    XMLPlatformUtils::Initialize();
  }
  catch (const XMLException& toCatch) {
    // bad init
    return 1;
  }
  XMLPlatformUtils::Terminate();
  return 0;
}


When building, I get the error at line 1:
"main.cpp:1:42: fatal error: xercesc/util/PlatformUtils.hpp: No such file or directory"

what is confusing to me is that obviously netbeans sees the file, because if I hold ctrl and click on line 1, NetBeans opens up PlatformUtils.hpp in another tab. so, that header is obviously being found by NB, but I'm not sure why it throws an error during build?

Previously I had not properly put the xerces files in the right include path, and I was also seeing errors on line 2, because namespace wasn't properly defined. However, I know the include path must be set correctly because those code warnings are gone too.

any ideas why netbeans sees the file and can open it in the IDE, but fails to build claiming it is not there?

Thanks,
Brian


brneuro wrote:
What I've done so far is download Xerces, extract to '/usr/local/include/xerces-c-3.1.1' and ran ./configure.


That sounds to me like you didn't follow the instructions properly. You should delete the '/usr/local/include/xerces-c-3.1.1' directory.

Extract the Xerces archive somewhere in your home directory. Then follow these instructions:
http://xerces.apache.org/xerces-c/build-3.html#UNIX

To summerise, cd into the directory, then type:
1
2
3
4
5
./configure
make
su
make install
exit

Note that before you type make insall you will need to switch user to root su and then exit out of root after.
Last edited on
Thanks, Galik.

The instructions are not totally step by step, and assume that one understands the process and utility of building... I figured that since I was using xerces source that I wouldn't need to compile it, just configure... obviously I don't get why one needs to build to use source?

Anyway, I had tried those steps before, and I redid them now so we're on the same page... while it resolve the error in my first post, it results in other build problems. so full circle here, and this is where I am at:

error at line 7, and hovering the cursor over it reveals "unable to resolve identifier initialize"

main.cpp:7: undefined reference to `xercesc_3_1::XMLUni::fgXercescDefaultLocale'
main.cpp:7: undefined reference to `xercesc_3_1::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_1::PanicHandler*, xercesc_3_1::MemoryManager*)'
main.cpp:13: undefined reference to `xercesc_3_1::XMLPlatformUtils::Terminate()'

but again, it says it can't resolve initialize, but I can control+click and it takes me to line 173 of PlatformUtils.hpp where 'initialize' is, and then from that line a ctrl+click on 'fgXercescDefaultLocale' takes me to XMLUni.hpp line 297 where I see "static const char fgXercescDefaultLocale[];"
Those look like link errors. I don't use NetBeans but there must be some way to specify the library to link with. It is probably around the same place you specify the include headers.

The library I think you need to specify is "xerces-c".

Basically Xerces is a binary library with headers to allow your project to link with it. This is why you need to compile it first and then tell your project which library to link with.
Topic archived. No new replies allowed.