Eclipse CDT下使用openssl的疑惑

lonelybug 2009-04-06 06:19:07
http://topic.csdn.net/u/20081209/19/c6e410b9-4619-46e1-a3f6-244e0e99dcfc.html?seed=297272196
这是另一个网友的帖子,虽然他已经结局了,可是并没有把解决的方法贴出来。我希望各位高手可以帮我解决一下。

我的问题跟他一摸一样。只不过我用的是CDT环境而已,最终的gcc命令行也是一样的。

我的包含包括了
#include <openssl/crypto.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
可是这不是最重要的问题,问题是,静态连接库已经做出来了,可是无论如何都出现下面的错误。


编译选项
gcc test.c -Wall -lcrypto -lssl

gcc版本
Reading specs from ../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5/configure --with-gcc --with-gnu-ld --with-gnu-as -
-host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --
enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shar
ed --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --ena
ble-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-sync
hronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special)

错误信息
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xa0c): undefined reference to `_CreateDCA@16'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xa19): undefined reference to `_CreateCompatibleDC@4'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xa2a): undefined reference to `_GetDeviceCaps@8'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xa3a): undefined reference to `_GetDeviceCaps@8'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xa50): undefined reference to `_CreateCompatibleBitmap@12'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xa5e): undefined reference to `_SelectObject@8'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xa70): undefined reference to `_GetObjectA@12'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xae1): undefined reference to `_BitBlt@36'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xaeb): undefined reference to `_GetBitmapBits@12'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xb42): undefined reference to `_SelectObject@8'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xb49): undefined reference to `_DeleteObject@4'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xb53): undefined reference to `_DeleteDC@4'
k:/dev/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libcrypto.a(rand_win.o):rand_
win.c:(.text+0xb5d): undefined reference to `_DeleteDC@4'
collect2: ld returned 1 exit status


非常感谢各位有相关开发经验的朋友帮忙,谢谢了。
...全文
469 17 打赏 收藏 举报
写回复
17 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
twlkhl 2010-08-10
http://www.openssl.cn/dispbbs.asp?boardid=2&id=10611&star=1&page=1
看这个链接也行,都有我回复的!!!
  • 打赏
  • 举报
回复
twlkhl 2010-08-10
[Quote=引用 15 楼 worcy_kiddy 的回复:]
CDT好用否?
[/Quote]
还行!
终于搞定了,答案看这里http://blog.csdn.net/pgplay/archive/2009/12/26/5081768.aspx#1469032
  • 打赏
  • 举报
回复
yui 2010-08-09
[Quote=引用 11 楼 twlkhl 的回复:]

楼上的GG,现在不是没有指定libcrypto.a和libssl.a库路径的问题,这两个库是能找到的。问题是libycrypto.a中的CreateDCA@16等一些函数用到了mingw/lib/下的libgdi32.a。看这里(问题4):http://topic.csdn.net/u/20090406/06/c4f5242d-3338-45f2-8e82-a92b93abad16.html
……
[/Quote]

呵呵,你说的环境我没试过,不过,指定LD_LIBRARY_PATH环境变量,或者创建动态链接应该有效吧?
  • 打赏
  • 举报
回复
twlkhl 2010-08-09
http://blog.csdn.net/pgplay/archive/2009/12/26/5081768.aspx#1469032
不好意思,刚才链接发错了,是这个!
  • 打赏
  • 举报
回复
twlkhl 2010-08-09
楼上的GG,现在不是没有指定libcrypto.a和libssl.a库路径的问题,这两个库是能找到的。问题是libycrypto.a中的CreateDCA@16等一些函数用到了mingw/lib/下的libgdi32.a。看这里(问题4):http://topic.csdn.net/u/20090406/06/c4f5242d-3338-45f2-8e82-a92b93abad16.html
我的问题是怎么按这个贴中的解决方法添加libgdi32.a库呢??环境:Eclipse + CDT + MINGW4.4.0 + Qt4.6.0,谢谢!
  • 打赏
  • 举报
回复
yui 2010-08-09
try

gcc test.c -Wall -lcrypto -lssl

-->

gcc test.c -Wall -Lpath/to/your/lib/of/openssl -lcrypto -lssl
  • 打赏
  • 举报
回复
twlkhl 2010-08-09
顶!!!!同样的问题,很棘手!怎么木大神来指点指点呢!
  • 打赏
  • 举报
回复
黑泡泡选手 2010-08-09
CDT好用否?
  • 打赏
  • 举报
回复
twlkhl 2010-08-09
我必须用静态库哈,没办法哇!
  • 打赏
  • 举报
回复
帮顶下吧。
  • 打赏
  • 举报
回复
lonelybug 2009-04-06
另外,为什么每个版本的变异方法都不太一样呢?我的这个版本是openssl-0.9.8k
  • 打赏
  • 举报
回复
lonelybug 2009-04-06
我用的是INSTALL.W32文件里面说的方法建立的mingw下的.a的文件,而且4个.a的文件都建立了。
GNU C (MinGW)
-------------

* Compiler installation:

MinGW is available from http://www.mingw.org. Run the installer and
set the MinGW bin directory to the PATH in "System Properties" or
autoexec.bat.

* Compile OpenSSL:

> ms\mingw32

This will create the library and binaries in out. In case any problems
occur, try
> ms\mingw32 no-asm
instead.

libcrypto.a and libssl.a are the static libraries. To use the DLLs,
link with libeay32.a and libssl32.a instead.

See troubleshooting if you get error messages about functions not having
a number assigned.

* You can now try the tests:

> cd out
> ..\ms\test

最重要的是,都测试通过了,不过就是不能和我的程序编译,不知道.a文件属于静态文件,还时不时需要其它文件支持呢?
  • 打赏
  • 举报
回复
lonelybug 2009-04-06
不好意思LS朋友,我忘了说了,我实在Eclipse下CDT来写程序的。
我已经得到了那个文章中说得所有的问见,可是不知道为什么。

之前提示说找不到ssl,当我把路径设置正确之后,就出现一对这种错误。

  • 打赏
  • 举报
回复
morris88 2009-04-06
OpenSSL is written on plain old C, which means that as long as compilers use common object file format, you can easily link object files and static libraries, produced by one compiler, with another.

GNU MinGW32 compiler uses COFF object format, same as Microsoft Visual studio. It just has different naming convention. Rename libssl.a, produced with MinGW to ssl.lib, and you can use it in MSVC.
  • 打赏
  • 举报
回复
morris88 2009-04-06
详细说明见:http://vitus.wagner.pp.ru/articles/openssl-mingw.html


Building static version
Download and unpack sources of openssl. It comes in the tar.gz archive. Any build environment mentioned above includes tar program which is used to unpack archives.

Open command window (or terminal window on Unix), make sure that cygwin (or all of msys, mingw and ActiveState perl) directories are in your PATH (on Unix cross compiler automatically installed into PATH and perl is already there), change into top-level directory of unpacked source.

Open Configure script with text editor, find line

$IsMK1MF=1 if ($target eq "mingw" && $^O ne "cygwin" && !is_msys());
and comment it out (or delete altogether). If you are using Cygwin perl, you can omit this step. Condition would be false anyway. But function is_msys() might not work properly, and of course it wouldn't work when cross-compiling for Unix.

Configure script. On *nix you can just start

./Configure mingw
With cygwin or ActiveState perl you'll have to feed this script to perl

perl Configure mingw
Soon you get message "Configured for mingw".

Now, you are ready to run make. In the cygwin or msys environment just type make. On unix, if you type just make, native compiler would be invoked. You have to specify crosscompiler in the CC makefile variable:

make CC=i586-mingw32msvc-gcc RANLIB=i585-mingw32msvc-ranlib
With current stable (0.9.8d) verything should go fine until rehash target would be invoked. With development branch (0.9.9) you can go into some trouble - it is development version, it supposed to be buggy. See Troubleshooting section below for some hints.

When make tells "Doing certs" it would probably complain about 'openssl' program not found in msys and about inability to run program on Unix. You can safely ignore that for a while.

After build is finished you should have openssl.exe file in the apps directory, and two library files libssl.a and libcrypto.a in the toplevel directory.

If you are on native Win32 system, you may run test suite typing

make test
If you are doing build on Unix and want to run test, you have to find windows system to do so. This system should have MSYS and perl installed.

Doing shared build
You are probably not interesting in static build. Probably you want to have OpenSSL dlls which can be used with some native Win32 application such as Miranda IM.

To achieve this, you have to add shared parameter to Configure.

perl Configure mingw shared
But there bad thing happens:

everything is compiled, cryptoeay32-0.9.8.dll is built, but when it comes to building something that depends on this dll (such as ssleay32-0.9.8.dll), you get lot of complaints about unresolved symbols.

If you examine dll with dumpbin tool from MSVC you'll see that it doesn't export anything.

Fix is quite simple:

Open Configure script with text editor, find line with mingw configuration option:

"mingw","gcc:-mno-cygwin -DL_ENDIAN....
Find fragment which defines options for dll building (it lloks like
:-mno-cygwin -shared:
and add there -Wl,--export-all, so section would look like:
:-mno-cygwin -Wl,--export-all -shared:
Then rerun Configure mingw shared and make. Anything should run fine except certificate rehash.
  • 打赏
  • 举报
回复
lonelybug 2009-04-06
那个头文件不对?能否具体说明。

  • 打赏
  • 举报
回复
mengde007 2009-04-06
应该是头文件不对……
  • 打赏
  • 举报
回复
发帖
C语言

6.6w+

社区成员

C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
帖子事件
创建了帖子
2009-04-06 06:19
社区公告
暂无公告