gpt4 book ai didi

objective-c - Ocaml链接错误objective-c( cocoa )

转载 作者:行者123 更新时间:2023-12-03 16:30:32 26 4
gpt4 key购买 nike

我正在尝试从 ocaml 中调用一些 Objective-C 代码。

stub .m

#include <Cocoa/Cocoa.h>

#define CAML_NAME_SPACE

#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/callback.h>
#include <caml/alloc.h>
#include <caml/fail.h>

CAMLprim value ml_NSLog (value str)
{
CAMLparam1 (str);
NSLog (@"%s", String_val (str));
CAMLreturn (Val_unit);
}

使用以下命令将其编译为 stubs.o:

cc -Wextra -Wall -Werror -O -g -std=c99 -pedantic-errors -Wsign-compare -Wshadow -I /Users/Iwan/.opam/4.02.3/lib/ocaml   -c -o stubs.o stubs.m

我在index.ml中的ocaml代码是:

external _NSLog: string -> unit = "ml_NSLog"

let log s = _NSLog s

let () = log "hello"

当我执行ocamlopt -o app index.ml stubs.o时,我得到:

Undefined symbols for architecture x86_64:
"_NSLog", referenced from:
_ml_NSLog in stubs.o
(maybe you meant: _ml_NSLog)
"___CFConstantStringClassReference", referenced from:
CFString in stubs.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking

为什么在这种情况下会出现错误?

最佳答案

解决方案非常简单:

ocamlopt -cclib "-framework Cocoa" -o app index.ml stubs.o

我必须将 "-framework Cocoa" 作为 c 链接器的选项...

关于objective-c - Ocaml链接错误objective-c( cocoa ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44726705/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com