我已经安装了gcc:
$ gcc --version gcc(GCC)8.2.1 20180831 版权所有(C)2018自由软件基金会,Inc. 这是免费软件;请参阅复制条件的来源。没有 保证;甚至不是出于适销性或针对特定目的的适用性。
我正在尝试编译它:
#include <iostream>
#include <openssl/sha.h>
bool my_sha256(void* input, unsigned long length, unsigned char* md) {
SHA256_CTX context;
if (!SHA256_Init(&context)) {
return false;
}
if (!SHA256_Update(&context, (unsigned char*)input, length)) {
return false;
}
if (!SHA256_Final(md, &context)) {
return false;
}
return true;
}
int main(int argc, const char * argv[]) {
// ...........
return 0;
}
编译错误:
$ gcc main.cpp
/usr/bin/ld: /tmp/ccde3c1g.o: in function `my_sha256(void*, unsigned long, unsigned char*)':
main.cpp:(.text+0x37): undefined reference to `SHA256_Init'
/usr/bin/ld: main.cpp:(.text+0x64): undefined reference to `SHA256_Update'
/usr/bin/ld: main.cpp:(.text+0x8a): undefined reference to `SHA256_Final'
/usr/bin/ld: /tmp/ccde3c1g.o: in function `main':
main.cpp:(.text+0xd2): undefined reference to `std::cout'
/usr/bin/ld: main.cpp:(.text+0xd7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: /tmp/ccde3c1g.o: in function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x107): undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: main.cpp:(.text+0x11c): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
如何解决?