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 zlib.h when build with CMake off current source tree (solved) #558

Closed
a-ma72 opened this issue Apr 29, 2021 · 2 comments
Closed

Comments

@a-ma72
Copy link

a-ma72 commented Apr 29, 2021

I have to compile zlib off my source tree an install the output into my project. I use this CMakeLists.txt for that:

# https://github.com/madler/zlib.git
# Tag 1.2.11

# mkdir build && cd build && cmake -G "MinGW Makefiles" ..
# cmake --build . -j8
# cmake --install .

set( CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Install in project folder" FORCE )
add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR}/../../../zlib ${CMAKE_CURRENT_SOURCE_DIR}/../../../zlib/build )

On Windows10 (64bit) and MinGW compiler (TDM-GCC 9.2) and CMake 3.19.4 I get errors when build process reaches "example" and "minigzip". For both the "zlib.h" is missing.
When I change CMakeLists.txt of zlib:

#============================================================================
# Example binaries
#============================================================================

add_executable(example test/example.c)
target_link_libraries(example zlib)
# Bugfix (1 line):
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_test(example example)

add_executable(minigzip test/minigzip.c)
target_link_libraries(minigzip zlib)

if(HAVE_OFF64_T)
    add_executable(example64 test/example.c)
    target_link_libraries(example64 zlib)
    set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
    add_test(example64 example64)

    add_executable(minigzip64 test/minigzip.c)
    target_link_libraries(minigzip64 zlib)
    set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
endif()

All works fine.

Regards,
Andreas

@StefanRickli
Copy link

StefanRickli commented May 24, 2022

According to the solution provided on Stack Overflow, one could also add ${CMAKE_CURRENT_SOURCE_DIR} to the include_directories command right before the zlib part.

(In my case, the build fails on a default docker image of debian:buster)

@madler
Copy link
Owner

madler commented Feb 2, 2025

See #1027 .

@madler madler closed this as completed Feb 2, 2025
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

No branches or pull requests

3 participants