2017-06-23 5 views
2

ocamlの中からいくつかのobjective-cコードを呼び出そうとしています。Ocamlリンクエラーobjective-c(ココア)

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を実行すると、私はそれがstubs.oに次のコマンドでコンパイルさ

stubs.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); 
} 

取得:

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 

なぜこの場合エラーが発生しますか?

答えて

3

ソリューションは残酷に単純なものでした:

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

私はCリンカにオプションとして"-framework Cocoa"をPASしなければならなかった...