Project

Profile

Help

Link problems when trying to build C++ samples on Windows: unresolved external symbol

Added by Martin Honnen almost 3 years ago

On Windows (using Windows 10) and the C/C++ developer tools installed by VS 2019 I am not able to build the various cppTests samples, always failing to link. Example for testXPath.cpp:

C:\Program Files\Saxonica\SaxonC EE 11.1\samples\cppTests>.\build-windows.bat

C:\Program Files\Saxonica\SaxonC EE 11.1\samples\cppTests>set jdkdir=..\..\Saxon.C.API\jni

C:\Program Files\Saxonica\SaxonC EE 11.1\samples\cppTests>cl /EHsc "-I..\..\Saxon.C.API\jni" "-I..\..\Saxon.C.API\jni\win32"  testXPath.cpp ../../Saxon.C.API/SaxonCGlue.c ../../Saxon.C.API/SaxonCXPath.c ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XdmValue.cpp ../../Saxon.C.API/XdmItem.cpp ../../Saxon.C.API/XdmAtomicValue.cpp ../../Saxon.C.API/XdmNode.cpp ../../Saxon.C.API/XdmFunctionItem.cpp ../../Saxon.C.API/XdmArray.cpp ../../Saxon.C.API/XdmMap.cpp ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XQueryProcessor.cpp ../../Saxon.C.API/Xslt30Processor.cpp ../../Saxon.C.API/XsltExecutable.cpp ../../Saxon.C.API/XPathProcessor.cpp ../../Saxon.C.API/SchemaValidator.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30139 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

