I am trying to use xerces-c-3.2.2 on Windows 10 from the sample in xerces-c-3.2.2\samples\src\SAXPrint, the sample used as a Visual Studio 2019 project.
Before, I used xerces-c_2_8_0 successfully with xerces-c-src_2_8_0\samples\SAX2Print as a Visual Studio 2019 project with Visual Studio configurations (not CMake). When trying the same with xerces-c-3.2.2 and the according sample, I get the 'error MSB6006: "CL.exe" exited with code 2'.
Note: I have built xerces-c-3.2.2 myself, as there are no binaries for it available. After the build of xerces-c-3.2.2, I get the files xerces-c_3.exp, xerces-c_3.lib, and xerces-c_3_2.dll in C:\Xerces\xerces-c-3.2.2\src\Release, and the include files are in C:\Xerces\xerces-c-3.2.2\xerces-c-3.2.2\src.
On https://developercommunity.visualstudio.com/content/problem/405001/error-msb6006-clexe-exited-with-code-2.html, it was suggested to use Clang as a compiler, as the mentioned "MSB6006" error should be a compiler bug that has not been fixed by Microsoft yet. For using Clang, one has to use CMake in the current version of Visual Studio (I would prefer CMake anyway, for other reasons), and I could not figure out how to setup the project with CMake correctly. The problem is how to tell CMake about the Xerces library files (with xerces-c-3.2.2, there seems to be the only one library file xerces-c_3.lib).
So my top-level CMakeLists.txt (without linking) is:
cmake_minimum_required (VERSION 3.8)
project ("SAXPrint")
include_directories("C:\\Xerces\\xerces-c-3.2.2\\xerces-c-3.2.2\\src")
add_subdirectory ("SAXPrint")
The CMakeLists.txt in the subdirectory is
cmake_minimum_required (VERSION 3.8)
add_executable(SAXPrint "SAXPrint.cpp" "SAXPrint.hpp")
(Yes, I know I should use the absolute paths as arguments to CMake, but that should not be the point here.)
To inform CMake about the xerces library file, I tried
link_directories("C:\\Xerces\\xerces-c-3.2.2\\xerces-c-3.2.2\\src\\Release")
in top-level CMakeLists.txt and I tried
target_link_libraries(SAXPrint "C:\\Xerces\\xerces-c-3.2.2\\xerces-c-3.2.2\\src\\Release")
(this last one does not seem to be accepted, as Visual Studio then keeps displaying the message "generate CMake cache to refresh") and I have read something about the CMake "find_library" command that I did not understand.
The error message I get is
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: static char const * const xercesc_3_2::XMLUni::fgXercescDefaultLocale" (__imp_?fgXercescDefaultLocale@XMLUni@xercesc_3_2@@2QBDB) referenced in function main C:\Users\stefan\source\repos\SAXPrint C:\Users\stefan\source\repos\SAXPrint.cpp.obj 1
So any comment how to use the Xerces library file is really welcome, but even better would be if someone had a whole sample CMake project that works with Xerces Version 3 and Visual Studio 2019. I would prefer a CMake project, as this seems to be a better choice for what I would like to accomplish. Thanks.