我从 https://www.saxonica.com/download/c.xml
下载最新的适用于 Linux 的 SaxonC-HE 库然后从上面的网站,我将 libsaxon-hec-12.4.1 复制到 /usr/local/lib 并开始编写代码。当用C++编译代码时,出现错误:
对“SaxonProcessor::newXQueryProcessor”等的未定义引用
在我的 qmake 文件中,我添加 LIBS += -lsaxon-hec-12.4.1
伪代码:
#include SaxonProcessor.h
SaxonProcess *processor = new SaxonProcessor(false);
XQueryProcessor *query = processor->newXQueryProcessor();
query->setQueryContent(content);
query->setParameters(parameter, XdmValue);
const char *result = query->runQueryToString();
我想知道是否需要自己编译 saxonc 库并生成 lib 文件以便我可以链接到。但是下载的 SaxonC 文件夹中没有 make 文件
好吧,如果您查看示例,那么您肯定会看到,要编译例如
testXQuery.cpp
,build64-linux.sh文件编译了之前Saxon.C.API
中的许多文件并链接它们,即在https://saxonica.plan.io/projects/saxonmirrorhe/repository/he/revisions/he_mirror_saxon_12_4_1/条目/src/main/c/samples/cppTests/build64-linux.sh你看
#!/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
然后
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
#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>
这应该显示要编译哪些文件,然后链接到哪些文件以使用 SaxonC 运行 XQuery。