Author Topic: problem with ZLIB  (Read 21755 times)

Offline maxest

  • Single posting newcomer
  • *
  • Posts: 6
problem with ZLIB
« on: February 24, 2006, 02:36:38 pm »
i need to use in my project zlib (www.zlib.net). i wrote a code, added zlibwapi.lib in Project -> Build Options -> Linker. now i try to compile the code and i get an error:
C:\Program Files\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.4\..\..\..\..\mingw32\bin\ld.exe: cannot find -lzlibwapi.lib
does anyone know what's going on?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9474
Re: problem with ZLIB
« Reply #1 on: February 24, 2006, 08:00:53 pm »
C:\Program Files\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.4\..\..\..\..\mingw32\bin\ld.exe: cannot find -lzlibwapi.lib
You want to use *.lib -> use a MS compiler (such as MSVC Toolkit, it's free).
You want to use *.a  -> use e.g. the MinGW compiler.
There is also a way to convert *.lib to *.a if you really need to use MinGW. Here is how it's done for python:

Create libpython22.a
To create Python extensions, you need to link against the Python library. Unfortunately, most Python distributions are provided with Python22.lib, a library in Microsoft Visual C++ format. GCC expects a .a file (libpython22.a to be precise.). Here's how to convert python22.lib to libpython22.a:
   1. Download pexport (from here or http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip).
   2. Get Python22.dll (it should be somewhere on your harddrive).
   3. Run : pexports python22.dll > python22.def
      This will extract all symbols from python22.dll and write them into python22.def.
   4. Run : dlltool --dllname python22.dll --def python22.def --output-lib libpython22.a
      This will create libpython22.a (dlltool is part of MinGW utilities).
   5. Copy libpython22.a to c:\python22\libs\ (in the same directory as python22.lib).

"This trick should work for all Python versions, including future releases of Python. You can also use this trick to convert other libraries."
Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: problem with ZLIB
« Reply #2 on: February 24, 2006, 10:13:44 pm »
I don't know what zlibwapi.lib is, but it does not look like the correct thing.

An easy way to use zlib with MinGW that works (I know for sure because I've done it just 2 days ago) is this:
1. Download and unpack the zlib-1.23 source zipfile
2. Open a cmd prompt and cd to the top level folder
3. type mingw32-make -f win32\Makefile.gcc
4. Wait until it is done (about 6-8 seconds), then copy the libraries (most importantly the .a and .dll) to your lib folder
(so much for setup, now for the fun stuff)
5. Make a project, write your program etc.
6. Be sure that your lib folder is in the linker's search path (normally that is the case)
7. Add z to the "Link libraries" field in project options (or alternatively, specify the absolute path)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline maxest

  • Single posting newcomer
  • *
  • Posts: 6
Re: problem with ZLIB
« Reply #3 on: February 25, 2006, 10:51:58 am »
i just knew that i would have to "compile" something, just as i did it with SDL
everything works. great THX!

Offline maxest

  • Single posting newcomer
  • *
  • Posts: 6
Re: problem with ZLIB
« Reply #4 on: February 25, 2006, 11:06:29 am »
one more problem..
i wanted to compile the same code while using ms visual c++ and it doesn't work. it gives errors:
src.obj : error LNK2001: unresolved external symbol _compress
Debug/ZLIB.exe : fatal error LNK1120: 1 unresolved externals
i don't understand, i linked zlibwapi.lib. do you know what may be the cause?
(sorry for asking about ms visual c++ on code::blocks forum but this is a very similiar problem :))

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: problem with ZLIB
« Reply #5 on: February 25, 2006, 03:06:27 pm »
Sorry, not using Visual C++...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9474
Re: problem with ZLIB
« Reply #6 on: February 25, 2006, 03:38:34 pm »
Me not eighter. :|
To be honest: If I encounter trouble with VC(6) projects I convert them into C::B. I really find C::B easier to understand when it comes to project settings and stuff. This might be an option for you, too (if you are hopefully not using MFC?!).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: problem with ZLIB
« Reply #7 on: February 25, 2006, 04:43:49 pm »
You want to use *.lib -> use a MS compiler (such as MSVC Toolkit, it's free).
You want to use *.a  -> use e.g. the MinGW compiler.

I have always believed that .lib was just for M$ compiler, but the libxml2 library used by Dev-C++ is a libxml2.lib and not a libxml2.a :? (as I was expecting). Anyway, it works :).
Probably it is a .lib done for MinGW and not for M$ a compiler.

There is also a way to convert *.lib to *.a if you really need to use MinGW. Here is how it's done for python:

Create libpython22.a
To create Python extensions, you need to link against the Python library. Unfortunately, most Python distributions are provided with Python22.lib, a library in Microsoft Visual C++ format. GCC expects a .a file (libpython22.a to be precise.). Here's how to convert python22.lib to libpython22.a:
   1. Download pexport (from here or http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip).
   2. Get Python22.dll (it should be somewhere on your harddrive).
   3. Run : pexports python22.dll > python22.def
      This will extract all symbols from python22.dll and write them into python22.def.
   4. Run : dlltool --dllname python22.dll --def python22.def --output-lib libpython22.a
      This will create libpython22.a (dlltool is part of MinGW utilities).
   5. Copy libpython22.a to c:\python22\libs\ (in the same directory as python22.lib).

"This trick should work for all Python versions, including future releases of Python. You can also use this trick to convert other libraries."
Morten.

Thanks for posting this example. Very useful :D.

Best wishes,
Michael

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9474
Re: problem with ZLIB
« Reply #8 on: February 25, 2006, 04:55:46 pm »
Thanks for posting this example. Very useful :D.
The credits go to a webpage I unfortunately have forgotten to bookmark - somewhere near google... ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline maxest

  • Single posting newcomer
  • *
  • Posts: 6
Re: problem with ZLIB
« Reply #9 on: February 25, 2006, 05:24:01 pm »
MortenMacFly: i know i'm a little mad but not crazy enough to use MFC :P i tried to make myself learn this, at least a little.. but i just couldn't :D

Offline Ti64CLi++

  • Single posting newcomer
  • *
  • Posts: 1
Re: problem with ZLIB
« Reply #10 on: August 04, 2018, 03:38:12 pm »
Sorry for this necro post


I don't know what zlibwapi.lib is, but it does not look like the correct thing.

An easy way to use zlib with MinGW that works (I know for sure because I've done it just 2 days ago) is this:
1. Download and unpack the zlib-1.23 source zipfile
2. Open a cmd prompt and cd to the top level folder
3. type mingw32-make -f win32\Makefile.gcc
4. Wait until it is done (about 6-8 seconds), then copy the libraries (most importantly the .a and .dll) to your lib folder
(so much for setup, now for the fun stuff)
5. Make a project, write your program etc.
6. Be sure that your lib folder is in the linker's search path (normally that is the case)
7. Add z to the "Link libraries" field in project options (or alternatively, specify the absolute path)

I tried your method, but she fails.
When I run mingw32-make -f win32\Makefile.gcc, cmd tells me :
Quote
gcc: error: CreateProcess: No such file or directory
win32\Makefile.gcc:85: recipe for target 'adler32.o' failed
mingw32-make: *** [adler32.o] Error 1

I don't know why.
Thanks for any help :)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2105
Re: problem with ZLIB
« Reply #11 on: August 04, 2018, 04:43:39 pm »
This has nothing to do with codeblocks... you simply fail to compile a 3th party library. You can ask at the support forum for the compiler, or better for the library... But here you probably won't find help...