缘起
经过一段时间的努力,终于将《深入例解计算系统》看到第4章了,然后就是编译其网站上提供的Y86的工具的使用遇到一些问题。
问题描述:
/usr/bin/ld: cannot find -ltk
/usr/bin/ld: cannot find -ltcl
其makefile文件如下:
# Comment this out if you don't have Tcl/Tk on your system
#GUIMODE=-DHAS_GUI
# Modify the following line so that gcc can find the libtcl.so and
# libtk.so libraries on your system. You may need to use the -L option
# to tell gcc which directory to look in. Comment this out if you
# don't have Tcl/Tk.
TKLIBS=-L/usr/lib -ltk -ltcl
# Modify the following line so that gcc can find the tcl.h and tk.h
# header files on your system. Comment this out if you don't have
# Tcl/Tk.
TKINC=-isystem /usr/include
##################################################
# You shouldn't need to modify anything below here
##################################################
# Use this rule (make all) to build the Y86 tools. The variables you've
# assigned to GUIMODE, TKLIBS, and TKINC will override the values that
# are currently assigned in seq/Makefile and pipe/Makefile.
all:
(cd misc; make all)
(cd pipe; make all GUIMODE=$(GUIMODE) TKLIBS="$(TKLIBS)" TKINC="$(TKINC)")
(cd seq; make all GUIMODE=$(GUIMODE) TKLIBS="$(TKLIBS)" TKINC="$(TKINC)")
(cd y86-code; make all)
clean:
rm -f *~ core
(cd misc; make clean)
(cd pipe; make clean)
(cd seq; make clean)
(cd y86-code; make clean)
(cd ptest; make clean)
解决方法
1.安装tcl和tk工具:sudo apt-get install tcl8.5-dev tk8.5-dev (注意是tcl8.5-dev不是tcl8.5,两者的区别就是tcl8.5仅仅下载安装了动态连接库,tcl8.5-dev将会安装静态连接库以及相关的支持的库文件)
2.修改makefile: TKLIBS=-I/usr/lib -ltk8.5 -ltcl8.5
其实,上面出现的这个问题非常的普遍,如果是Linux下使用源代码安装各种各样的软件,或这编写各种各样的helloworld程序,很容易遇到链接程序关于链接库的问题。关于链接,《深入例解计算机系统》中有专门的一章来讨论这个问题,我要抓紧时间,争取早日看到。在gcc 命令选项中,-lxxx好像连接的是静态连接库,至于动态连接库,不是很熟悉,不太清楚,可能需要使用命令行选项进行设置。
为解决这个问题,google一下,发现一个博客介绍的挺详细的,具体内容如下:
2 安装了,版本也对了,但lib(.so.version-num)的symbolic link 不正确,没有连结到正确的函式库文件(.so)
1、32位 与 64位 冲突问题
解决 yum provides libX11.so
libX11-devel-1.3-2.el6.x86_64 : Development files for libX11
Repo : base
Matched from:
Filename : /usr/lib64/libX11.so
解决:
yum install libX11-devel-1.3-2.el6.x86_64
安装 x86_64 兼容包
ln -s libjpeg.so.6 libjpeg.so
CFLAGS = -O2 -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC
为
CFLAGS = -O2 -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC-I/home/wu/jpeg-6b/jpeg/include
参考资料
[1]http://www.eefocus.com/wicoboy/blog/13-03/292170_cdab5.html
[2]http://www.arthurtoday.com/2010/06/ubuntu-tcl-tk.html#.UjHD5iEW3eU