[ACCEPTED]-gcc ld: symbol(s) not found for architecture x86_64-ocaml

Accepted answer
Score: 10

The interesting line is

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

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

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

Score: 4

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

$ ocamlopt -config

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


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

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

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

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

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

Using 23 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 22 a native 32-bit compiler, it looks like 21 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 20 show what you're trying to do, specifically. It 19 just defines some make rules for compiling 18 and linking different types of executables. However, since 17 you say your project is all OCaml, then 16 I'd say the entire problem is in this Makefile.

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

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

Score: 0

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

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

$ brew install ocaml

et 1 voilà

More Related questions