testXPath.cpp
Generating Code...
Compiling...
SaxonCGlue.c
SaxonCXPath.c
Generating Code...
Compiling...
SaxonProcessor.cpp
XdmValue.cpp
XdmItem.cpp
XdmAtomicValue.cpp
XdmNode.cpp
XdmFunctionItem.cpp
XdmArray.cpp
XdmMap.cpp
SaxonProcessor.cpp
XQueryProcessor.cpp
Xslt30Processor.cpp
XsltExecutable.cpp
XPathProcessor.cpp
SchemaValidator.cpp
Generating Code...
Microsoft (R) Incremental Linker Version 14.29.30139.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:testXPath.exe
testXPath.obj
SaxonCGlue.obj
SaxonCXPath.obj
SaxonProcessor.obj
XdmValue.obj
XdmItem.obj
XdmAtomicValue.obj
XdmNode.obj
XdmFunctionItem.obj
XdmArray.obj
XdmMap.obj
SaxonProcessor.obj
XQueryProcessor.obj
Xslt30Processor.obj
XsltExecutable.obj
XPathProcessor.obj
SchemaValidator.obj
SaxonProcessor.obj : warning LNK4042: object specified more than once; extras ignored
SaxonProcessor.obj : error LNK2019: unresolved external symbol "private: __cdecl DocumentBuilder::DocumentBuilder(class SaxonProcessor *,class _jobject *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0DocumentBuilder@@AEAA@PEAVSaxonProcessor@@PEAV_jobject@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: class DocumentBuilder * __cdecl SaxonProcessor::newDocumentBuilder(void)" (?newDocumentBuilder@SaxonProcessor@@QEAAPEAVDocumentBuilder@@XZ)
SaxonProcessor.obj : error LNK2019: unresolved external symbol "public: __cdecl SaxonApiException::SaxonApiException(char const *)" (??0SaxonApiException@@QEAA@PEBD@Z) referenced in function "public: static class SaxonApiException * __cdecl SaxonProcessor::checkForExceptionCPP(struct JNIEnv_ *,class _jclass *,class _jobject *)" (?checkForExceptionCPP@SaxonProcessor@@SAPEAVSaxonApiException@@PEAUJNIEnv_@@PEAV_jclass@@PEAV_jobject@@@Z)
XQueryProcessor.obj : error LNK2001: unresolved external symbol "public: __cdecl SaxonApiException::SaxonApiException(char const *)" (??0SaxonApiException@@QEAA@PEBD@Z)
Xslt30Processor.obj : error LNK2001: unresolved external symbol "public: __cdecl SaxonApiException::SaxonApiException(char const *)" (??0SaxonApiException@@QEAA@PEBD@Z)
XPathProcessor.obj : error LNK2001: unresolved external symbol "public: __cdecl SaxonApiException::SaxonApiException(char const *)" (??0SaxonApiException@@QEAA@PEBD@Z)
SaxonProcessor.obj : error LNK2019: unresolved external symbol "public: __cdecl SaxonApiException::SaxonApiException(char const *,char const *,char const *,int)" (??0SaxonApiException@@QEAA@PEBD00H@Z) referenced in function "public: static class SaxonApiException * __cdecl SaxonProcessor::checkForExceptionCPP(struct JNIEnv_ *,class _jclass *,class _jobject *)" (?checkForExceptionCPP@SaxonProcessor@@SAPEAVSaxonApiException@@PEAUJNIEnv_@@PEAV_jclass@@PEAV_jobject@@@Z)
SchemaValidator.obj : error LNK2001: unresolved external symbol "public: char const * __cdecl SaxonApiException::getMessage(void)" (?getMessage@SaxonApiException@@QEAAPEBDXZ)
SaxonProcessor.obj : error LNK2001: unresolved external symbol "public: char const * __cdecl SaxonApiException::getMessage(void)" (?getMessage@SaxonApiException@@QEAAPEBDXZ)
XQueryProcessor.obj : error LNK2001: unresolved external symbol "public: char const * __cdecl SaxonApiException::getMessage(void)" (?getMessage@SaxonApiException@@QEAAPEBDXZ)
Xslt30Processor.obj : error LNK2001: unresolved external symbol "public: char const * __cdecl SaxonApiException::getMessage(void)" (?getMessage@SaxonApiException@@QEAAPEBDXZ)
XPathProcessor.obj : error LNK2001: unresolved external symbol "public: char const * __cdecl SaxonApiException::getMessage(void)" (?getMessage@SaxonApiException@@QEAAPEBDXZ)
XQueryProcessor.obj : error LNK2019: unresolved external symbol "public: char const * __cdecl SaxonApiException::getErrorCode(void)" (?getErrorCode@SaxonApiException@@QEAAPEBDXZ) referenced in function "public: char const * __cdecl XQueryProcessor::getErrorCode(void)" (?getErrorCode@XQueryProcessor@@QEAAPEBDXZ)
Xslt30Processor.obj : error LNK2001: unresolved external symbol "public: char const * __cdecl SaxonApiException::getErrorCode(void)" (?getErrorCode@SaxonApiException@@QEAAPEBDXZ)
XPathProcessor.obj : error LNK2001: unresolved external symbol "public: char const * __cdecl SaxonApiException::getErrorCode(void)" (?getErrorCode@SaxonApiException@@QEAAPEBDXZ)
SchemaValidator.obj : error LNK2001: unresolved external symbol "public: char const * __cdecl SaxonApiException::getErrorCode(void)" (?getErrorCode@SaxonApiException@@QEAAPEBDXZ)
XsltExecutable.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl SaxonApiException::getMessageStr(void)" (?getMessageStr@SaxonApiException@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "public: char const * __cdecl XsltExecutable::getErrorMessage(void)" (?getErrorMessage@XsltExecutable@@QEAAPEBDXZ)
testXPath.exe : fatal error LNK1120: 6 unresolved externals

Why could that be? Does the cl command have to include more files, like

