libexpat: building expat 2.4.8 on windows using static runtime fails
Trying to upgrade to the latest version of expat using MSVC 2022, I find it impossible to link against expat, when compiled with the static runtime options. Here my cmake variables:
set (EXPAT_SHARED_LIBS OFF)
set (EXPAT_BUILD_EXAMPLES OFF)
set (EXPAT_BUILD_TESTS OFF)
set (EXPAT_BUILD_TOOLS OFF)
set (EXPAT_BUILD_TOOLS OFF)
if (WITH_STATIC_RUNTIME)
#expat is overriding this, so enforce it to be
set(EXPAT_MSVC_STATIC_CRT ON CACHE BOOL "Use /MT flag (static CRT) when compiling in MSVC" FORCE)
endif()
Unfortunately, when trying to link against the library, i get an undefined symbol:
libexpat.lib(xmlparse.c.obj) : error LNK2019: unresolved external symbol __imp_rand_s referenced in function generate_hash_secret_salt
additionally there are warnings, that indicate that the static runtime seems to be ignored:
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4217: symbol '_errno' defined in 'libucrt.lib(errno.obj)' is imported by 'libexpat.lib(xmlparse.c.obj)' in function 'ENTROPY_DEBUG'
LINK : warning LNK4217: symbol '__acrt_iob_func' defined in 'libucrt.lib(_file.obj)' is imported by 'libexpat.lib(xmlparse.c.obj)' in function 'ENTROPY_DEBUG'
LINK : warning LNK4217: symbol '__stdio_common_vfprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libexpat.lib(xmlparse.c.obj)' in function '_vfprintf_l'
LINK : warning LNK4217: symbol 'free' defined in 'libucrt.lib(free.obj)' is imported by 'libexpat.lib(xmlparse.c.obj)' in function 'parserCreate'
LINK : warning LNK4217: symbol 'malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'libexpat.lib(xmlparse.c.obj)' in function 'parserCreate'
LINK : warning LNK4217: symbol 'realloc' defined in 'libucrt.lib(realloc.obj)' is imported by 'libexpat.lib(xmlparse.c.obj)' in function 'parserCreate'
LINK : warning LNK4217: symbol 'strtoul' defined in 'libucrt.lib(strtox.obj)' is imported by 'libexpat.lib(xmlparse.c.obj)' in function 'ENTROPY_DEBUG'
LINK : warning LNK4217: symbol 'getenv' defined in 'libucrt.lib(getenv.obj)' is imported by 'libexpat.lib(xmlparse.c.obj)' in function 'ENTROPY_DEBUG'
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 27 (17 by maintainers)
Commits related to this issue
- Merge pull request #599 from libexpat/issue-597-windows-tests-xml-static CMake: Add missing XML_STATIC to test runners and fuzzers on Windows (related to #597) — committed to libexpat/libexpat by hartwork 2 years ago
- Merge pull request #627 from libexpat/issue-597-cmake-migrate-set-cache-to-option CMake: Unify inconsistent use of set() and option() (related to #597) — committed to libexpat/libexpat by hartwork 2 years ago
We resolved this issue in our Expat find script, by compiling it twice, to see whether the
XML_STATICcompile definition is needed:full script for example here:
https://github.com/copasi/COPASI/blob/develop/CMakeModules/FindEXPAT.cmake
@hartwork Thanks for your input, yes I am using it on windows. I can switch to the recommended version