How to compile NSPR by MinGW

本文详细介绍了如何使用MinGW编译Netscape Portable Runtime (NSPR)源代码的过程,包括下载、配置、编译等步骤,并针对编译过程中可能遇到的问题提供了具体的解决方案。

[How to compile NSPR by MinGW?]

 

[What’s the NSPR?]

Before introducing HOWTO, we must understand what the NSPR is. It is an abbreviation of Netscape Portable Runtime, and provides threads, thread pool, garbage collector, mutex, condition variable, etc, that are independent on the specific platforms. In short, it is a lib of platform-neutral APIs to hide the gaps of operation system. The figure 1-1 show its relationships among program and OS.


Figure 1-1 The Layer of NSPR

The friend Documentation and Training or The NSPR Reference are available in the mozilla.org website, 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.gz when I writing this article. If you like following the newer, please recheck the nspr’s release folder . Yeah, do you think that I am too verbose. Ok, let’s introduce how to compile it now.

 

[How to compile the source codes of NSPR?]

1. Download and Install MinGW in Window. Please refer to the part of FFmpeg Understanding(3. How to compile FFMPEG in Windows?) .

2. Download nspr-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. Make sure what options are available by configure.

$ ./configure --help

5. Configure it 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, please guarantee –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. Make it after finishing successfully.

$ make

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

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

$ make

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

8. Probe the root cause!

Debug 1) Check link.exe

$ which link

/bin/link.exe

Ok, it is not a proper linking position! As you 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 the original 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 a good way to do that, because it will take side-effects later. For example, when you want to use MinGW’s ‘find’ command, system will use windows’ one. Please check 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

 

As the result, I prefer to the following solution

Step 1: 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

Step 2: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. Check whether dist folder 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 proper building environment. Rich tools can help find the root-cause and save time.

2. Analyze the error information when having troubles. 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, Google maybe is your teacher: -).

 

With regards to the limited time, the article 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 .


 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值