📄 software-building.txt
字号:
make includes make 当然它不能正常运作... _________________________________________________________________ gcc -o xscrab -O2 -O -L/usr/X11R6/libinit.o xinit.o misc.o moves.o cmove.o main.o xutils.o mess.o popup.owidgets.o display.o user.o CircPerc.o-lXaw -lXmu -lXExExt -lXext -lX11 -lXt -lSM -lICE -lXExExt -lXext -lX11-lXpm -L../Xc -lXcBarGraf.o(.text+0xe7): undefined reference to `XtAddConverter'BarGraf.o(.text+0x29a): undefined reference to `XSetClipMask'BarGraf.o(.text+0x2ff): undefined reference to `XSetClipRectangles'BarGraf.o(.text+0x375): undefined reference to `XDrawString'BarGraf.o(.text+0x3e7): undefined reference to `XDrawLine'etc.etc.etc... _________________________________________________________________ 我在 [11]comp.os.linux.x 的新闻群组询问过, 而且有些人好心的指出似乎 Xt, Xaw, Xmu, 和 X11 libs 没有让连结器(linker)找得到. 嗯... 有两个主要的 Makefiles, 而且在 src 目录下的那个让我感兴趣. 在 Makefile 一行有定义 LOCAL_LIBS 成: LOCAL_LIBS = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) 这所指的 libs 并没有被连结器找到. 找找下个指到 LOCAL_LIBS 的地方, 我看到该在 Makerfile 的495行: $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBS) $(LDLIBS)$(EXTRA_LOAD_FLAGS) 而现在 LDLIBS 是什麽呢? LDLIBS = $(LDPOSTLIB) $(THREADS_LIBS) $(SYS_LIBRARIES)$(EXTRA_LIBRARIES) SYS_LIBRARIES 是: SYS_LIBRARIES = -lXpm -L../Xc -lXc 是个! 就是这样遗失 libraries. 大概连结器需要在 LOCAL_LIBS 之前看到 LDLIBS... 所以, 第一件事要尝试去修 改 Makefile 就是改写在495行的 $(LOCAL_LIBS) 和 $(LDLIBS) , 所以它现在变 成: $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LDLIBS) $(LOCAL_LIBS)$(EXTRA_LOAD_FLAGS) ^^^^^^^^^^^^^^^^^^^^^^^ 在上面的改後,我试著再次执行 make , 瞧, 它这次可正常跑了. 当然, Xscrabble 仍然需要一些微调(fine tuning]与玩弄(twiddling), 像是重新命名 字典以及标注某些辅助的叙述在原始码档案之一, 但正因为那样,它已给我好几个 小时的消遣. 你可以寄 e-mail [12]Matt Chapman, 而且从他的 [13]home page 下载 Xscrabble. _________________________________________________________________ Scrabble 是 Milton Bradley Co., Inc. 的注册商标. _________________________________________________________________ 7. 第二个例子: Xloadimage 这个例子提出较简单的问题. xloadimage 程式加入到我的图形工作组似乎是很有 用. 我从一本由 Mui 和 Quercia 所著的好书 [14]X User Tools 所附的 CD 上 的原始码目录(source directory), 直接复制 xloadi41.gz 档案下来. 如预期 的, 用 tar xzvf 解开所有档案. 然而, make 出现了令人讨厌的错误而且中断. _________________________________________________________________ gcc -c -O -fstrength-reduce -finline-functions -fforce-mem-fforce-addr -DSYSV -I/usr/X11R6/include-DSYSPATHFILE=\"/usr/lib/X11/Xloadimage\" mcidas.cIn file included from /usr/include/stdlib.h:32, from image.h:23, from xloadimage.h:15, from mcidas.c:7:/usr/lib/gcc-lib/i486-linux/2.6.3/include/stddef.h:215:conflicting types for `wchar_t'/usr/X11R6/include/X11/Xlib.h:74: previous declaration of`wchar_t'make[1]: *** [mcidas.o] Error 1make[1]: Leaving directory`/home/thegrendel/tst/xloadimage.4.1'make: *** [default] Error 2 _________________________________________________________________ 这错误讯息含有最根本的线索. 看一下档案 image.h 的23行. _________________________________________________________________ #include <stdlib.h> _________________________________________________________________ 啊哈! 在 xloadimage, wchar_t 原始码的某处已经重复定义了在标准 include 档案 stdlib.h 已定义的东西. 首先试试将在 image.h 的23行标注(commenting out)起来, 也许 stdlib.h include 是不大需要的. 此时, build 过程没有任何重大错误. xloadimage 程式现在功能都正常. 8. 第三个例子: Fortune 最後例子需要某些 C 程式设计知识. 大部分的 Linux 软体是用 C 写的, 而且至 少学点 C 明显的对任何想软体安装的人会有助益. 恶名昭彰的(notorious) fortune 程式在每次 Linux 开机起来时秀出幽默的谚语 "fortune cookie". 不幸地 (有双关意思的), 设法在 Red Hat 发行套件 2.0.30 的核心下建立,出现了 一堆严重的错误. _________________________________________________________________ ~/fortune# make allgcc -O2 -Wall -fomit-frame-pointer -pipe -c fortune.c -ofortune.ofortune.c: In function `add_dir':fortune.c:551: structure has no member named `d_namlen'fortune.c:553: structure has no member named `d_namlen'make[1]: *** [fortune.o] Error 1make[1]: Leaving directory `/home/thegrendel/for/fortune/fortune'make: *** [fortune-bin] Error 2 _________________________________________________________________ 看一下 fortune.c, 有关联的几行在这. _________________________________________________________________ if (dirent->d_namlen == 0) continue; name = copy(dirent->d_name, dirent->d_namlen); _________________________________________________________________ 我们需要找出 dirent 的 structure, 但它没有宣告(declared)在 fortune.c 档 案中, 想用 grep dirent 来秀出是否在其它原始码的档案中, 但也没有. 然而, 在 fortune.c 档的最上方有下列这行. _________________________________________________________________ #include <dirent.h> _________________________________________________________________ 这似乎是系统函式库的 include 档案, 所以要找 dirent.h 的合理位置是在 /usr/include. 事实上, dirent.h 的确有在 /usr/include 中, 但该档没有包 含 dirent 的 structure. 然而, 参考另一个 dirent.h 档. _________________________________________________________________ #include <linux/dirent.h> _________________________________________________________________ 最後, 去 /usr/include/linux/dirent.h, 我们可找到我们所需要宣告的 structure. _________________________________________________________________ struct dirent { long d_ino; __kernel_off_t d_off; unsigned short d_reclen; char d_name[256]; /* We must not includelimits.h! */}; _________________________________________________________________ 足够地确定, 这个 structure 宣告没有包含 d_namelen, 但有一对与其相当的选 择. 其中最可能的是 d_reclen, 因为 这个 structure member 表示某样东西的 length 而且它是 short integer. 其他大略, d_ino, 可能是 inode number, 判 断它的 name 和 type. 事实上, 我们大概是处理 "directory entry" structure, 而元素表示档案属性, 它的名称, inode, 和 length (以 blocks 作 单位). 这似乎对我们的猜想很合理. 我们编辑档案 fortune.c, 而且改变在551行和553行的 d_namelen 变成 d_reclen. 再试试 make all. Success. 这次建立没有错误. 我们现在能够从 fortune 获得 "cheap thrills" 9. 哪□可找到原始码档案 现在你很渴望的使用你最新获得的知识来加入一些工具和其它好东西到你的系 统, 你可以在线上找到它们, [15]Linux Applications and Utilities Page, 或 者在很合理价位的 CD ROM 的档案, 藉由 [16]Red Hat, [17]InfoMagic, 以及其 它的. 一个众多原始码的宝库是在 [18]comp sources UNIX archive. 很多 UNIX 原始码发表在 [19]alt.sources 新闻群组. 如果你要找特别的原始码 包装的, 你可以贴在相关的 [20]alt.sources.wanted 新闻群组. 另外一个不错 的地方是查看 [21]comp.os.linux.announce 新闻群组. 要取得在 [22]Unix sources 的通信论坛, 请寄个 subscribe 讯息到那. 至於 [23]alt.sources 新闻群组的档案是在下面 ftp 站: * [24]ftp.sterling.com/usenet/alt.sources/ * [25]wuarchive.wustl.edu/usenet/alt.sources/articles * [26]src.doc.ic.ac.uk/usenet/alt.sources/articles 10. 结语 总结, 百折不挠会使什麽都变成不一样 (而且高难度挫折门槛明显会有帮助). 使 出全力,从失败中获得学习更是重要. 在每个过失的步伐, 每个失败造就了能够掌 握 建立软体艺术 的知识个体. 11. 参考与进一步阅读资料BORLAND C++ TOOLS AND UTILITIES GUIDE, Borland International, 1992,pp. 9-42.[Borland C++, ver. 3.1. 的发行手册之一. 给了很好介绍在语法和概念上,使用 Borland 在 DOS 下残馀的实作.]DuBois, Paul: SOFTWARE PORTABILITY WITH IMAKE, O'Reilly and Associates,1996, ISBN 1-56592-226-3.[这据说是完整的 imake 参考资料, 虽然我在写本文时,还未取得.]Frisch, Aeleen: ESSENTIAL SYSTEM ADMINISTRATION, O'Reilly andAssociates, 1995, ISBN 1-56592-127-5.[这是其它卓越的系统管理手册已经有概略层面的谈到建立软体.]Lehey, Greg: PORTING UNIX SOFTWARE, O'Reilly and Associates, 1995, ISBN1-56592-126-7.Mui, Linda 和 Valerie Quercia: X USER TOOLS, O'Reilly and Associates,1994, ISBN 1-56592-019-8, pp. 734-760.Oram, Andrew 和 Steve Talbott: MANAGING PROJECTS WITH MAKE, O'Reillyand Associates, 1991, ISBN 0-937175-90-0.Peek, Jerry 和 Tim O'Reilly 与 Mike Loukides: UNIX POWER TOOLS,O'Reilly and Associates / Random House, 1997, ISBN 1-56592-260-3.[很棒的概念来源, 而且有大量使用工具你可能从原始码来建立,使用在本文中讨论的方法.]Stallman, Richard M. 和 Roland McGrath: GNU MAKE, Free SoftwareFoundation, 1995, ISBN 1-882114-78-7.[应该是需要阅读的.]Welsh, Matt 和 Lar Kaufman: RUNNING LINUX, O'Reilly and Associates,1996, ISBN 1-56592-151-8.[仍然是全部 Linux 参考资料最好的, 虽然在某些地方缺少比较深入讨论.] 当然还有 make, imake, xmkmf, gcc, ldconfig, gzip, tar, 和 patch 的 man pages.References 1. mailto:thegrendel@theriver.com 2. http://personal.riverusers.com/~thegrendel/ 3. mailto:r6921068@ms.cc.ntu.edu.tw 4. file://localhost/tmp/bg5sgmltools.12324/Software-Building.txt.html#finalsteps 5. ftp://sunsite.unc.edu/ 6. http://www.lesstif.org/ 7. ftp://sunsite.unc.edu/ 8. ftp://tsx-11.mit.edu/ 9. news://comp.os.linux.x/ 10. news://comp.os.linux.development/ 11. news://comp.os.linux.x/ 12. mailto:matt@belgarath.demon.co.uk 13. http://www.belgarath.demon.co.uk/programs/index.html 14. file://localhost/tmp/bg5sgmltools.12324/Software-Building.txt.html#refs 15. http://www.redhat.com/linux-info/linux-app-list/linapps.html 16. http://www.redhat.com/ 17. mailto:orders@infomagic.com 18. ftp://ftp.vix.com/pub/usenet/comp.sources.unix/ 19. news://alt.sources/ 20. news://alt.sources.wanted/ 21. news://comp.os.linux.announce/ 22. mailto:unix-sources@pa.dec.com 23. news://alt.sources/ 24. ftp://ftp.sterling.com/usenet/alt.sources/ 25. ftp://wuarchive.wustl.edu/usenet/alt.sources/articles 26. ftp://src.doc.ic.ac.uk/usenet/alt.sources/articles
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -