好吧,我使用Ocamlyacc製作詞法分析器和解析器。我已經完成了我的研究,我認爲這與我的makefile沒有爲我的編譯器選擇正確的位版本或類似的東西有關?我不太瞭解makefile,這就是我問的原因。gcc ld:找不到架構x86_64的符號
我在另一臺電腦上運行我的程序,它沒有任何問題,所以它必須與我的機器有關。
這是一個MacBook Pro 64位。我正在使用Xcode 4.2.1。
這裏的生成文件:
SHELL = /bin/sh
C_C = gcc
CPP_C = g++
ifdef GPROF
C_CPP_FLAGS = -pg -O3
else
ifndef DEBUG
C_CPP_FLAGS = -O3
else
C_CPP_FLAGS = -g
endif
endif
C_LD = $(C_C)
CPP_LD = $(CPP_C)
C_YACC = bison
C_LEX = flex
AR = ar
RANLIB = ranlib
OCAML_C = ocamlc
OCAML_OPT_C = ocamlopt
ifdef GPROF
OCAML_C_FLAGS = -dtypes
OCAML_OPT_C_FLAGS = -dtypes
OCAML_LD = $(OCAML_C) -g
OCAML_OPT_LD = $(OCAML_OPT_C) -p
else
ifndef DEBUG
OCAML_C_FLAGS = -dtypes
OCAML_OPT_C_FLAGS = -dtypes
OCAML_LD = $(OCAML_C) -g
OCAML_OPT_LD = $(OCAML_OPT_C)
else
OCAML_C_FLAGS = -dtypes
OCAML_OPT_C_FLAGS = -dtypes
OCAML_LD = $(OCAML_C) -g
OCAML_OPT_LD = $(OCAML_OPT_C)
endif
endif
OCAML_MKTOP = ocamlmktop
OCAML_CP = ocamlcp
OCAML_DEP = ocamldep
OCAML_LEX = ocamllex
OCAML_YACC = ocamlyacc
OCAML_C_CPP_INC = -I $(shell $(OCAML_C) -v | tail -1 | sed -e \
's/^Standard library directory: //')
是我得到的錯誤是:
ld: symbol(s) not found for architecture x86_64
下面是完整的輸出:
make
Linking OCAML (top level) program nanoml.top
ocamlmktop -o nanoml.top -custom nano.cmo nanoLex.cmo nanoParse.cmo main.cmo \
-cc g++ -cclib ' '
/var/folders/n3/jgblhwmj40lchgq71bmgr8sw0000gn/T/camlprimbd6a63.c:784: warning: deprecated conversion from string constant to ‘char*’
.
. //The same line ALOT of times. Removed due to limit of chars in a single post.
.
/var/folders/n3/jgblhwmj40lchgq71bmgr8sw0000gn/T/camlprimbd6a63.c:784: warning: deprecated conversion from string constant to ‘char*’
ld: warning: ignoring file /usr/local/lib/ocaml/libcamlrun.a, file was built for archive which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
"_caml_alloc_dummy", referenced from:
_caml_builtin_cprim in ccZbZ9Mf.o
.
. //And many of these lines
.
"_caml_get_exception_backtrace", referenced from:
_caml_builtin_cprim in ccZbZ9Mf.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
File "_none_", line 1, characters 0-1:
Error: Error while building custom runtime system
make: *** [nanoml.top] Error 2
預先感謝您!編輯: 我只使用Ocaml。沒有C++或C需要與它鏈接。我從來沒有試過用makefile運行我的ocaml代碼,但是我可以在這臺計算機上運行其他ocaml代碼。這是第一次失敗,但這是我第一次使用makefile。
而且相同的生成文件和代碼在其他機器上工作(儘管老機器),所以我認爲這與使用64位的這一個有關。
,我發現我已經給另一個生成文件看起來像這樣:
# Generic compilation rules
%.o : %.c
@echo Compiling C file $<
$(C_C) $(C_CPP_FLAGS) $(C_CPP_INCLUDES) -c $< -o [email protected]
%.o : %.cc
@echo Compiling C++ file $<
$(CPP_C) $(C_CPP_FLAGS) $(C_CPP_INCLUDES) -c $< -o [email protected]
%.o : %.cpp
@echo Compiling C++ file $<
$(CPP_C) $(C_CPP_FLAGS) $(C_CPP_INCLUDES) -c $< -o [email protected]
%.cmi: %.mli
@echo Compiling OCAML interface $<
$(OCAML_C) $(OCAML_C_FLAGS) $(OCAML_INCLUDES) -c $< -o [email protected]
%.cmo: %.ml
@echo Compiling \(to byte code\) OCAML module $<
$(OCAML_C) $(OCAML_C_FLAGS) $(OCAML_INCLUDES) -c $< -o [email protected]
%.cmx: %.ml
@echo Compiling \(to native code\) OCAML module $<
$(OCAML_OPT_C) $(OCAML_OPT_C_FLAGS) $(OCAML_INCLUDES) -c $< -o [email protected]
%.ml: %.mll
@echo Lexing OCAML file $<
$(OCAML_LEX) $<
%.ml %.mli: %.mly
@echo Yaccing OCAML file $<
$(OCAML_YACC) $<
# Generic cleaning rules
default-clean:
rm -f *~ *.o *.cmo *.cmx .*.depend *.cmi
.PHONY: default-clean
# Generic link rules and library creation rules
#
# These rules assume that the following variables are set (when necessary):
#
# - C_EXE : name of the C executable
# - CPP_EXE : name of the C++ executable
# - OCAML_EXE : name of the OCaml executable (without suffix)
# - OCAML_TPL_EXE : name of the OCaml custom toplevel (without suffix)
# - C_CPP_LIB : name of the C/C++ library
# - OCAML_LIB : name of the OCaml library (without suffix)
# - C_CPP_EXE_OBJ : list of C/C++ objects (without suffix) to build exe
# - OCAML_EXE_OBJ : list of OCaml modules (without suffix) to build exe
# - C_CPP_LIB_OBJ : list of C/C++ objects (without suffix) to build lib
# - OCAML_LIB_OBJ : list of OCaml modules (without suffix) to build lib
# - C_CPP_LD_FLAGS : C and C++ linker flags
# - OCAML_LD_FLAGS : OCaml linker (both native and bytecode) flags
# - C_CPP_LD_LIBS : C and C++ linker libraries
# - OCAML_LD_LIBS : OCaml linker (both native and bytecode) libraries
ifdef C_EXE
$(C_EXE): $(C_CPP_EXE_OBJ:%=%.o)
@echo Linking C program [email protected]
$(C_LD) $(C_CPP_LD_FLAGS) -o [email protected] $(C_CPP_EXE_OBJ:%=%.o) $(C_CPP_LD_LIBS)
endif
ifdef CPP_EXE
$(CPP_EXE): $(C_CPP_EXE_OBJ:%=%.o)
@echo Linking C++ program [email protected]
$(CPP_LD) $(C_CPP_LD_FLAGS) -o [email protected] $(C_CPP_EXE_OBJ:%=%.o) $(C_CPP_LD_LIBS)
endif
ifdef C_CPP_LIB
$(C_CPP_LIB).a: $(C_CPP_LIB_OBJ:%=%.o)
@echo Creating C/C++ library [email protected]
$(AR) r [email protected] $?
$(RANLIB) [email protected]
endif
ifdef OCAML_EXE
$(OCAML_EXE).byte: $(C_CPP_EXE_OBJ:%=%.o) $(OCAML_EXE_OBJ:%=%.cmo)
@echo Linking OCAML \(byte code\) program [email protected]
$(OCAML_LD) $(OCAML_LD_FLAGS) -o [email protected] -custom $(OCAML_LD_LIBS:%=%.cma) $(C_CPP_EXE_OBJ:%=%.o) $(OCAML_EXE_OBJ:%=%.cmo) \
-cc $(CPP_C) -cclib '$(C_CPP_LD_FLAGS) $(C_CPP_LD_LIBS)'
$(OCAML_EXE).opt: $(C_CPP_EXE_OBJ:%=%.o) $(OCAML_EXE_OBJ:%=%.cmx)
@echo Linking OCAML \(native code\) program [email protected]
$(OCAML_OPT_LD) $(OCAML_LD_FLAGS) -o [email protected] $(OCAML_LD_LIBS:%=%.cmxa) $(C_CPP_EXE_OBJ:%=%.o) $(OCAML_EXE_OBJ:%=%.cmx) \
-cc $(CPP_C) -cclib '$(C_CPP_LD_FLAGS) $(C_CPP_LD_LIBS)'
$(OCAML_EXE).top: $(C_CPP_EXE_OBJ:%=%.o) $(OCAML_EXE_OBJ:%=%.cmo)
@echo Linking OCAML \(top level\) program [email protected]
$(OCAML_MKTOP) $(OCAML_LD_FLAGS) -o [email protected] -custom $(OCAML_LD_LIBS:%=%.cma) $(C_CPP_EXE_OBJ:%=%.o) $(OCAML_EXE_OBJ:%=%.cmo) \
-cc $(CPP_C) -cclib '$(C_CPP_LD_FLAGS) $(C_CPP_LD_LIBS)'
endif
ifdef OCAML_TPL_EXE
$(OCAML_TPL_EXE).byte: $(C_CPP_EXE_OBJ:%=%.o) $(OCAML_EXE_OBJ:%=%.cmo)
@echo Linking OCAML \(byte code\) toplevel [email protected]
$(OCAML_MKTOP) $(OCAML_LD_FLAGS) -o [email protected] -custom $(OCAML_LD_LIBS:%=%.cma) $(C_CPP_EXE_OBJ:%=%.o) $(OCAML_EXE_OBJ:%=%.cmo) \
-cc $(CPP_C) -cclib '$(C_CPP_LD_FLAGS) $(C_CPP_LD_LIBS)'
endif
ifdef OCAML_LIB
$(OCAML_LIB).cma: $(OCAML_LIB_OBJ:%=%.cmo)
@echo Creating OCAML \(byte code\) library [email protected]
$(OCAML_LD) $(OCAML_LD_FLAGS) -a -o [email protected] $(OCAML_LIB_OBJ:%=%.cmo)
$(OCAML_LIB).cmxa $(OCAML_LIB).a: $(OCAML_LIB_OBJ:%=%.cmx)
@echo Creating OCAML \(native code\) library [email protected]
$(OCAML_OPT_LD) $(OCAML_LD_FLAGS) -a -o [email protected] $(OCAML_LIB_OBJ:%=%.cmx)
endif
ifdef OCAML_CINTF
ifdef OCAML_BYTECODE_CINTF
$(OCAML_CINTF).o: $(OCAML_CINTF_OBJ:%=%.cmo)
@echo Creating OCAML \(native code\) C interface library [email protected]
$(OCAML_LD) $(OCAML_LD_FLAGS) -output-obj -o [email protected] $(OCAML_LD_LIBS:%=%.cma) $(OCAML_CINTF_OBJ:%=%.cmo)
$(OCAML_CINTF_LIB).a: $(OCAML_CINTF).o $(C_CPP_CINTF_OBJ:%=%.o)
@echo Creating C/C++ interface library [email protected]
$(AR) r [email protected] $?
$(RANLIB) [email protected]
else
$(OCAML_CINTF).o: $(OCAML_CINTF_OBJ:%=%.cmx)
@echo Creating OCAML \(native code\) C interface library [email protected]
$(OCAML_OPT_LD) $(OCAML_LD_FLAGS) -output-obj -o [email protected] $(OCAML_LD_LIBS:%=%.cmxa) $(OCAML_CINTF_OBJ:%=%.cmx)
$(OCAML_CINTF_LIB).a: $(OCAML_CINTF).o $(C_CPP_CINTF_OBJ:%=%.o)
@echo Creating C/C++ interface library [email protected]
$(AR) r [email protected] $?
$(RANLIB) [email protected]
endif
endif
# Generic dependencies creation rules
.%.mli.depend: %.mli
@echo Generating dependencies for OCAML interface $<
$(OCAML_DEP) $< > [email protected]
.%.ml.depend: %.ml
@echo Generating dependencies for OCAML module $<
$(OCAML_DEP) $< > [email protected]
啊,我看到的i386所以這是一個32位編譯器。如何讓我的g ++/gcc編譯器以32位而不是64位運行? – 2012-02-15 21:54:27
'cc -arch i386'適合我。 – 2012-02-15 22:01:44
我已經嘗試了「gcc -arch i386」和「gcc -arch amd64」。這兩個結果如下: 「ld:warning:忽略文件/usr/local/lib/ocaml/libcamlrun.a,該文件是爲歸檔而構建的,而不是被鏈接的體系結構(x86_64)」。 – 2012-02-16 04:54:47