News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

problem with ZLIB

Started by maxest, February 24, 2006, 02:36:38 PM

Previous topic - Next topic

maxest

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?

MortenMacFly

Quote from: maxest on February 24, 2006, 02:36:38 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

thomas

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."

maxest

i just knew that i would have to "compile" something, just as i did it with SDL
everything works. great THX!

maxest

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 :))

thomas

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."

MortenMacFly

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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Michael

Quote from: MortenMacFly on February 24, 2006, 08:00:53 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.

Quote from: MortenMacFly on February 24, 2006, 08:00:53 PM
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
[url="http://img207.imageshack.us/img207/9728/411948picture4em.png"]http://img207.imageshack.us/img207/9728/411948picture4em.png[/url]

MortenMacFly

Quote from: Michael on February 25, 2006, 04:43:49 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

maxest

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

Ti64CLi++

Sorry for this necro post


Quote from: thomas 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)

I tried your method, but she fails.
When I run mingw32-make -f win32\Makefile.gcc, cmd tells me :
Quotegcc: 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 :)

BlueHazzard

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...