Can't use Xerces-C. Compilation Error.

Posted on 2006-05-05
Last Modified: 2012-06-21
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.

#include <iostream>
#include <iostream.h>


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

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


      // 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:

g++ -L/usr/il_kernel/xerces/xerces-c-src_2_7_0/lib/ -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?
Question by:willem_liu
    LVL 5

    Expert Comment

    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 -I/usr/il_kernel/xerces/xerces-c-src_2_7_0/src sample1.c -o sample1
    LVL 5

    Accepted Solution

    Ups, my fault, this should do it:

    g++ -L/usr/il_kernel/xerces/xerces-c-src_2_7_0/lib -lxerces-c -I/usr/il_kernel/xerces/xerces-c-src_2_7_0/src sample1.c -o sample1

    Author Comment

    I'll be trying it and see how it works.

    Author Comment

    Thanks alot for your help! I can't imagine how simple this actually was:D

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now