免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1995 | 回复: 4

诡异,HP-UX GCC不能链接自定义库! [复制链接]

论坛徽章:
0
发表于 2014-01-16 19:12 |显示全部楼层
本帖最后由 sculida 于 2014-01-16 19:23 编辑

首先非常感谢各位前辈花时间浏览我的问题!
---------------------------------------------------
本机环境
HP-UX test02 B.11.11 U 9000/800 1106434635 unlimited-user license
gcc版本
Reading specs from /usr/local/lib/gcc/hppa2.0w-hp-hpux11.11/3.4.2/specs
Configured with: /scratch/njs/pkgbuild/3.3.1/hpux-11/gcc-3.4.2/configure --enable-languages=c,c++ --enable-threads=posix --disable-nls --with-gnu-as --without-gnu-ld --with-as=/usr/local/bin/as --with-ld=/usr/ccs/bin/ld --with-libiconv-prefix=/usr/local --prefix=/usr/local
Thread model: posix
gcc version 3.4.2
-------------------------------------------------
源代码部分
asdf.h
#ifndef ASDF_H
#define ASDF_H
void print();
#endif

asdf.c
#include "asdf.c"
#include <stdio.h>
void print() {printf("just pirnt\n");}

main.c
#include "asdf.h"
int main() {print();return 0;}
----------------------------------------------------------------------
编译语句
gcc -c main.c
gcc -c -fPIC asdf.c
gcc -shared -fPIC asdf.o -o libasdf.so
这三句都没问题,但是,接下来
gcc main.o -o main -L. -lasdf
提示出错
/usr/ccs/bin/ld: Can't find library: "asdf"
collect2: ld returned 1 exit status

不过,这样倒是可以的
gcc main.o libasdf.so -o main
----------------------------------------------------------------------
提问,红字那里我使用linux gcc就可以编译成功,不知这个hpux gcc怎么就不行,要不然是什么参数没设置好的原因。
想请高手指点一二。我怎样才能在这台hpux上使用自定义动态库。不胜感谢!

论坛徽章:
0
发表于 2014-01-16 22:54 |显示全部楼层
你把这两句:
gcc -c -fPIC asdf.c
gcc -shared -fPIC asdf.o -o libasdf.so
合并成一句:
gcc -shared -fPIC asdf.c -o libasdf.so
试试看。

论坛徽章:
0
发表于 2014-01-17 08:50 |显示全部楼层
回复 2# 吴楚客
谢谢吴楚客前辈。这样的我已经试过了,在最后一步链接的时候,依然是提示
/usr/ccs/bin/ld: Can't find library: "asdf"
collect2: ld returned 1 exit status


   

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:53:17
发表于 2014-01-17 09:14 |显示全部楼层

file libasdf.so
看看这个文件是不是一个真的.so。怀疑你的这个文件虽然扩展名.so,但内容是个静态.o

论坛徽章:
0
发表于 2014-01-17 15:12 |显示全部楼层
回复 4# duanlin
谢谢!但是怎么查看该文件是否是一个库文件呢?


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP