Chinaunix

标题: Tru64下如何编译使和用自己的动态链接库 [打印本页]

作者: ---    时间: 2004-07-28 15:07
标题: Tru64下如何编译使和用自己的动态链接库
网上又很多编译动态链接库的文章,但是几乎没有Tru64unix下的自己查看了下帮助,总结出来和大家共享。


环境: alpha ds10, Tru64 unix5.1b,  cc 编译器

首先要有一个源文件如wbc.c

1:用如下命令语句创建一个目标文件
cc -c  wbc.c
得到wbc.o

2:用如下命令连接成动态连接库文件
ld -shared -expect_unresolved '*' -o libwbc.so wbc.o
得到一个动态连接库libwbc.so,
可以使用ldd libwbc.so 和 nm  libwbc.so命令查看里边内容

3:main.c使用此动态连接库的方法如下:
cc -o main.exe libwbc.so main.c
得到可执行文件main.exe

我试验,《unix环境高级编程》上的例程都是上面的方法。
作者: ---    时间: 2004-07-28 15:09
标题: Tru64下如何编译使和用自己的动态链接库
参数的作用如下
//在man ld中
-error_unresolved
      Produce an error message and return a nonzero error status when
      unresolved symbols are encountered, except for those matching
      -expect_unresolved. This is the default behavior for linking executable
      programs.
#当遇到不明符号时产生error message and return a nonzero error status,是默认参数


-update_registry location_file
      Register the location of this shared object's segments and make sure
      they stay out of the way of others in the location_file. The
      location_file is updated if it is writable. This option is used with
      -shared.
#将加产生的so_locations,定位为location_file

You use the following switches to alter the manner in which ld searches
  -lx Search a library, libx.{so|a}, where x is a string.

-noarchive
      Require -l references to resolve to shared objects. Normally, if the
      shared object as specified by the -l is not found, the linker attempts
      to find the corresponding archive to resolve undefined symbols. This
      option disallows using those archives. Note that this option is posi-
      tion sensitive and can be used more than once on a command line. It
      affects only those options that follow it, and it is turned off by the
      next occurrence of a -noso or -so_archive option.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2