编译 C++和 Ubuntu 11.10 上的 OpenSSL
我在 Ubuntu 11.10 上编译 C++ 和 OpenSSL 项目时遇到严重问题。 编译命令是:
g++ -Wall -lssl -lm -lcrypto -I ./src ./src/server.cpp -o ./bin/server
我收到这些错误:
server.cpp:(.text+0x8ff): undefined reference to `RSA_new'
server.cpp:(.text+0x92d): undefined reference to `PEM_read_RSAPrivateKey'
server.cpp:(.text+0xa85): undefined reference to `RSA_size'
server.cpp:(.text+0xaa1): undefined reference to `RSA_size'
server.cpp:(.text+0xae7): undefined reference to `RSA_private_decrypt'
server.cpp:(.text+0xd84): undefined reference to `BF_set_key'
server.cpp:(.text+0xf1d): undefined reference to `BF_ecb_encrypt'
server.cpp:(.text+0x13c6): undefined reference to `BF_ecb_encrypt'
collect2: ld returned 1 exit status
make: *** [server] Error 1
我成功安装了 openssl 和 libssl-dev 但问题仍然存在。 我尝试在内核 3.0 的 Linux Mint 12 上编译该项目,但遇到了同样的问题。 在我使用内核 2.6 的旧 Linux 操作系统上,该项目编译并运行良好(使用相同的 Makefile 和相同的源)。 请帮我!
I got a serious problem compiling my C++ and OpenSSL project on my Ubuntu 11.10.
The compiling command is:
g++ -Wall -lssl -lm -lcrypto -I ./src ./src/server.cpp -o ./bin/server
I receive these errors:
server.cpp:(.text+0x8ff): undefined reference to `RSA_new'
server.cpp:(.text+0x92d): undefined reference to `PEM_read_RSAPrivateKey'
server.cpp:(.text+0xa85): undefined reference to `RSA_size'
server.cpp:(.text+0xaa1): undefined reference to `RSA_size'
server.cpp:(.text+0xae7): undefined reference to `RSA_private_decrypt'
server.cpp:(.text+0xd84): undefined reference to `BF_set_key'
server.cpp:(.text+0xf1d): undefined reference to `BF_ecb_encrypt'
server.cpp:(.text+0x13c6): undefined reference to `BF_ecb_encrypt'
collect2: ld returned 1 exit status
make: *** [server] Error 1
I successfully installed openssl and libssl-dev but the problem persists.
I tried to compile the project on Linux Mint 12 with the kernel 3.0 and I had the same problem.
On my old Linux OS with the kernel 2.6 the project compiled and worked fine (using the same Makefile and the same sources).
Please help me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常,您需要在引用它们的代码后面添加
-l
链接标志。尝试Generally you need to have the
-l
link flags after the code that references them. Try正如 此答案 的评论所述,链接器仅查找未定义的符号以按照列出参数的顺序包含。
也就是说,如果您的 cpp 文件使用这些库,则这些库必须列在 cpp 文件之后。
As the comment to this answer states, the linker only looks for undefined symbols to include in the order the parameters are listed.
That is, if your cpp file uses the libraries, the libraries have to be listed after the cpp file.
这些错误来自加密库,请检查 ssl 和加密库是否在 /usr/lib 中可用,或者检查您安装的位置(如果没有安装它们),并且您是否在编译命令中设置了 libssl 和 libcrypto 的库搜索路径?
Those error are from crypto library, check whether ssl and crypto libraries are available in /usr/lib or where ever u installed if not install them and have u set the library search path for libssl and libcrypto in your compiling command?