Jump to content
Sign in to follow this  
hisoka

compilation of zlib in cygwin

Recommended Posts

I have windows 7 64 bit and Cygwin installed on it . I have zlib open source version 1.2.11 from https://zlib.net/ . I would like to compile it using Cygwin but I have no idea how to do it from the beginning til the end and step by step . Although I googled in the internet about how to compile zlib in cygwin , not only I did not find many articles , but the few I found were of no help to me as they do not show how to do the work step by step and in a simple way . Moreover , I read the zlib manual but there is not mentioned how to compile zlib . So any help on how to compile zlib in cygwin will be really appreciated

Share this post


Link to post
Share on other sites

In general, you compile it the same way you compile anything else.  You need the source code, any dependencies, and a compiler for whatever language was used to write it.

  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you for your reply justsomeguy . After reading your reply , which helped me , I , now ,  know how to compile a single C or C++ source code  using GCC and G++ in Cygwin windows . However , the ZLIB folder I installed from the https://zlib.net/  website  has many source code files with .C and .CPP extensions . In addition to that ,  it has many different other files with different extensions like  MSC ,  RAW , PAS , ADB , ADS

1) what I know is that the only files I should compile , using command lines with GCC and G++ compilers  in cygwin , are the ones with .C and .CPP  extensions (if I am wrong please correct me ) . There are , in the ZLIB folder , however , many files with .C and .CPP . should they ALL be compiled or SOME of them ? if they should all be compiled ,  should I compile them one by one  or all in the same time ? and  If I should compile them all in the same time , should I put them together in a one separated folder then compile them at once ?   because they are scattered  in different folders . Or It is enough to write there names all  in Cygwin in one command line and thus Cygwin compiler will compile them all in the same time ?

 

2) what are the roles of the other different extensions i mentioned above ? for example PAS extension is pascal . What has pascal to do with our zlib program written in C ? RAW extension is used by cameras what has this to do with zlib program for compression and decompression and the same for ADB and ADS which are database files ????

 

 

 

Edited by hisoka

Share this post


Link to post
Share on other sites

The folder contains a readme file, did you read it?  It tells you how to compile it.  There's also a FAQ, and there's an index file which describes the other files.  If you're talking about files in a directory like contrib, did you read the readme.contrib file?  Inside the pascal folder in the contrib folder, did you read the readme.txt file?

What has pascal to do with our zlib program written in C ?

What if you're writing a program in Pascal and want to use zlib?

RAW extension is used by cameras what has this to do with zlib program for compression and decompression and the same for ADB and ADS which are database files ????

I can name a file anything I want, it doesn't mean that it's whatever a website says a certain file extension is for, and it doesn't mean that Windows will open the correct program if I just double-click on it.  If I rename a picture file with a .adb extension, does that mean that picture is now a database?  If you open one of those adb files in a text editor, do you see a database?

  • Thanks 1

Share this post


Link to post
Share on other sites

OK , I read them as you told me . and in the README file it is mentioned how to compile it . Now , however , I have another problem which is more complicated than the first :

During the building process in cygwin , I got this error :

$ ./configure
Checking for gcc...
Checking for shared library support...
No shared library support.
Building static library libz.a version 1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... No.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... No.


$ make test
gcc -O3 -I. -c -o example.o test/example.c
gcc -O3  -c -o adler32.o adler32.c
gcc -O3  -c -o crc32.o crc32.c
gcc -O3  -c -o deflate.o deflate.c
gcc -O3  -c -o infback.o infback.c
gcc -O3  -c -o inffast.o inffast.c
gcc -O3  -c -o inflate.o inflate.c
gcc -O3  -c -o inftrees.o inftrees.c
gcc -O3  -c -o trees.o trees.c
gcc -O3  -c -o zutil.o zutil.c
gcc -O3  -c -o compress.o compress.c
gcc -O3  -c -o uncompr.o uncompr.c
gcc -O3  -c -o gzclose.o gzclose.c
gcc -O3  -c -o gzlib.o gzlib.c
gzlib.c: In function ‘gz_open’:
gzlib.c:243:20: warning: implicit declaration of function ‘_wopen’; did you mean  ‘fwopen’? [-Wimplicit-function-declaration]
         fd == -2 ? _wopen(path, oflag, 0666) :
                    ^~~~~~
                    fwopen
gcc -O3  -c -o gzread.o gzread.c
gcc -O3  -c -o gzwrite.o gzwrite.c
ar rc libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.     o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
gcc -O3 -o example.exe example.o -L. libz.a
libz.a(gzlib.o):gzlib.c:(.text+0xab2): undefined reference to `_wopen'
libz.a(gzlib.o):gzlib.c:(.text+0xab2): relocation truncated to fit: R_X86_64_PC3  2 against undefined symbol `_wopen'
libz.a(gzlib.o):gzlib.c:(.text+0xc50): undefined reference to `_wopen'
libz.a(gzlib.o):gzlib.c:(.text+0xc50): relocation truncated to fit: R_X86_64_PC3  2 against undefined symbol `_wopen'
collect2: error: ld returned 1 exit status
make: *** [Makefile:289: example.exe] Error 1

