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

Missing DEBUG macro #11311

Closed
SunBlack opened this issue Nov 20, 2024 · 5 comments · Fixed by #11314
Closed

Missing DEBUG macro #11311

SunBlack opened this issue Nov 20, 2024 · 5 comments · Fixed by #11314
Assignees

Comments

@SunBlack
Copy link
Contributor

What is the bug?

Currently we have issues switching from an old GDAL version (3.3.3 - nmake build systems) to a new one (3.5+ - cmake build system) as the linker fails in debug mode. Specifically, we have the linker problem with OGRSpatialReference::FindMatches.

With vcpk, on the other hand, we don't have the linker issue. That's why I used dumpbin to inspect the gdald.lib:

  • Result of dumpbin with GDAL compiled via vcpkg:
    ?FindMatches@OGRSpatialReference@@QEBAPEAPEAUOGRSpatialReferenceHS@@PEAPEADPEAHPEAPEAH@Z
    (public: struct OGRSpatialReferenceHS * __ptr64 * __ptr64 __cdecl OGRSpatialReference::FindMatches(char * __ptr64 * __ptr64,int * __ptr64,int * __ptr64 * __ptr64)const __ptr64)
  • Result of dumpbin with self compiled GDAL:
    ?FindMatches@OGRSpatialReference@@QEBAPEAPEAXPEAPEADPEAHPEAPEAH@Z
    (public: void * __ptr64 * __ptr64 __cdecl OGRSpatialReference::FindMatches(char * __ptr64 * __ptr64,int * __ptr64,int * __ptr64 * __ptr64)const __ptr64)

As you can see, the return type differs. The reason for this is this:

#ifdef DEBUG
typedef struct OGRSpatialReferenceHS *OGRSpatialReferenceH;
typedef struct OGRCoordinateTransformationHS *OGRCoordinateTransformationH;
#else
/** Opaque type for a Spatial Reference object */
typedef void *OGRSpatialReferenceH;
/** Opaque type for a coordinate transformation object */
typedef void *OGRCoordinateTransformationH;
#endif

For some reason DEBUG is defined during building self compiled GDAL, but during compiling via vcpkg. Unfortunately, I have not yet found where this macro is defined, as it is not actually a predefined one (_DEBUG is predefined, but not DEBUG, see here). If you create a simple CMake project that has only one executable, set the debug mode in MSVC, and copy in the above #ifdef from GDAL, you will also see that DEBUG is not defined this case.

So the question is: Where is DEBUG defined? And shouldn't it be exported so that it is active for the GDAL headers when it is included?

Steps to reproduce the issue

  1. Build GDAL with default settings
  2. Create a simple CMake project with just a executable

Versions and provenance

Windows 10/11

Additional context

No response

@rouault
Copy link
Member

rouault commented Nov 20, 2024

A workaround is that you use CMake Release or RelWithDebInfo builds, not Debug one

rouault added a commit to rouault/gdal that referenced this issue Nov 20, 2024
@SunBlack
Copy link
Contributor Author

A workaround is that you use CMake Release or RelWithDebInfo builds, not Debug one

Tried it, but doesn't work. When we are building our framework in Debug mode, but using Release GDAL libraries, we are getting SEH expception. When building Release and RelWithDebInfo (with -DCMAKE_RELWITHDEBINFO_POSTFIX=d, so that the two build types do not overwrite each other), CMake sadly prefers the Release library instead the RelWithDebInfo.

@rouault
Copy link
Member

rouault commented Nov 21, 2024

Tried it, but doesn't work. When we are building our framework in Debug mode, but using Release GDAL libraries, we are getting SEH expception.

ah yes, that's a Windows thing where the ABI of the C++ standard library changes between debug and release. Nothing that GDAL can do about.

@SunBlack
Copy link
Contributor Author

SunBlack commented Nov 21, 2024

Tried it, but doesn't work. When we are building our framework in Debug mode, but using Release GDAL libraries, we are getting SEH expception.

ah yes, that's a Windows thing where the ABI of the C++ standard library changes between debug and release. Nothing that GDAL can do about.

Yep. Actually, my idea now is to backport the fix from #11314. So if the version is <= 3.10.0, that it adds the flag to the imported target. However, this would possibly break the vcpkg setup, because for some reason it runs without the flag. That's why I'm currently still looking for what the vcpkg port does differently.

Btw: We need for Linux also a separate Debug build as we compile our framework with _GLIBCXX_DEBUG and therefore also all dependencies needs to be compiled with it (for better assertions). Somehow the missing DEBUG is okay for the linker.

@SunBlack
Copy link
Contributor Author

SunBlack commented Nov 21, 2024

Ok I think I found the reason, why vcpkg works for us. As we are still using GDAL 3.8.5 there, so this commit is still not relevant for us: bfed070. As vcpkg builds the dependencies the MSVC tree will not be entered (I think). Therefore the Debug-Flag will not be set.

So without testing: Could be it, that OGRSpatialReference::FindMatches is also not working for the vcpkg build 3.9.0 and newer?

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 a pull request may close this issue.

2 participants