cl /EHsc "-I%jdkdir%" "-I%jdkdir%\win32"  testXPath.cpp ../../Saxon.C.API/SaxonCGlue.c ../../Saxon.C.API/SaxonCXPath.c ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/DocumentBuilder.cpp ../../Saxon.C.API/SaxonApiException.cpp ../../Saxon.C.API/XdmValue.cpp ../../Saxon.C.API/XdmItem.cpp ../../Saxon.C.API/XdmAtomicValue.cpp ../../Saxon.C.API/XdmNode.cpp ../../Saxon.C.API/XdmFunctionItem.cpp ../../Saxon.C.API/XdmArray.cpp ../../Saxon.C.API/XdmMap.cpp ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XQueryProcessor.cpp ../../Saxon.C.API/Xslt30Processor.cpp ../../Saxon.C.API/XsltExecutable.cpp ../../Saxon.C.API/XPathProcessor.cpp ../../Saxon.C.API/SchemaValidator.cpp
cl /EHsc "-I%jdkdir%" "-I%jdkdir%\win32"  testXSLT30.cpp ../../Saxon.C.API/SaxonCGlue.c ../../Saxon.C.API/SaxonCXPath.c ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/DocumentBuilder.cpp ../../Saxon.C.API/SaxonApiException.cpp cppExtensionFunction.cpp ../../Saxon.C.API/XdmValue.cpp ../../Saxon.C.API/XdmItem.cpp ../../Saxon.C.API/XdmAtomicValue.cpp ../../Saxon.C.API/XdmNode.cpp ../../Saxon.C.API/XdmFunctionItem.cpp ../../Saxon.C.API/XdmArray.cpp ../../Saxon.C.API/XdmMap.cpp ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XQueryProcessor.cpp ../../Saxon.C.API/Xslt30Processor.cpp ../../Saxon.C.API/XsltExecutable.cpp ../../Saxon.C.API/XPathProcessor.cpp ../../Saxon.C.API/SchemaValidator.cpp
cl /EHsc "-I%jdkdir%" "-I%jdkdir%\win32"  testXQuery.cpp ../../Saxon.C.API/SaxonCGlue.c ../../Saxon.C.API/SaxonCXPath.c ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/DocumentBuilder.cpp ../../Saxon.C.API/SaxonApiException.cpp ../../Saxon.C.API/XdmValue.cpp ../../Saxon.C.API/XdmItem.cpp ../../Saxon.C.API/XdmAtomicValue.cpp ../../Saxon.C.API/XdmNode.cpp ../../Saxon.C.API/XdmFunctionItem.cpp ../../Saxon.C.API/XdmArray.cpp ../../Saxon.C.API/XdmMap.cpp ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XQueryProcessor.cpp ../../Saxon.C.API/Xslt30Processor.cpp ../../Saxon.C.API/XsltExecutable.cpp ../../Saxon.C.API/XPathProcessor.cpp ../../Saxon.C.API/SchemaValidator.cpp
cl /EHsc "-I%jdkdir%" "-I%jdkdir%\win32"  testValidator.cpp ../../Saxon.C.API/SaxonCGlue.c ../../Saxon.C.API/SaxonCXPath.c ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/DocumentBuilder.cpp ../../Saxon.C.API/SaxonApiException.cpp ../../Saxon.C.API/XdmValue.cpp ../../Saxon.C.API/XdmItem.cpp ../../Saxon.C.API/XdmAtomicValue.cpp ../../Saxon.C.API/XdmNode.cpp ../../Saxon.C.API/XdmFunctionItem.cpp ../../Saxon.C.API/XdmArray.cpp ../../Saxon.C.API/XdmMap.cpp ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XQueryProcessor.cpp ../../Saxon.C.API/Xslt30Processor.cpp ../../Saxon.C.API/XsltExecutable.cpp ../../Saxon.C.API/XPathProcessor.cpp ../../Saxon.C.API/SchemaValidator.cpp

That seems to fix it.


Replies (2)

RE: Link problems when trying to build C++ samples on Windows: unresolved external symbol - Added by Martin Honnen almost 3 years ago

I will attach the build file I fixed to be able to get the compiling and linking to work on Windows:

set jdkdir=..\..\Saxon.C.API\jni

