连接OpenSSL的LLVM 6错误

时间:2014-09-12 05:36:05

标签: xcode openssl xcode6gm

Xcode 6 GM及其LLVM 6给出了这个链接错误:

Undefined symbols for architecture i386:
"_fopen$UNIX2003", referenced from:
  _BIO_new_file in libcrypto.a(bss_file.o)
  _file_ctrl in libcrypto.a(bss_file.o)
  _open_console in libcrypto.a(ui_openssl.o)
"_fputs$UNIX2003", referenced from:
  _write_string in libcrypto.a(ui_openssl.o)
  _read_string in libcrypto.a(ui_openssl.o)
"_fwrite$UNIX2003", referenced from:
  _send_fp_chars in libcrypto.a(a_strex.o)
  _write_fp in libcrypto.a(b_dump.o)
  _file_write in libcrypto.a(bss_file.o)
  _file_puts in libcrypto.a(bss_file.o)
"_strerror$UNIX2003", referenced from:
  _ERR_load_ERR_strings in libcrypto.a(err.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

现在,this answer建议添加一个特别.c文件,对于上述情况,该文件将是:

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

FILE *fopen$UNIX2003( const char *filename, const char *mode )
{
    return fopen(filename, mode);
}

size_t fwrite$UNIX2003( const void *a, size_t b, size_t c, FILE *d )
{
    return fwrite(a, b, c, d);
}

void fputs$UNIX2003(const char *restrict c, FILE *restrict f)
{
    fputs(c, f);
}

char *strerror$UNIX2003(int errnum)
{
    return strerror(errnum);
}

它“有效”,但这是最好的(甚至是可取的)方法吗?

2 个答案:

答案 0 :(得分:1)

正如您所猜测的那样,不,这不是修复Xcode 6中LLVM链接器问题的明智方法。相反,假设您正在为iOS开发,您需要做的是为新iOS重建OpenSSL 8 SDK。 Here's a good project这将帮助你做到这一点。

答案 1 :(得分:0)

如果这可以节省任何人一些时间,我已经找到修复这个特定的链接器问题(将其添加到任何任何cpp文件):

extern "C"{
    size_t fwrite$UNIX2003( const void *a, size_t b, size_t c, FILE *d )
    {
        return fwrite(a, b, c, d);
    }
    char* strerror$UNIX2003( int errnum )
    {
        return strerror(errnum);
    }
    time_t mktime$UNIX2003(struct tm * a)
    {
        return mktime(a);
    }
    double strtod$UNIX2003(const char * a, char ** b) {
        return strtod(a, b);
    }
}