gcc ld: symbol(s) not found for architecture x86_64

佐手、 提交于 2019-11-29 06:22:05

The interesting line is

ld: warning: ignoring file /usr/local/lib/ocaml/libcamlrun.a, file was built for archive which is not the architecture being linked (x86_64)

It tells you that your ocaml runtime is a probably a 32 bit library, instead of the 64 bits you need.

You might want to try the "-m32" flag of g++ to compile everything in 32 bits, or to install a 64 bit version of ocaml.

It looks like maybe your OCaml compiler is producing 32-bit executables. One way to tell is to say:

$ ocamlopt -config

If you see architecture i386, it's a 32-bit compiler. If you see architecture amd64, it's a 64-bit compiler. At any rate, these are the two different values I see on my Macbook Pro.

Edit

The Makefile you give doesn't really describe what you're trying to do. It just defines names for some language processors. The real Makefile is possibly elsewhere.

Since the Makefile doesn't actually say anything about what you're doing, I realized that I don't see any evidence that you're linking OCaml and C++ (or C) together. The first line of output doesn't show anything except what looks like OCaml files. Furthermore, they're named xyz.cmo, which are bytecode OCaml files. That is, they're not 32-bit or 64-bit (native) files.

Do you have some C++ and some OCaml components that need to be linked together, or is your project pure OCaml? If it's pure OCaml, I'd say the problem is all in the Makefile. You shouldn't have to worry about the architecture if you just want to run OCaml code.

If there's some C++ or C, then you need to compile it with -arch i386 (to get 32-bit objects) and then link everything together with a linker (ld) that knows it's producing a 32-bit target. (Or, as Fabrice Le Fessant says, you could install a 64-bit OCaml compler.)

A possible suggestion is to create a tiny OCaml file and just see if you can compile and run it.

Using the bytecode compiler, it looks like this:

$ uname -rs
Darwin 10.8.0
$ cat tiny.ml
Printf.printf "hello world\n"
$ ocamlc -o tiny tiny.ml
$ file tiny.cmo
tiny.cmo: Objective caml object file (.cmo) (Version 006).
$ file tiny
tiny: a /sw/bin/ocamlrun script text executable
$ tiny
hello world

Using a native 32-bit compiler, it looks like this:

$ ocamlopt -o tiny tiny.ml
$ file tiny.cmx
tiny.cmx: Objective caml native object file (.cmx) (Version 011).
$ file tiny.o
tiny.o: Mach-O object i386
$ file tiny
tiny: Mach-O executable i386
$ tiny
hello world

Edit 2

Your second makefile still doesn't show what you're trying to do, specifically. It just defines some make rules for compiling and linking different types of executables. However, since you say your project is all OCaml, then I'd say the entire problem is in this Makefile.

The problem appears to be that this Makefile specifies which C compiler and libraries the OCaml compiler should use as its back-end, using the -cc and -cclib options. On most systems, it will work OK to just specify the standard C compiler as the back-end for OCaml. On Mac OS X, there are 32-bit/64-bit architectural complications. Since you can compile OCaml successfully without this Makefile, I'd suggest that the OCaml compiler already knows how to compile and link OCaml programs. So you might try just removing the -cc and -cclib options from the Makefile.

To do this: In all three sections under OCAML_EXE remove the third line entirely (the line with -cc and -cclib), and remove the trailing backslash on the previous line.

I've been having this problem for the past two days while trying to compile gphoto2. I just recently upgraded from OS X 10.8 to OS X 10.9. At first I thought it would have been issues on the new XCode version and the command line tools.

I made sure to update everything but the architecture inconsistency on ocaml was still there so, I decided to install the homebrew version of ocaml:

$ brew install ocaml

et voilà

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!