【问题标题】:Compile C++ and OpenSSL on Ubuntu 11.10在 Ubuntu 11.10 上编译 C++ 和 OpenSSL
【发布时间】:2012-01-20 18:15:40
【问题描述】:

我在 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

我成功安装了 openssllibssl-dev,但问题仍然存在。 我尝试使用内核 3.0 在 Linux Mint 12 上编译项目,但遇到了同样的问题。 在我使用内核 2.6 的旧 Linux 操作系统上,项目编译并运行良好(使用相同的 Makefile 和相同的源)。 请帮帮我!

【问题讨论】:

标签: c++ g++ openssl


【解决方案1】:

通常您需要在引用它们的代码之后添加-l 链接标志。试试

g++ -Wall  -I ./src ./src/server.cpp -o ./bin/server -lssl -lm -lcrypto

【讨论】:

  • 作为新用户,请注意,除了(或什至代替)感谢之外,最好的回应是支持和/或接受最佳答案。不必是我的。
【解决方案2】:

正如this answer 的注释所述,链接器仅查找未定义符号以包含在列出参数的顺序中。

也就是说,如果您的 cpp 文件使用库,则库必须列在 cpp 文件之后。

【讨论】:

    【解决方案3】:

    这些错误来自加密库,请检查 /usr/lib 中是否有 ssl 和加密库,或者如果没有安装它们,你是否安装了它们,并且你是否在编译命令中设置了 libssl 和 libcrypto 的库搜索路径?

    【讨论】:

      猜你喜欢
      • 2012-03-07
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      相关资源
      最近更新 更多