How to compile NSPR by MinGW

来源:互联网 发布:淘宝网店规章制度 编辑:程序博客网 时间:2024/06/05 18:56

[How to compile NSPR by MinGW?]

 

[What’s the NSPR?]

Beforeintroducing HOWTO, we must understand what the NSPR is. It is an abbreviationof Netscape Portable Runtime, and provides threads, thread pool, garbagecollector, mutex, condition variable, etc, that are independent on the specificplatforms. In short, it is a lib of platform-neutral APIs to hide the gaps ofoperation system. The figure 1-1 show its relationships among program and OS.


Figure1-1 The Layer of NSPR

The friend Documentationand Training or The NSPR Referenceare available in the mozilla.orgwebsite, and readers can understand it deeply after investigation.

 

[Where to download the latest source codes of NSPR?]

The latest source code is nspr-4.7.3.tar.gzwhen I writing this article. If you like following the newer, please recheckthe nspr’srelease folder. Yeah, do you think that I am too verbose. Ok, let’sintroduce how to compile it now.

 

[How to compile the source codes of NSPR?]

1. Downloadand Install MinGW in Window. Please refer to the part of FFmpegUnderstanding(3. How to compile FFMPEG in Windows?).

2. Downloadnspr-4.7.3.tar.gz.It is a slow FTP server, so please keep patient even if you become depressed.

3.Uncompress it in your appropriate folder.

$ tar xvzf nspr-4.7.3.tar.gz

$ cd nspr-4.7.3/mozilla/nsprpub

4. Makesure what options are available by configure.

$ ./configure --help

5. Configureit in terms of your requirements. Herein, I give a sample for reference.

$ ./configure --prefix=/mingw --disable-static --enable-shared --enable-optimize --disable-debug --enable-win32-target=WINNT --enable-nspr-threads

If your system is Windows95/98/Me, pleaseguarantee –enable-win32-target=WIN95.There are some crazy users use win3.1 or win3.2, then please set –enable-win32-target=WIN16.I am interested whether somebody is using them now?!

6. Makeit after finishing successfully.

$ make

Whathave happen? If you are lucky man, please skip step7. In my pc, “nsinstall: Command not found” is printed as error information.Please refer to step7 to overcome it: -).

7. Downloadmoztools-static.zip,and extract ‘moztools/bin/nsinstall.exe’ into ‘/mingw/bin’. Please remake it.

$ make

Whathave happen? WOW, I lose my temper, and say “TMDzzNNDzzXdujdidkqqIsmVVs”!After several minute, I become clam. I MUST make it successful in my mind!

8. Probethe root cause!

Debug 1) Check link.exe

$ which link

/bin/link.exe

Ok, it is not a proper linking position! Asyou know, we must use MS’s Linkage.

Debug 2) Where is link.exe of MS?

$ where link

/bin/link.exe

XXX/VC/bin/link.exe

Ok, we find the path of MS’s link.exe.

Debug 3) Check the order of the environment variable “PATH’

$ echo $PATH

.:/usr/local/bin:/mingw/bin:/bin: /c/Program Files/Microsoft Visual Studio:XXXXXXXX

Ok, the order is wrong, we must reorder it!

Debug 4) Open /etc/profile to reorder PATH. Comment theoriginal line in 19th and use the modified line in 20th.

$ vim /etc/profile

18 if [ $MSYSTEM == MINGW32 ]; then

 19 #  export PATH=".:/usr/local/bin:/mingw/bin:/bin:$PATH"

 20   export PATH="$PATH:.:/usr/local/bin:/mingw/bin:/bin"

 21 else

 22   export PATH=".:/usr/local/bin:/bin:/mingw/bin:$PATH"

 23 fi

Debug 5) Save /etc/profile and exit MinGW.

Debug 6) Open new MinGW to make it.

$ cd XXX/ nspr-4.7.3/mozilla/nsprpub

$ make

 

In fact, Debug 4)5)6) is not agood way to do that, because it will take side-effects later. For example, whenyou want to use MinGW’s ‘find’ command, system will use windows’ one. Pleasecheck the following command in your system to confirm whether it is true: -).

$ where find

c:/WINDOWS/system32/find.exe

C:/mytools/msys/bin/find.exe

 

Asthe result, I prefer to the following solution

Step1: Copy VC’s link to /bin folder and rename to vc_link.exe.

$ cp /c/Program/ Files/Microsoft/ Visual/ Studio/ 8/VC/bin/link.exe /bin/vc_link.exe

Step2:Edit ./config/autoconf.mk and modify link to vc_link in the 62th..

$ vim ./configu/autoconf.mk

62 LD      = vc_link

Step3:Save ./config/autoconf.mk

Step4:Make it

$ cd XXX/ nspr-4.7.3/mozilla/nsprpub

$ make

 

9. Checkwhether distfolder has shared and static libs

 

ARE YOU OK NOW?! Yes, I am a bit tired.Open-source often makes me sleep deeply at night: -)!

 

[Summarization]

1. It is very important to build a properbuilding environment. Rich tools can help find the root-cause and save time.

2. Analyze the error information when havingtroubles. It is an key factor to decide whether you can overcome it.

3. Believe that release version must be OK,and the failure is brought about by yourself. In the critical points, Googlemaybe is your teacher: -).

 

With regards to the limited time, thearticle only shows the partial options for NSPR, others will be explored later.

 

[Appendix]

If you have met any troubles when compiling source codes by linking the libs of NSPR, please refer to How to solve the linking errors when using the ATOMIC functions.