-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define XML_STATIC in pkg-config file when building a static expat #805
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @haileys before reviewing the technical details of the pull request I would like to understand the bug report side of this better, the requirements engineering side of things. I have a guess but I'd like to be sure. Could you elaborate what you did to see things fail with -DEXPAT_SHARED_LIBS=OFF
, what the related error output was, which operating system(s) and compiler(s) are involved? Thanks!
Thanks for the quick reply @hartwork. I am experimenting with building a statically linked GTK stack to ease deployment on non-Linux systems, and the target for my work is Windows. I am indeed using When |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@haileys thanks for elaborating, that makes sense. Also tested your code locally with static and shared mode and both seem to work as expected 👍
I'm a bit surprised by the existing use of _MSC_EXTENSIONS
at…
libexpat/expat/lib/expat_external.h
Lines 87 to 96 in 86a3623
#if ! defined(XML_STATIC) && ! defined(XMLIMPORT) | |
# ifndef XML_BUILDING_EXPAT | |
/* using Expat from an application */ | |
# if defined(_MSC_EXTENSIONS) && ! defined(__BEOS__) && ! defined(__CYGWIN__) | |
# define XMLIMPORT __declspec(dllimport) | |
# endif | |
# endif | |
#endif /* not defined XML_STATIC */ |
…which according to…
- https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170
- https://learn.microsoft.com/en-us/cpp/build/reference/za-ze-disable-language-extensions?view=msvc-170
…is enabled by default but also means that mangling only happens with MSVC but not MinGW? My Windows is getting a little rusty, it's been 10+ years now. Do you happen to know if MinGW would need the same or not in this context? Does not need to be part of the pull request in any case, but would be great to know.
One more thing: We have two build systems here — CMake and GNU Autotools — and I wonder if expat.pc.in
of the Autotools build system should do the same or not (in general), I try to keep them in sync as much as feasibly possible. Is there some hard reason why ./configure
and MSVC are known to be impossible to be combined? Related again here is the question whether this is an MSVC-only topic.
@haileys PS: This just turned out to also cause red CI at https://github.com/libexpat/libexpat/actions/runs/7591776257/job/20687698564?pr=805 where the diff is a trailing space at the end of the line. So I guess we do need this times two. Would you be comfortable to also extend |
@hartwork I had a look at making similar changes to the autotools build system, but to be honest I've never really been able to figure out autotools. I managed to generate a configure script on mingw64, but it seems to have been generated with a syntax error and failed due to that. It doesn't look like configure.ac has any reference to XML_STATIC anyway, so I wonder, would it be acceptable if I fixed the trailing space issue so that we don't get mismatches in the generated pkgconfig files in the usual path (building a shared library), and leaving the MSVC static build support for CMake only? |
Mine too I'm afraid, I use Linux usually, and I'm having to re-learn everything for this project! :) I'm not sure about MinGW |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@haileys is there a reason why we cannot or should not use Cflags.private
?
For example:
# grep -F Cflags.private /usr/lib64/pkgconfig/xmlsec1-openssl.pc
Cflags.private: -DXMLSEC_STATIC
# diff -u0 <(pkg-config --cflags --static xmlsec1-nss | xargs -n1) <(pkg-config --cflags xmlsec1-nss | xargs -n1)
--- /dev/fd/63 2024-01-23 00:26:22.782678240 +0100
+++ /dev/fd/62 2024-01-23 00:26:22.783678250 +0100
@@ -13 +12,0 @@
--DXMLSEC_STATIC
# pkg-config --version
2.1.0
@hartwork Oh, I didn't know about that option! I have tried it out, applying this patch to my build instead: diff --git a/expat/expat.pc.cmake b/expat/expat.pc.cmake
index da7a0549..56da4137 100644
--- a/expat/expat.pc.cmake
+++ b/expat/expat.pc.cmake
@@ -10,3 +10,4 @@ URL: https://libexpat.github.io/
Libs: -L${libdir} -l$<TARGET_PROPERTY:expat,pkgconfig_$<LOWER_CASE:$<CONFIG>>_output_name>
Libs.private: $<TARGET_PROPERTY:expat,pkgconfig_libm>
Cflags: -I${includedir}
+Cflags.private: -DXML_STATIC
diff --git a/expat/expat.pc.in b/expat/expat.pc.in
index db080653..a53ab118 100644
--- a/expat/expat.pc.in
+++ b/expat/expat.pc.in
@@ -10,3 +10,4 @@ URL: https://libexpat.github.io/
Libs: -L${libdir} -l@PACKAGE_NAME@
Libs.private: @LIBM@
Cflags: -I${includedir}
+Cflags.private: -DXML_STATIC But it appears that it's not getting picked up for some reason when building fontconfig, which depends on expat. The unresolved external symbol errors are back, and I have confirmed by inspecting the Including |
Hi @haileys , thanks for playing with # grep -R -i -F cflags.private /usr/lib64/pkgconfig/
/usr/lib64/pkgconfig/libarchive.pc:Cflags.private: -DLIBARCHIVE_STATIC
/usr/lib64/pkgconfig/xmlsec1-nss.pc:Cflags.private: -DXMLSEC_STATIC
/usr/lib64/pkgconfig/liblzma.pc:Cflags.private: -DLZMA_API_STATIC
/usr/lib64/pkgconfig/xmlsec1-openssl.pc:Cflags.private: -DXMLSEC_STATIC …and not mentioned at e.g. https://people.freedesktop.org/~dbn/pkg-config-guide.html (which seems to rank high on Google) that Now regarding fontconfig, it could either be that (a) something needs fixing on their side or (b) that their compile error revels some misunderstanding in the picture I just painted in the paragraph above. Also, there are two(?) implementations of pkg-config out there (at least histortically), maybe one is dead already, may need a closer look. In Gentoo mine is from https://gitea.treehouse.systems/ariadne/pkgconf , package name is For moving forward: I'd like to learn more about the fontconfig issue you run into and also which implementation of pkg(-)conf(ig) you are exposed to. What do you think? |
@haileys I would like to add two things:
|
@haileys , @hartwork libexpat.lib(xmlparse.c.obj) : error LNK2019: unresolved external symbol __imp_rand_s referenced in function generate_hash_secret_salt |
@AsifKhan-78 your report/question is a bit out of place here and I don't understand your scenario in detail, yet. You can either create a new issue with more details or we can jump on a call in English or German. For the latter please find my e-mail address in my profile, so that we can co-ordinate the when and how of a call. Thank you. |
@haileys any news? |
Closing due to no reply for two weeks, superseded by pull request #815… |
…build-on-windows pkg-config: Add missing `-DXML_STATIC` for Windows (alternative to #805)
XML_STATIC
is required to be defined when using expat as a static library, but it is not set in the generated pkgconfig when expat is built as a static library. This sets it up so that apps using a static expat via pkgconfig will automatically set the right definition.