I checked this link for help :

https://stackoverflow.com/questions/42537454/compiling-gcc-7-20170212-on-windows-7-64-with-cygwin-wopen-error

There is it is mentioned :

Quote

but it is not mentioned how these patches are done . I do not know how to do those patches . Or if there is another solution for how to solve the above error , I will be very thankful and glad to see it . 

 

 

Share this post


Link to post
Share on other sites

Those are diff files.  They describe changes to a file.  The + and - describe lines that have been added or removed.

  • Thanks 1

Share this post


Link to post
Share on other sites

You are the best justsomeguy . The problem is solved and I do not see the error anymore . Here is the result :

$ make test
gcc -O3 -I. -c -o example.o test/example.c
gcc -O3  -c -o adler32.o adler32.c
gcc -O3  -c -o crc32.o crc32.c
gcc -O3  -c -o deflate.o deflate.c
gcc -O3  -c -o infback.o infback.c
gcc -O3  -c -o inffast.o inffast.c
gcc -O3  -c -o inflate.o inflate.c
gcc -O3  -c -o inftrees.o inftrees.c
gcc -O3  -c -o trees.o trees.c
gcc -O3  -c -o zutil.o zutil.c
gcc -O3  -c -o compress.o compress.c
gcc -O3  -c -o uncompr.o uncompr.c
gcc -O3  -c -o gzclose.o gzclose.c
gcc -O3  -c -o gzlib.o gzlib.c
gcc -O3  -c -o gzread.o gzread.c
gcc -O3  -c -o gzwrite.o gzwrite.c
ar rc libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
gcc -O3 -o example.exe example.o -L. libz.a
gcc -O3 -I. -c -o minigzip.o test/minigzip.c
gcc -O3 -o minigzip.exe minigzip.o -L. libz.a
hello world
zlib version 1.2.11 = 0x12b0, compile flags = 0xa9
uncompress(): hello, hello!
gzread(): hello, hello!
gzgets() after gzseek:  hello!
inflate(): hello, hello!
large_inflate(): OK
after inflateSync(): hello, hello!
inflate with dictionary: hello, hello!
                *** zlib test OK ***

 

but I am really still confused . After  building ,  I do not see any EXE  file . Instead , I got these files and folders :

folders : include , lib , share

files : zconfig.h , zlib.h , zlib.pc , libz.a , zlib.3

What I am missing?

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

One of those files, I assume zlib.3, is a shared library like a DLL that you can import and use in other languages.  That's what zlib is - a shared library.

Share this post


Link to post
Share on other sites

You mean that my compilation succeeded and that the above files I got , after compilation , are the right files  ?? should not I get , for example , after compilation , a file with a DLL extension ? Are these above files what I am supposed to get after compilation of zlib source code ?

Edited by hisoka

Share this post


Link to post
Share on other sites

should not I get , for example , after compilation , a file with a DLL extension ?

If you were compiling a library for Windows, then that would be common.

Remember that the part after the dot in a filename is just as meaningless as the part before it.  Don't assume that just because Windows keeps a list of programs to run when you double-click on a file with a certain extension, that means that there is some rule out there about filename extensions.  Our CentOS servers mostly use .so files for the same purpose.  Many of them don't have an extension at all.

Are these above files what I am supposed to get after compilation of zlib source code ?

Since it looks like the compilation worked, then my guess is yes.  I have no experience with Cygwin though.

Share this post


Link to post
Share on other sites
Quote

Remember that the part after the dot in a filename is just as meaningless as the part before it

1) with due all respect , Sir , I do not agree with you . The file extension is not meaningless because it tells with what program should the file be opened . If you have a jpg extension file , that is a photo ,  and try to open it with a Winrar program or any other program  instead of a photo viewer  ,  the photo will not be opened and an error will be triggered . The extension tells with what program should the file be opened . Moreover , if I change the extension of the photo from jpg to txt and open it with notepad will I be able to see a photo ? no , i will see garbage characters in the text file . So how can you tell me that the extension is meaningless ?

2) in this link : http://www.winimage.com/zLibDll/minizip.html

it is mentioned the following :

Quote

Now, with version 1.23 and 1.14 of zLib, the Minizip library is inlucded in the contrib/minizip directory

which is the case for me . So I have minizip library in the contrib/minizip directory and I read all the files there like configure , makefile , minizip64-info.txt ... but i do not know how to compile minizip as it is not mentioned how to compile it in the above files . and not in the whole zlib directories

