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


非常感谢各位有相关开发经验的朋友帮忙,谢谢了。
...全文
612 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
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
  • 打赏
  • 举报
回复
应该是头文件不对……
这个是完整源码 java实现 大数据 Spark 可视化大屏+Kafka+SpringBoot+Vue3 【大数据毕业设计】基于Spark实时社交媒体舆情分析与趋势预测(Java版本+可视化大屏+Kafka+SpringBoot+Vue3) 源码+论文 完整版 数据库Mysql 随着微博、抖音、知乎、小红书等社交媒体平台的快速发展,网络舆情呈现出数据规模大、传播速度快、情绪演化复杂等特点。传统离线批处理方式难以满足舆情监测对时效性的要求,亟需构建一套能够支撑实时采集、流式计算、情感分析与趋势预测的综合系统。本文围绕“基于Spark实时社交媒体舆情分析与趋势预测”课题,设计并实现了一套前后端分离的舆情分析平台。系统后端采用Java语言与Spring Boot框架构建RESTful服务,结合JWT完成管理员身份认证与权限控制;数据处理层引入Spark思想的流式窗口统计与Kafka消息缓冲机制,对社交媒体帖文进行情感倾向识别、热度指数计算和按小时窗口聚合;趋势预测模块基于历史热度序列构建多元线性回归模型,输出未来窗口的热度预测值,并采用RMSE、MAE、MAPE等指标评价预测效果;前端采用Vue3、Vue Router、Pinia、Element Plus与ECharts实现管理后台与数据可视化大屏,支持帖文管理、话题管理、实时舆情查看、趋势对比和个人中心维护等功能。数据库选用MySQL,库名为db_social_opinion,核心业务表均以t_前缀命名,覆盖管理员、用户、平台、话题、帖文、实时统计、预测结果与误差指标等实体。测试结果表明,系统能够稳定完成舆情事件模拟、实时统计刷新与趋势预测展示,界面日期时间统一采用“2026-11-02 17:25:17”格式,满足本科毕业设计对完整性、规范性与可演示性的要求。本文工作对高校舆情教学实验、中小规模舆情监测系统原型开发具有一定

70,038

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