1.下载github源码
git clone https://github.com/kolyvan/kxsmb/
2.下载适配过iOS的samba
下载https://github.com/shaojiankui/samba-iOS 将samba-iOS目录里所有内容放入kxsmb根目录的samba目录下,如果没有samba目录创建一个。
Rake的时候理论上会从samba官方自动下载samba包然后解压。但是自动下载的samba会报错。
这是修改过后的samba,Xcode9 iOS11以后,废弃了system方法。所以可以找替代方法逐个修改使用到system的.c文件
system(cmd) 改为 popen(cmd, "r"),修改记录https://github.com/shaojiankui/samba-iOS/commit/e3b1dfe072e1d1e5470f94e9b1d461ac2933932d
github源码是我自己修改过后,并且rake成功的samba源码。
2.Rake
cd到kxsmb
直接执行 rake
如果编译成功会如下图所示。合并好的通用静态库在kxsmb的libs目录。
1 2 3 4 5 6 7 8 9 10 11 |
Executing xcrun lipo -create -arch armv7 samba/source3/bin/armv7/libsmbclient.a -arch arm64 samba/source3/bin/arm64/libsmbclient.a -arch i386 samba/source3/bin/i386/libsmbclient.a -arch x86_64 samba/source3/bin/x86_64/libsmbclient.a -output samba/source3/bin/universal/libsmbclient.a Executing xcrun lipo -create -arch armv7 samba/source3/bin/armv7/libtalloc.a -arch arm64 samba/source3/bin/arm64/libtalloc.a -arch i386 samba/source3/bin/i386/libtalloc.a -arch x86_64 samba/source3/bin/x86_64/libtalloc.a -output samba/source3/bin/universal/libtalloc.a Executing xcrun lipo -create -arch armv7 samba/source3/bin/armv7/libtevent.a -arch arm64 samba/source3/bin/arm64/libtevent.a -arch i386 samba/source3/bin/i386/libtevent.a -arch x86_64 samba/source3/bin/x86_64/libtevent.a -output samba/source3/bin/universal/libtevent.a Executing xcrun lipo -create -arch armv7 samba/source3/bin/armv7/libtdb.a -arch arm64 samba/source3/bin/arm64/libtdb.a -arch i386 samba/source3/bin/i386/libtdb.a -arch x86_64 samba/source3/bin/x86_64/libtdb.a -output samba/source3/bin/universal/libtdb.a Executing xcrun lipo -create -arch armv7 samba/source3/bin/armv7/libwbclient.a -arch arm64 samba/source3/bin/arm64/libwbclient.a -arch i386 samba/source3/bin/i386/libwbclient.a -arch x86_64 samba/source3/bin/x86_64/libwbclient.a -output samba/source3/bin/universal/libwbclient.a "copy samba/source3/bin/universal/libsmbclient.a -> libs" "copy samba/source3/bin/universal/libtalloc.a -> libs" "copy samba/source3/bin/universal/libtevent.a -> libs" "copy samba/source3/bin/universal/libtdb.a -> libs" "copy samba/source3/bin/universal/libwbclient.a -> libs" JakeydeMac-mini:kxsmb jakey$ |
3.报错解决
1.Xcode缺少crt_externs.h
1 2 3 4 5 6 7 |
rake aborted! Errno::ENOENT: No such file or directory @ rb_sysopen - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/crt_externs.h /Users/jakey/Desktop/kxsmb/Rakefile:52:in `copyIfNotExists' /Users/jakey/Desktop/kxsmb/Rakefile:235:in `checkExtInclude' /Users/jakey/Desktop/kxsmb/Rakefile:242:in `block in <top (required)>' Tasks: TOP => default => build_all => build_smb_armv7 (See full trace by running task with --trace) |
iOS7模拟器以后移动了crt_externs.h的位置。
crt_externs.h内容如下,创建crt_externs.h文件保存到 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include目录。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <sys/cdefs.h> __BEGIN_DECLS extern char ***_NSGetArgv(void); extern int *_NSGetArgc(void); extern char ***_NSGetEnviron(void); extern char **_NSGetProgname(void); #ifdef __LP64__ extern struct mach_header_64 * #else /* !__LP64__ */ extern struct mach_header * #endif /* __LP64__ */ _NSGetMachExecuteHeader(void); __END_DECLS |
2.提示autoconf版本错误解决办法
1 2 3 4 |
$ curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz $ tar -xzf autoconf-2.69.tar.gz $ cd autoconf-2.69 $ ./configure && make && sudo make install |
3.如果提示No Rakefile found
则需要安装 autoconf、automake、libtool
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz $ tar -xzf autoconf-2.69.tar.gz $ cd autoconf-2.69 $ ./configure && make && sudo make install //回退到上一级目录,否则安装到 autoconf 中 $ cd .. $ curl -OL http://ftpmirror.gnu.org/automake/automake-1.14.tar.gz $ tar -xzf automake-1.14.tar.gz $ cd automake-1.14 $ ./configure && make && sudo make install //回退到上一级目录,否则安装到 automake 中 $ cd .. $ curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz $ tar -xzf libtool-2.4.2.tar.gz $ cd libtool-2.4.2 $ ./configure && make && sudo make install |
4.报错'system' is unavailable: not available on iOS
1 2 3 4 5 6 7 8 9 |
../lib/util/fault.c:134:13: error: 'system' is unavailable: not available on iOS result = system(cmdstring); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdlib.h:195:6: note: 'system' has been explicitly marked unavailable here int system(const char *) __DARWIN_ALIAS_C(system); ^ 1 error generated. The following command failed: |
解决办法:
Xcode9 iOS11以后,废弃了system方法。所以可以找替代方法逐个修改使用到system的.c文件
system(cmd) 改为 popen(cmd, "r") 替代
posix_spawn也可以替代system,system(cmd) 改为 run_cmd(cmd) 替代。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <spawn.h> extern char **environ; int run_cmd(char *cmd) { pid_t pid; char *argv[] = {"sh", "-c", cmd, NULL}; int status; status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ); if (status == 0) { if (waitpid(pid, &status, 0) == -1) { perror("waitpid"); } } return status; } |
5.如果提示以下问题。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
checking whether we are big endian... configure: error: in `/Users/jakey/Desktop/kxsmb/samba/source3': configure: error: cannot run test program while cross compiling See `config.log' for more details rake aborted! ******** Build failed ******** /Users/jakey/Desktop/kxsmb/Rakefile:42:in `system_or_exit' /Users/jakey/Desktop/kxsmb/Rakefile:216:in `buildArch' /Users/jakey/Desktop/kxsmb/Rakefile:260:in `block in <top (required)>' Tasks: TOP => default => build_all => build_smb_i386 (See full trace by running task with --trace) |
解决办法,执行终端rake之前执行export(重新rake需要恢复samba文件夹到未rake状态,因为rake会生成缓存文件,我使用git 管理了下这个目录,就直接revert了,也可以直接替换成新的):
1 2 3 4 5 6 7 8 9 10 |
export samba_cv_big_endian=no export samba_cv_little_endian=yes export samba_cv_CC_NEGATIVE_ENUM_VALUES=yes export libreplace_cv_HAVE_GETADDRINFO=no export samba_cv_HAVE_WRFILE_KEYTAB=no export smb_krb5_cv_enctype_to_string_takes_krb5_context_arg=no export smb_krb5_cv_enctype_to_string_takes_size_t_arg=yes export ac_cv_file__proc_sys_kernel_core_pattern=yes rake |
4.Lib下载
我编译好的库。可以直接在ios上使用的。方便无法编译的人下载。最新编译 samba4.0.26xcode12macos11.0120201213
链接: https://pan.baidu.com/s/1VNLj-veq2snmNxuVcIAWhQ 提取码: 9hgy
特别提醒
一定要多看下博客的说明,我在macos11.01 xcode12编译就遇到了一个错误(博客中的第5个)。
按操作直接就解决了。
参考博客:
https://blog.csdn.net/lovechris00/article/details/80524801
https://blog.csdn.net/weixin_39546911/article/details/80606449
转载请注明:天狐博客 » iOS开发之macOS下kxsmb编译smb类库