如何将OpenSSL与emscripten链接? [英] How to link OpenSSL with emscripten?

查看:371
本文介绍了如何将OpenSSL与emscripten链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译一些使用OpenSSL和emscripten的C代码,但是出现未解决的符号警告,例如:

I'm trying to compile some C code that uses OpenSSL with emscripten, but I get unresolved symbol warnings like:

warning: unresolved symbol: SHA256_Init
warning: unresolved symbol: SHA256_Final
warning: unresolved symbol: SHA256_Update

我使用以下命令编译了代码:

I compiled the code using this command:

emcc SHA256.c -lssl -lcrypto -L /usr/local/openssl-1.0.2k/lib/ -I /usr/local/openssl-1.0.2k/include -s WASM=1 -o SHA256.html --emrun

带有以下源代码

#include <stdio.h>
#include <string.h>
#include <stdlib.h>


#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>


void sha256(char *string, char outputBuffer[65])
{
    unsigned char hash[SHA256_DIGEST_LENGTH];
    SHA256_CTX sha256;
    SHA256_Init(&sha256);
    SHA256_Update(&sha256, string, strlen(string));
    SHA256_Final(hash, &sha256);
    int i = 0;
    for(i = 0; i < SHA256_DIGEST_LENGTH; i++)
    {
        sprintf(outputBuffer + (i * 2), "%02x", hash[i]);
    }
    outputBuffer[64] = 0;
}


int main (void)
{
    static unsigned char buffer[65];
    sha256("string", buffer);
    printf("%s\n", buffer);

    return 0;
}

推荐答案

使用emscripten而不是使用系统版本来编译两个库:crypto和openssl.

Compile the two libraries : crypto and openssl with emscripten, rather than using the system versions.

将为这些库生成的.bc文件用作em ++命令的链接器参数,它应该可以工作.

Use the generated .bc files for these libraries as linker arguments to the em++ command and it should work.

这篇关于如何将OpenSSL与emscripten链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