我试图在我的代码中执行此功能
#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;
}
我在Xcode上遇到openssl的问题,我把它安装在文件夹/usr/local/ssl/ios/openssl-1.1.0c/中,添加了库搜索路径和Header但它给了我这个错误:
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)
你可以帮我吗?