所以,在 python 中,如果我想访问 OSX 包,我可以像这样使用 objc 模块:
import objc
objc.loadBundle('CoreWLAN',
bundle_path='/System/Library/Frameworks/CoreWLAN.framework',
module_globals=globals())
在 golang 中是否有一种优雅的方法可以做到这一点,也许是使用模块?谷歌并没有找到我。我是否必须使用该语言的 C 导入功能来调用它?这可能吗?
我的具体情况是,我想读取可用接入点的 WIFI 数据、信道、信号强度和信噪比,以便与 Google Maps Geolocation API 对话。
最佳答案
Andlabs 给出了一个很好的回应,遗憾的是他没有将其作为答案。
基本上你这样使用cgo...
//cgo LDFLAGS: -framework CoreWLAN
...您可以直接调用框架。引用他的回答:
A .framework bundle contains at its top level a dynamically loaded library. In the case of the system frameworks, this dynamically loaded library's filename is the base name of the framework, and does not have the typical .dylib extension. If you are willing to use libdl directly, which means cgo, you can dynamically load this dylib and call its functions directly. But since we're using cgo at this point, there's a better way: //cgo LDFLAGS: -framework CoreWLAN and then use the API directly from cgo. – andlabs
And in fact, looking into it, CoreWLAN's API is Objective-C based, so you have no choice but to use cgo and do the latter of what I said :/ (Do not try to use the Objective-C runtime API directly; that leads to verbose, unsafe, and nonportable code.) – andlabs
关于macos - 在 golang 中导入 OSX 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32595037/
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
我已经在mountainlion上成功安装了rbenv和rubybuild。运行rbenvinstall1.9.3-p392结束于:校验和不匹配:ruby-1.9.3-p392.tar.gz(文件已损坏)预期f689a7b61379f83cbbed3c7077d83859,得到1cfc2ff433dbe80f8ff1a9dba2fd5636它正在下载的文件看起来没问题,如果我使用curl手动下载文件,我会得到同样不正确的校验和。有没有人遇到过这个?他们是如何解决的? 最佳答案 tl:博士;使用浏览器从http://ftp.rub
升级到OSXYosemite后,我现有的pow.cx安装不起作用。升级到最新的pow.cx无效。通过事件监视器重新启动它也没有成功。 最佳答案 卸载(!)并重新安装解决了这个问题。curlget.pow.cx/uninstall.sh|shcurlget.pow.cx|sh 关于ruby-on-rails-OSXYosemite更新破坏了pow.cx,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/q
如何解决这个错误:$rvminstall1.9.3Searchingforbinaryrubies,thismighttakesometime.Nobinaryrubiesavailablefor:osx/10.9/x86_64/ruby-1.9.3-p547.Continuingwithcompilation.Pleaseread'rvmhelpmount'togetmoreinformationonbinaryrubies.Checkingrequirementsforosx.Certificatesin'/usr/local/etc/openssl/cert.pem'arealr
输入rakedb:create后我得到:LoadError:Couldnotopenlibrary'sodium':dlopen(sodium,5):imagenotfound.Couldnotopenlibrary'libsodium.dylib':dlopen(libsodium.dylib,5):imagenotfound这里还有一些输出。/Users/Mao/.rvm/gems/ruby-2.0.0-p451/gems/ffi-1.9.3/lib/ffi/library.rb:133:in`blockinffi_lib'/Users/Mao/.rvm/gems/ruby-2.0
我找遍了所有我能找到的地方,但似乎找不到解决这个问题的办法。我在Lion10.8.2上使用Xcode4.5.1,并尝试为Rails项目运行bundle,但它一直卡在这上面。我正在为Heroku使用Thingem。Bolanos@Jeremys-Mac-mini⦿-1.9.3fishfarm$sudogeminstalleventmachinePassword:Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingeventmachine:ERROR:Failedtobuildgemnativeextens
当我尝试在macOSMojave(10.14.1)上构建带有ruby支持(--enable-rubyinterp)的vim(8.1.0509)时,出现错误:Infileincludedfrom/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10:fatalerror:'ru
我觉得自己像个十足的白痴,但我整天都在研究这个,却一无所获。我重新启动了几次,试图在我的OSX环境、RVM、Brew、Ruby上完全安装Ruby:每次我完成Ruby安装时,它都会在rubygems安装上触底。我不得不重新开始的原因是,在我第一次成功安装(使用打包的一体式RubyInstaller)后,RVM不会在Jewellerybox中更新,所以我无法管理我的gems-这是一个问题通过在/usr/local中而不是在我自己的目录下的系统上的初始Ruby安装。为了解决这个问题,我卸载了我所有的Ruby东西并重新开始。一切正常,直到ruby编译器在安装ruby2.0.0时开始
只是想更新到最新版本的Ruby。在ruby-lang.org/en/documentation/installation/#homebrew上,我发现你应该可以通过自制软件来完成:brewinstallruby但是,当我在“更新”后列出ruby版本(ruby-v)时,它仍然是旧版本2.0.0。Hermes:~Sancho$ruby-vruby2.0.0p481(2014-05-08revision45883)[universal.x86_64-darwin13]我碰巧列出了/usr/local/bin/的内容,我可以看到一个符号链接(symboliclink):ruby->..
将MacOS升级到10.14.2Mojave后,我无法再使用RVM安装任何Ruby版本。它总是给出这样的错误:$rvminstall2.5.3ruby-2.5.3-#removingsrc/ruby-2.5.3..Searchingforbinaryrubies,thismighttakesometime.Nobinaryrubiesavailablefor:osx/10.14/x86_64/ruby-2.5.3.Continuingwithcompilation.Pleaseread'rvmhelpmount'togetmoreinformationonbinaryrubies.Ch