dmitry_bond
dmitry_bond

Reputation: 440

XALAN-C 1.12 - weird error when building statically

I need to build and link both Xerces-C (3.2.5/latest) and Xalan-C (1.12/latest) libs statically.

Xerces 3.2.5 was built statically without any problems. I just run CMake command like this:

cmake . -A Win32 -DBUILD_SHARED_LIBS:BOOL=OFF

It generated VS-projects, then I run

cmake --build . --clean-first --config Release

And it was built.

But unfortunately static build of Xalan-C was fail. :-(

I created a script like this:

set BuildCfgName=Release
set XERCES_ROOT=D:\libs\ApacheXML\xerces-c-3.2.5
set XercesC_LIBRARY=D:\libs\ApacheXML\libs\static\xerces-c_3.lib
set XercesC_INCLUDE_DIR=%XERCES_ROOT%\src
cmake . -A Win32 -DBUILD_SHARED_LIBS:BOOL=OFF -DXercesC_LIBRARY=%XercesC_LIBRARY% -DXercesC_INCLUDE_DIR=%XercesC_INCLUDE_DIR% -Dmessage-loader=inmemory

Then opened it in VS 2012 and try to build but it fail with lot of errors like these:

Error   51  error C2491: 'xalanc_1_12::XalanDOMInit::s_initCounter' : definition of dllimport static data member not allowed    D:\libs\ApacheXML\xalan_c-1.12\src\xalanc\XalanDOM\XalanDOMInit.cpp 27
[...]
Error   88  error C2491: 'xalanc_1_12::TranscodeToLocalCodePage' : definition of dllimport function not allowed D:\libs\ApacheXML\xalan_c-1.12\src\xalanc\XalanDOM\XalanDOMString.cpp   1085
[...]
Error   93  error C2491: 'xalanc_1_12::TranscodeFromLocalCodePage' : definition of dllimport function not allowed   D:\libs\ApacheXML\xalan_c-1.12\src\xalanc\XalanDOM\XalanDOMString.cpp   1211

I inspected all compiler and linker settings in VS2012 IDE for project properties - I cannot find anything which may affect that. :-\

Could you please advice - is it possible at all to build Xalan-C 1.12 statically? Or if there is bug in build configuration?

Because in "src\xalanc\Include\PlatformDefinitions.hpp" I see this:

#if defined(_MSC_VER) //<- this part is actual for compiling
  #define XALAN_PLATFORM_EXPORT     __declspec(dllexport)
  #define XALAN_PLATFORM_IMPORT     __declspec(dllimport)
  #define XALAN_PLATFORM_EXPORT_FUNCTION(T) XALAN_PLATFORM_EXPORT T
  #define XALAN_PLATFORM_IMPORT_FUNCTION(T) XALAN_PLATFORM_IMPORT T
#else
  #define XALAN_PLATFORM_EXPORT
  #define XALAN_PLATFORM_IMPORT
  #define XALAN_PLATFORM_EXPORT_FUNCTION(T) T XALAN_PLATFORM_EXPORT
  #define XALAN_PLATFORM_IMPORT_FUNCTION(T) T XALAN_PLATFORM_IMPORT
#endif

As I understand these definitions looks wrong...

So, on 1st glance - Xalan-C 1.12 is impossible to build statically.

But maybe I missed something?... Could you please advise?

So, 'MRE-scenario' is following:

  1. Download Xerces-C - https://dlcdn.apache.org//xerces/c/3/sources/xerces-c-3.2.5.zip

1.1) Extract to "D:\libs\ApacheXML\xerces-c-3.2.5"

1.2) Create cmk.cmd script (see above)

1.3) Built it with CMake or with VS (I tried VS2012 and VS2022 - both works fine for Xerces-C static lib building)

  1. Download Xalan-C - https://dlcdn.apache.org/xalan/xalan-c/sources/xalan_c-1.12.zip

2.1) Extract to "D:\libs\ApacheXML\xalan_c-1.12"

2.2) ... and so on

Upvotes: 1

Views: 177

Answers (1)

dmitry_bond
dmitry_bond

Reputation: 440

As discovered - I need to change only 2 header files in XALAN to make static build on Windows working correctly:

  • "xalan_c-1.12\src\xalanc\Include\PlatformDefinitions.hpp"
  • "xalan_c-1.12\src\xalanc\XPathCAPI\XPathCAPI.h"

In both files I only need to comment out __declspec(dllimport) code, like this: /* __declspec(dllimport) */.

Then static version of XALAN 1.12 was successfully built. Then I can link it to my test app and it works correctly.

Upvotes: 0

Related Questions