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

Makefile.msc introduces a release CRT into debug VC++ builds #569

Closed
gh-andre opened this issue Jul 25, 2021 · 3 comments
Closed

Makefile.msc introduces a release CRT into debug VC++ builds #569

gh-andre opened this issue Jul 25, 2021 · 3 comments

Comments

@gh-andre
Copy link

Makefile.msc only makes release builds and provides no way to make a debug build, which makes it harder to use generated libraries in debug configurations because VC++ CRT (C/C++ runtime) for debug and release builds are different. Specifically, -MD is used unconditionally on this line in Makefile.msc:

CFLAGS  = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)

The fix is fairly simple and is to remove -MD from CFLAGS and add it conditionally, based on whether DEBUG=1 is defined.

CFLAGS  = -nologo -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)
...
!IFDEF DEBUG
CFLAGS = $(CFLAGS) /MDd
!ELSE
CFLAGS = $(CFLAGS) /MD /DNDEBUG
!ENDIF

This also adds NDEBUG, which is needed for assert calls to work properly for release builds (i.e. should be no-op in release builds).

This would build debug and release libraries.

nmake -f win32\Makefile.msc DEBUG=1
nmake -f win32\Makefile.msc

You can find a full patch here:

https://github.com/StoneStepsInc/zlib-nuget/blob/master/patches/Makefile.msc.patch

I do realize that there's a CMake build, but I find Makefile.msc cleaner for my purposes and since it's a part of the core project, it probably should work for commonly used configurations.

@madler
Copy link
Owner

madler commented Feb 2, 2025

See #1027 .

@madler madler closed this as completed Feb 2, 2025
@gh-andre
Copy link
Author

gh-andre commented Feb 2, 2025

One thing to mention that in the past I couldn't use CMake because it was configured such that using --prefix with cmake --install failed to copy build artifacts into the specified location and instead forced a copy into the protected C:\Program Files\ directory, which some Open Source projects mistakenly consider analogous to /usr/local/. In addition to this, release builds were not configured to generate debug symbols. I guess now that nmake is gone, I will have to create patches for CMake files to address these issues.

@madler
Copy link
Owner

madler commented Feb 2, 2025

@gh-andre Try cmake on the current develop branch to see if it resolves your issues.

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