[C] Gzip Compression #CR8 - gzip functions considered undefined references

I’ve been stuck on stage Gzip Compression #CR8 for a while now and even checked other people’s code examples to see they seem to be using the same gzip functions as me.

Some notes about my environment and code

and here’s the output i’m currently seeing

[compile] -- Build files have been written to: /app/build
[compile] [ 50%] Building C object CMakeFiles/http-server.dir/src/main.c.o
[compile] [100%] Linking C executable http-server
[compile] /usr/bin/ld: CMakeFiles/http-server.dir/src/main.c.o: in function `gzip_deflate':
[compile] main.c:(.text+0x8d): undefined reference to `deflateInit2_'
[compile] /usr/bin/ld: main.c:(.text+0xa7): undefined reference to `deflateBound'
[compile] /usr/bin/ld: main.c:(.text+0x105): undefined reference to `deflate'
[compile] /usr/bin/ld: main.c:(.text+0x11f): undefined reference to `deflateEnd'
[compile] collect2: error: ld returned 1 exit status
[compile] gmake[2]: *** [CMakeFiles/http-server.dir/build.make:97: http-server] Error 1
[compile] gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/http-server.dir/all] Error 2
[compile] gmake: *** [Makefile:91: all] Error 2
[compile] Looks like your code failed to compile.
[compile] If you think this is a CodeCrafters error, please let us know at hello@codecrafters.io.

Hey @brycegallo, you can add the following two lines to CMakeLists.txt to resolve the issue:

find_package(ZLIB REQUIRED)
target_link_libraries(http-server PRIVATE ZLIB::ZLIB)

This ensures that your project links correctly against the Zlib library.

1 Like

Thank you so much! everything’s working now

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.