Skip to content
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

Fix static MinGW build #245

Conversation

rockdaboot
Copy link

@rockdaboot rockdaboot commented May 6, 2023

Copied over the comments and macro tree from src/pcre2_internal.h, which I consider to be correctly.

Fixes #243

src/pcre2posix.h Outdated
http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
information there, using __declspec(dllexport) without "extern" we have a
definition; with "extern" we have a declaration. The settings here override the
setting in pcre2.h (which is included below); it defines only
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(which is included below)

this is not correct in this context

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I amended the comment.

Copy link
Contributor

@carenas carenas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the non static build as shown by:

src/pcre2posix.c:62: warning: "PCRE2POSIX_EXP_DECL" redefined
   62 | #  define PCRE2POSIX_EXP_DECL extern __declspec(dllexport)
      | 
In file included from src/pcre2posix.c:52:
src/config.h:257: note: this is the location of the previous definition
  257 | #define PCRE2POSIX_EXP_DECL extern __attribute__ ((visibility ("default")))
      | 
src/pcre2posix.c:63: warning: "PCRE2POSIX_EXP_DEFN" redefined
   63 | #  define PCRE2POSIX_EXP_DEFN __declspec(dllexport)
      | 
src/config.h:260: note: this is the location of the previous definition
  260 | #define PCRE2POSIX_EXP_DEFN extern __attribute__ ((visibility ("default")))
      | 

@rockdaboot
Copy link
Author

This breaks the non static build as shown by:

src/pcre2posix.c:62: warning: "PCRE2POSIX_EXP_DECL" redefined
   62 | #  define PCRE2POSIX_EXP_DECL extern __declspec(dllexport)
      | 
In file included from src/pcre2posix.c:52:
src/config.h:257: note: this is the location of the previous definition
  257 | #define PCRE2POSIX_EXP_DECL extern __attribute__ ((visibility ("default")))
      | 
src/pcre2posix.c:63: warning: "PCRE2POSIX_EXP_DEFN" redefined
   63 | #  define PCRE2POSIX_EXP_DEFN __declspec(dllexport)
      | 
src/config.h:260: note: this is the location of the previous definition
  260 | #define PCRE2POSIX_EXP_DEFN extern __attribute__ ((visibility ("default")))
      | 

This happens without this PR as well (commit 04fbb65).

@rockdaboot rockdaboot force-pushed the rockdaboot/fix-static-mingw-build branch from 8548ef9 to cd894c0 Compare May 7, 2023 13:06
@rockdaboot
Copy link
Author

Removed the (superfluous) defines from src/pcre2posix.c.

@carenas
Copy link
Contributor

carenas commented May 8, 2023

Those defines weren't superfluous. As explained in the documentation[1] the code you are adding is linking to, you need to set them differently depending of if you are building the library or a program that uses it.

There is an interesting takeaway from your accidental solution though, and it is that the __declspec(dllimport) is actually optional[2], and that could be exploited (albeit with a small performance hit) to avoid having to keep track of the way the library was build with PCRE2_STATIC, and which is the root cause of the problem as shown in #246.

[1] https://web.archive.org/web/20130907051123/http://msdn.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx
[2] https://learn.microsoft.com/en-us/cpp/build/importing-into-an-application-using-declspec-dllimport

@rockdaboot
Copy link
Author

Superceded by #249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MinGW: Failed to build static lib undefined reference to '__imp_pcre2_regcomp'
2 participants