静态链接为什么不通过?
时间:2011-05-02
来源:互联网
但是 -I已经指明了头文件位置了,-L选项指明了库文件位置了。
C/C++ code
[pro@rhel5 ~/openssl 06:32:10]$gcc -Wall -static -I/usr/local/openssl1.0.0d/include/ -L/usr/local/openssl1.0.0d/lib -lcrypto rsagen.c -o rsagen /tmp/ccqG3FNz.o: In function `main': rsagen.c:(.text+0x3d): undefined reference to `RSA_generate_key' collect2: ld returned 1 exit status [pro@rhel5 ~/openssl 06:32:11]$ [root@rhel5 ~ 06:33:17]#ll /usr/local/openssl1.0.0d/ total 16 drwxr-xr-x 2 root root 4096 Apr 4 04:40 bin drwxr-xr-x 3 root root 4096 Apr 4 04:40 include drwxr-xr-x 4 root root 4096 Apr 4 04:40 lib drwxr-xr-x 6 root root 4096 Apr 4 04:40 ssl [root@rhel5 ~ 06:33:28]#ll /usr/local/openssl1.0.0d/lib/ total 3044 drwxr-xr-x 2 root root 4096 Apr 4 04:40 engines -rw-r--r-- 1 root root 2651972 Apr 4 04:40 libcrypto.a -rw-r--r-- 1 root root 442488 Apr 4 04:40 libssl.a drwxr-xr-x 2 root root 4096 Apr 4 04:40 pkgconfig [root@rhel5 ~ 06:33:47]#ll /usr/local/openssl1.0.0d/include/ total 4 drwxr-xr-x 2 root root 4096 Apr 4 04:40 openssl [root@rhel5 ~ 06:33:52]#
源码
:
C/C++ code
#include <openssl/rsa.h> #include <openssl/engine.h> int main() { RSA *r=RSA_generate_key(2048,RSA_3,NULL,NULL); return 0; }
作者: dungeonsnd 发布时间: 2011-05-02
作者: dungeonsnd 发布时间: 2011-05-02
作者: aa_qq110 发布时间: 2011-05-02
另外,.o文件不是用-L链接的吧。。。。。并且也没见到你链接其它的库,估计你的函数就是那个.o文件里,想要用-L链接,把.o文件用ar打包成静态库,或者用gcc -shared生成动态库
作者: Arnold9009 发布时间: 2011-05-02
直接这样可以正常编译和运行。
gcc -Wall -static rsagen.c -lcrypto -o rsagen
这样的话估计是链接到系统自己的原来版的openssl库了。
作者: dungeonsnd 发布时间: 2011-05-02
:
已经编译了。
TO 3L
:
是.a 的库,不是.o的目标文件哦。
作者: dungeonsnd 发布时间: 2011-05-02
[pro@rhel5 ~/openssl 07:19:54]$gcc -Wall -static -I/usr/local/openssl1.0.0d/include/ -L/usr/local/openssl1.0.0d/lib rsagen.c -lcrypto -o rsagen
/usr/local/openssl1.0.0d/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x2d): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x43): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4d): undefined reference to `dlclose'
/usr/local/openssl1.0.0d/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x8f): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0xe8): undefined reference to `dlerror'
/usr/local/openssl1.0.0d/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x43d): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x514): undefined reference to `dlerror'
/usr/local/openssl1.0.0d/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x5a1): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x67d): undefined reference to `dlerror'
/usr/local/openssl1.0.0d/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x6e3): undefined reference to `dlclose'
/usr/local/openssl1.0.0d/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x7b7): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x828): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x86d): undefined reference to `dlerror'
collect2: ld returned 1 exit status
在网上查了一下,说要链接libdl即加上 -dl,但是不还是不行啊.
[pro@rhel5 ~/openssl 07:20:10]$gcc -Wall -static -I/usr/local/openssl1.0.0d/include/ -L/usr/local/openssl1.0.0d/lib rsagen.c -lcrypto -o rsagen -ldl
/usr/local/openssl1.0.0d/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x2d): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
[pro@rhel5 ~/openssl 07:20:22]$
作者: dungeonsnd 发布时间: 2011-05-02
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28