![](/img/trans.png)
[英]LLVM on MacOs - unknown type name 'template' in standard file iosfwd
[英]cgo on macOS - unknown type name NSString
在 go 代碼中,我有以下代碼:
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -L./ ${SRCDIR}/test.dylib -framework Foundation
#include "./test.h"
#include <stdlib.h>
#include <stdio.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSString.h>
*/
import "C"
test.h 有一個帶有 NSString 的結構
在構建 go 代碼時,它顯示錯誤:未知類型名稱 'NSString' NSString nspath,
有人可以指導這里出了什么問題,因為我已經包含了適當的目標 C 庫和頭文件。
Not running OSX/iOS, but looking at github, it looks like at least some developers wrap objective-c code in the cgo preamble inside a typical C function.
這看起來是一個特別好的例子:
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <Foundation/NSBundle.h>
#import <Foundation/NSString.h>
#include <stdlib.h>
#include <string.h>
const char *assets_zip_path() {
NSString *path = [[NSBundle mainBundle] pathForResource: @"aaaaxy" ofType: @"dat"];
const char *data = [path UTF8String];
if (data == NULL) {
return NULL;
}
return strdup(data);
}
*/
import "C"
func openAssetsZip() (*os.File, error) {
pathCStr := C.assets_zip_path()
...
您也可能已經在go/mobile package 中找到了您需要的綁定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.