3

I'm trying to execute this function in my code

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stddef.h>
#include <time.h> 
#include <math.h>
#include <openssl/rand.h>

unsigned int random_uint(unsigned int limit) {
    union {
        unsigned int i;
        unsigned char c[sizeof(unsigned int)];
    } u;

    do {
        if (!RAND_bytes(u.c, sizeof(u.c))) {
            fprintf(stderr, "Can't get random bytes!\n");
            exit(1);
        }
    } while (u.i < (-limit % limit));

    return u.i % limit;
}

I have problems with openssl on Xcode, I installed it in the folder /usr/local/ssl/ios/openssl-1.1.0c/, added Library search path and Header but it gives me this error:

Ld Build/Products/Debug/ccc normal x86_64
cd /Users/edoardosavini/Downloads/ccc
export MACOSX_DEPLOYMENT_TARGET=10.12
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cla
ng -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.plat
form/Developer/SDKs/MacOSX10.12.sdk -L/Users/edoardosavini/Downloads/ccc/Build/Products/De
bug -L/usr/local/ssl/ios/openssl-1.1.0c -F/Users/edoardosavini/Downloads/ccc/Build/Product
s/Debug -filelist /Users/edoardosavini/Downloads/ccc/Build/Intermediates/ccc.build/Debug/c
cc.build/Objects-normal/x86_64/ccc.LinkFileList -mmacosx-version-min=10.12 -Xlinker -objec
t_path_lto -Xlinker /Users/edoardosavini/Downloads/ccc/Build/Intermediates/ccc.build/Debug
/ccc.build/Objects-normal/x86_64/ccc_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplica
te /usr/local/ssl/ios/openssl-1.1.0c/libssl.a -lssl -Xlinker -dependency_info -Xlinker /Us
ers/edoardosavini/Downloads/ccc/Build/Intermediates/ccc.build/Debug/ccc.build/Objects-norm
al/x86_64/ccc_dependency_info.dat -o /Users/edoardosavini/Downloads/ccc/Build/Products/Deb
ug/ccc

    Undefined symbols for architecture x86_64:
      "_RAND_bytes", referenced from:
          _random_uint in main.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

can you help me please?

jww
  • 97,681
  • 90
  • 411
  • 885
Esavini
  • 31
  • 2
  • Well, did you verify `libssl` and `libcrypto` are x86_64? Use `lipo -info ` to do so. Related: [Compilation and Installation](https://wiki.openssl.org/index.php/Compilation_and_Installation) on the OpenSSL wiki and [Build Multiarch OpenSSL on OS X](http://stackoverflow.com/q/25530429) on Stack Overflow. – jww Dec 11 '16 at 04:48
  • It tells me this: input file libcrypto.a is not a fat file Non-fat file: libcrypto.a is architecture: x86_64 @jww – Esavini Dec 11 '16 at 23:08
  • I also tried to do the same with lib sodium library and tells me that: Undefined symbols for architecture x86_64: "_randombytes_uniform", referenced from: _foo in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) – Esavini Dec 11 '16 at 23:11

0 Answers0