静态链接为什么不通过?

我想静态链接openssl的库为什么不成功? 找不到实现?
但是 -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

对了,系统RHEL5中自带一个0.9.8版的openssl,另一目录下我安装了1.0.0版的openssl,我是想用新版的来链接。

作者: dungeonsnd   发布时间: 2011-05-02

openssl是否已经编译?

作者: 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 2L
:
已经编译了。


TO 3L
:
是.a 的库,不是.o的目标文件哦。

作者: dungeonsnd   发布时间: 2011-05-02

晕死了,烦啊。。。 怎么才能链接指定目录下的.a库呀...

[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