Link to home
Start Free TrialLog in
Avatar of willem_liu
willem_liu

asked on

Can't use Xerces-C. Compilation Error.

This is the code snippet I want to compile called sample1.c:

======================================================================================
#include <xercesc/dom/DOM.hpp>

// Other include files, declarations, and non-Xerces-C++ initializations.

#if defined(XERCES_NEW_IOSTREAMS)
#include <iostream>
#else
#include <iostream.h>
#endif

#ifdef XERCES_CPP_NAMESPACE_USE
XERCES_CPP_NAMESPACE_USE
#endif

int main(int argc, char* argv[])
{
      try {
            XMLPlatformUtils::Initialize();
      }
      catch (const XMLException& toCatch)
      {
            // Do your failure processing here
            return 1;
      }

      // Do your actual work with Xerces-C++ here.

      XMLPlatformUtils::Terminate();

      // Other terminations and cleanup.
      return 0;
}
======================================================================================

I've already installed Xerces C correctly as I could compile all the Samples that were included with the Xerces C library.

I get the following error if I use the following makefile to compile the above code:

======================================================================================
gmake
g++ -L/usr/il_kernel/xerces/xerces-c-src_2_7_0/lib/libxerces-c.so -I/usr/il_kernel/xerces/xerces-c-src_2_7_0/src sample1.c -o sample1
/tmp/ccUYy9te.o: In function `main':
/tmp/ccUYy9te.o(.text+0x17): undefined reference to `xercesc_2_7::XMLUni::fgXercescDefaultLocale'
/tmp/ccUYy9te.o(.text+0x1c): undefined reference to `xercesc_2_7::XMLPlatformUtils::Initialize(char const *, char const *, xercesc_2_7::PanicHandler *, xercesc_2_7::MemoryManager *, bool)'
/tmp/ccUYy9te.o(.text+0x31): undefined reference to `xercesc_2_7::XMLPlatformUtils::Terminate(void)'
/tmp/ccUYy9te.o(.text+0x49): undefined reference to `xercesc_2_7::XMLException type_info function'
collect2: ld returned 1 exit status
gmake: *** [sample1] Error 1
======================================================================================

Do you know what I'm doing wrong here?
Avatar of Dragon_Krome
Dragon_Krome

you have the wrong parameters:

-L specifies the directory where to look for the shared library, therefore your cmdline should look like :

g++ -L/usr/il_kernel/xerces/xerces-c-src_2_7_0/lib -lxerces-c.so -I/usr/il_kernel/xerces/xerces-c-src_2_7_0/src sample1.c -o sample1
ASKER CERTIFIED SOLUTION
Avatar of Dragon_Krome
Dragon_Krome

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of willem_liu

ASKER

I'll be trying it and see how it works.
Thanks alot for your help! I can't imagine how simple this actually was:D