Share this post


Link to post
Share on other sites

The file extension is not meaningless because it tells with what program should the file be opened . 

No, the file extension doesn't tell anyone anything, the operating system keeps a list of file extensions and associated programs.  That information is not stored with the file, it is not stored inside the file data or in the filename.  That is a feature of the operating system, not the file and not the filename.

The point is that there is not some magical thing with filenames or some set of rules for how they need to be named or which files with which names need to be used for which purposes.  Is it up to programmers to define those.  If I want to write a program called Poorly Notated German, and I decide to write my binary data files using a .png extension, I can do that.  If I want to change the Windows file associations to use my program to open .png files instead of the default, I can do that too.  The point of all of this is that filenames are arbitrary and do not contain any information, the operating system is what makes the link between file extensions and programs.  So any compiler is not obligated to produce a file with a .dll extension if what you have made is a linked library/shared object.  Again, it is left up to the programmer, and you can see them specify the filename in the build command:

ar rc libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o

It's right there at the beginning - that looks like a command to a linker or something to combine all of those object files and produce a file called libz.a.  They could have written libz.dll there, but they didn't, because it doesn't matter.  If the thing you're focused on is which names they decided to call their files, that's the wrong thing to focus on.  That's my point, and that's why I say the filenames are meaningless.

but i do not know how to compile minizip

Well, I don't know either.  If it was me, I would try some make commands.  I would go to the project homepage as given in the text file and look for resources there.

Share this post


Link to post
Share on other sites

OK , if the file extension does not tell anyone anything and if it is up to the programmer to decide the name of the extension and how the file should be opened and so on ... how am I  supposed to know , faced with a file ,  what is the right program to use to open it !? I cannot meet the programmer who programmed it to ask him :)

So what should I do then ?

Edited by hisoka

Share this post


Link to post
Share on other sites

how am I  supposed to know , faced with a file ,  what is the right program to use to open it !?

Well, the only information about the file that you have, other than the name, is the contents.  If you can't determine what program you're supposed to use by looking at the contents of the file, then it's pretty hard to figure that out without documentation about whatever the file is.  I guess a programmer could add a text portion at the top of their file describing the contents of the file, but most of the time they don't do that.

Share this post


Link to post
Share on other sites
Quote

Well, the only information about the file that you have, other than the name, is the contents

I have a file with a text extension . When I opened it with a notepad , I noticed , apart from the plain text in it , thousands of  garbage characters . Let me apply what I learnt : the extension does not tell anyone anything . Therefore I need to look at the content . The content is a mixture of Unicode-like garbage characters , in its majority , and plain text , in its minority . I think , based on the content of that text file , it is an EXE  but i am not sure . I can be wrong . Could you please , look at the file content and tell me , suppose you have an approximate  idea ,  what is the right program , based on its content of course ,  to use to open it  ? because  I am sure it is NOT notepad . I attached the file with my post

.text

Edited by hisoka

Share this post


Link to post
Share on other sites

If it's an executable, then you don't need a program to open it, you can just execute it.  You can't really tell just by looking at binary data what that data is supposed to represent though, we've already had this discussion in another topic.

Share this post


Link to post
Share on other sites
Quote

If it's an executable, then you don't need a program to open it, you can just execute it

how ? you mean by double click on it ?

Quote

though, we've already had this discussion in another topic

Could you provide me with  the link of the other topic so that i can revise it again because I do not know where did we have the same discussion

Quote

You can't really tell just by looking at binary data

in the .text file , there no binary data but a garbage of Unicode characters

Share this post


Link to post
Share on other sites

how ? you mean by double click on it ?

If it's Windows, I suppose you need to change the file type to a .exe so that Windows tries to execute it when you double-click on it.  If you're typing commands into a console you just type the name of it, as long as it has execute permission.

This is where we talk about trying to divine some sort of meaning from binary data:

http://w3schools.invisionzone.com/topic/57997-knowing-what-is-the-hex-number/

in the .text file , there no binary data but a garbage of Unicode characters

Again, we've already talked about this.  It's binary data.  Just because you're opening it with a program that tries to display everything as text doesn't change the nature of the file.

  • Like 1

Share this post


Link to post
Share on other sites

Yes yes yes :) I did understand you very well but . It is only that I forget . Thank you for remembering me . I change the file to .exe and run it as administrator but to my surprise I got an error that says :

Windows cannot find key.exe make sure you typed the name correctly and try again . I did many researches , through googling the error , but none of the solutions I found in google helped me solve my problem . I am lost and really stuck and do not know how to solve my problem . Help

Share this post


Link to post
Share on other sites

the file I am trying to run is the file with the text extension I sent to you . I changed its extension to .exe and I named it key then I run it as administrator but I got the above error .

 

Edited by hisoka

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×