cl /EHsc "-I%jdkdir%" "-I%jdkdir%\win32"  testXPath.cpp ../../Saxon.C.API/SaxonCGlue.c ../../Saxon.C.API/SaxonCXPath.c cppExtensionFunction.cpp  ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XdmValue.cpp ../../Saxon.C.API/XdmItem.cpp ../../Saxon.C.API/XdmAtomicValue.cpp ../../Saxon.C.API/DocumentBuilder.cpp ../../Saxon.C.API/XdmNode.cpp ../../Saxon.C.API/XdmFunctionItem.cpp ../../Saxon.C.API/XdmArray.cpp ../../Saxon.C.API/XdmMap.cpp ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/SaxonApiException.cpp ../../Saxon.C.API/XQueryProcessor.cpp ../../Saxon.C.API/Xslt30Processor.cpp ../../Saxon.C.API/XsltExecutable.cpp ../../Saxon.C.API/XPathProcessor.cpp ../../Saxon.C.API/SchemaValidator.cpp
cl /EHsc "-I%jdkdir%" "-I%jdkdir%\win32"  testXSLT30.cpp ../../Saxon.C.API/SaxonCGlue.c ../../Saxon.C.API/SaxonCXPath.c cppExtensionFunction.cpp  ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XdmValue.cpp ../../Saxon.C.API/XdmItem.cpp ../../Saxon.C.API/XdmAtomicValue.cpp ../../Saxon.C.API/DocumentBuilder.cpp ../../Saxon.C.API/XdmNode.cpp ../../Saxon.C.API/XdmFunctionItem.cpp ../../Saxon.C.API/XdmArray.cpp ../../Saxon.C.API/XdmMap.cpp ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/SaxonApiException.cpp ../../Saxon.C.API/XQueryProcessor.cpp ../../Saxon.C.API/Xslt30Processor.cpp ../../Saxon.C.API/XsltExecutable.cpp ../../Saxon.C.API/XPathProcessor.cpp ../../Saxon.C.API/SchemaValidator.cpp
cl /EHsc "-I%jdkdir%" "-I%jdkdir%\win32"  testXQuery.cpp ../../Saxon.C.API/SaxonCGlue.c ../../Saxon.C.API/SaxonCXPath.c cppExtensionFunction.cpp  ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XdmValue.cpp ../../Saxon.C.API/XdmItem.cpp ../../Saxon.C.API/XdmAtomicValue.cpp ../../Saxon.C.API/DocumentBuilder.cpp ../../Saxon.C.API/XdmNode.cpp ../../Saxon.C.API/XdmFunctionItem.cpp ../../Saxon.C.API/XdmArray.cpp ../../Saxon.C.API/XdmMap.cpp ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/SaxonApiException.cpp ../../Saxon.C.API/XQueryProcessor.cpp ../../Saxon.C.API/Xslt30Processor.cpp ../../Saxon.C.API/XsltExecutable.cpp ../../Saxon.C.API/XPathProcessor.cpp ../../Saxon.C.API/SchemaValidator.cpp
cl /EHsc "-I%jdkdir%" "-I%jdkdir%\win32"  testValidator.cpp ../../Saxon.C.API/SaxonCGlue.c ../../Saxon.C.API/SaxonCXPath.c cppExtensionFunction.cpp  ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/XdmValue.cpp ../../Saxon.C.API/XdmItem.cpp ../../Saxon.C.API/XdmAtomicValue.cpp ../../Saxon.C.API/DocumentBuilder.cpp ../../Saxon.C.API/XdmNode.cpp ../../Saxon.C.API/XdmFunctionItem.cpp ../../Saxon.C.API/XdmArray.cpp ../../Saxon.C.API/XdmMap.cpp ../../Saxon.C.API/SaxonProcessor.cpp ../../Saxon.C.API/SaxonApiException.cpp ../../Saxon.C.API/XQueryProcessor.cpp ../../Saxon.C.API/Xslt30Processor.cpp ../../Saxon.C.API/XsltExecutable.cpp ../../Saxon.C.API/XPathProcessor.cpp ../../Saxon.C.API/SchemaValidator.cpp
    (1-2/2)

    Please register to reply