linker error with openssl (trying SH1 example)

纵饮孤独 提交于 2019-12-11 02:39:26

问题


I'm trying to compile an example of how to implement SHA1 but I keep getting this error:

[Linker Error] Unresolved external '_SHA1' referenced from C:\PROGRAM FILES (X86)\BORLAND\CBUILDER6\PROJECTS\UNIT1.OBJ

I downloaded openssl files from their website, I tried both copying the headers directory to my project directory and copying it to my includes directory, but nothing.

here's the example code:

#include <string.h>
#include <openssl/sha.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
    int i;
    unsigned char ibuf[] = "compute sha1";
    unsigned char obuf[20];

    SHA1(ibuf, strlen(ibuf), obuf);

    for (i = 0; i < 20; i++) {
        printf("%02x ", obuf[i]);
    }
    printf("\n");

    return 0;
}x

P.S: I'm using Borland C++ Builder 6


回答1:


You can add the OpenSSL .lib files to your project via "Add to project..." or use #pragma comment

#pragma comment(lib, "ssl_lib_file_here.lib")

int main(int argc, char* argv[])



回答2:


I downloaded openssl files from their website,

And

... except that there're no files with extension '.lib' in the directory the setup I downloaded installed

You need to use Shining Light's Win32OpenSSL or build OpenSSL yourself.

If you use Shining Light's version, everything is already built. While Thomas Hruska keeps Win32OpenSSL up to date with OpenSSL releases, I don't think he offers anything compatible with the version of C++ Builder 6 (circa 2002) you are using.

If you want to build OpenSSL from sources on the Win32 platform, then see INSTALL.W32 and INSTALL.W64 in the root directory of the OpenSSL distribution.

I believe you have a third option. That option is to grab a modern IDE. Microsoft offers a trial version of Visual Studio (the link for the Trial is on the right of the page). Embarcadero also offers a free trial version of C++ Builder XE5. Both should work with Shining Light's Win32OpenSSL.



来源:https://stackoverflow.com/questions/22543385/linker-error-with-openssl-trying-sh1-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!