Fei Su
Fei Su

Reputation: 9

Undefined reference error when link to Saxon library in C++

I download the latest SaxonC-HE for Linux library from https://www.saxonica.com/download/c.xml

Then from the above website, I follow copy libsaxon-hec-12.4.1 to /usr/local/lib And start writing code. When compile the code in C++, I got error:

Undefined reference to 'SaxonProcessor::newXQueryProcessor' etc

In my qmake file, I add LIBS += -lsaxon-hec-12.4.1

Pseudo code:

#include SaxonProcessor.h
SaxonProcess *processor = new SaxonProcessor(false);
XQueryProcessor *query = processor->newXQueryProcessor();
query->setQueryContent(content);
query->setParameters(parameter, XdmValue);
const char *result = query->runQueryToString();

I am wondering if I need to compile the saxonc library myself and generate lib files so I can link to. But there is no make file from the downloaded SaxonC folder

Upvotes: -3

Views: 164

Answers (2)

Fei Su
Fei Su

Reputation: 9

Fixed the error by adding saxon source files into my project.

Upvotes: 0

Martin Honnen
Martin Honnen

Reputation: 167401

Well, if you look at the samples then you will certainly see, that to compile e.g. testXQuery.cpp, the build64-linux.sh file compiles a lot of files from Saxon.C.API before and links them, i.e. in https://saxonica.plan.io/projects/saxonmirrorhe/repository/he/revisions/he_mirror_saxon_12_4_1/entry/src/main/c/samples/cppTests/build64-linux.sh you see

#!/bin/sh

#Build file for SaxonC on C++


export SAXON_ERRORS="-Wall -Werror -Wextra"


export TURN_ERRORS_TO_WARNINGS="-Wno-error=sizeof-pointer-memaccess -Wno-error=unused-value -Wno-error=extra -Wno-error=reorder -Wno-error=sign-compare -Wno-error=unused-variable -Wno-error=unused-parameter -Wno-error=return-type -Wno-error=unused-but-set-variable"

rm -r bin
mkdir -p bin

gcc -m64  -g   -fPIC -I../../Saxon.C.API/graalvm -c ../../Saxon.C.API/SaxonCGlue.c -o bin/SaxonCGlue.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@ $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

gcc -m64  -g  -fPIC  -I../../Saxon.C.API/graalvm -c ../../Saxon.C.API/SaxonCXPath.c -o bin/SaxonCXPath.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@ $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2



#g++  -std=c++14 -fPIC -m64  -g  -c cppExtensionFunction.cpp -o bin/cppExtensionFunction.o $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2
g++ -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/XdmValue.cpp -o bin/XdmValue.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@ $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++ -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/XdmItem.cpp -o bin/XdmItem.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@ $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2



g++  -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/XdmNode.cpp -o bin/XdmNode.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@ $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++ -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm -c ../../Saxon.C.API/XdmMap.cpp -o bin/XdmMap.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@ $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++ -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm -c ../../Saxon.C.API/XdmArray.cpp -o bin/XdmArray.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@ $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++ -std=c++14 -m64  -g   -fPIC -I../../Saxon.C.API/graalvm -c ../../Saxon.C.API/XdmFunctionItem.cpp -o bin/XdmFunctionItem.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++  -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/XdmAtomicValue.cpp -o bin/XdmAtomicValue.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++  -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/DocumentBuilder.cpp -o bin/DocumentBuilder.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++  -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/SaxonProcessor.cpp -o bin/SaxonProcessor.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++ -std=c++14 -m64  -g  -fPIC  -I../../Saxon.C.API/graalvm -c ../../Saxon.C.API/SaxonApiException.cpp -o bin/SaxonApiException.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++  -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/Xslt30Processor.cpp -o bin/Xslt30Processor.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++ -std=c++14 -m64  -g   -fPIC -I../../Saxon.C.API/graalvm -c ../../Saxon.C.API/XsltExecutable.cpp -o bin/XsltExecutable.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++  -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/XQueryProcessor.cpp -o bin/XQueryProcessor.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++  -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/XPathProcessor.cpp -o bin/XPathProcessor.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

g++  -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm  -c ../../Saxon.C.API/SchemaValidator.cpp -o bin/SchemaValidator.o -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

and then

g++  -std=c++14 -m64  -g  -fPIC -I../../Saxon.C.API/graalvm bin/SaxonCGlue.o bin/SaxonCXPath.o bin/SaxonProcessor.o bin/XQueryProcessor.o bin/Xslt30Processor.o bin/XsltExecutable.o bin/XPathProcessor.o bin/DocumentBuilder.o bin/XdmValue.o bin/XdmItem.o bin/XdmNode.o bin/XdmAtomicValue.o bin/XdmArray.o bin/XdmFunctionItem.o bin/XdmMap.o bin/SchemaValidator.o bin/SaxonApiException.o testXQuery.cpp -o testXQuery -ldl -lc -lsaxon-@@edition@@c-@@VERSION@@  $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2

and the file https://saxonica.plan.io/projects/saxonmirrorhe/repository/he/revisions/he_mirror_saxon_12_4_1/entry/src/main/c/samples/cppTests/testXQuery.cpp has e.g.

#include "../../Saxon.C.API/SaxonProcessor.h"
#include "../../Saxon.C.API/XdmArray.h"
#include "../../Saxon.C.API/XdmAtomicValue.h"
#include "../../Saxon.C.API/XdmFunctionItem.h"
#include "../../Saxon.C.API/XdmItem.h"
#include "../../Saxon.C.API/XdmMap.h"
#include "../../Saxon.C.API/XdmNode.h"
#include "../../Saxon.C.API/XdmValue.h"
#include "CppTestUtils.h"
#include <string>

That should show you which files to compile and then link to to run XQuery with SaxonC.

Upvotes: 0

Related Questions