caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Specifying a framework to link with using ocamlopt?
@ 2011-02-23 13:10 Alan Schmitt
  2011-02-23 13:33 ` Daniel Bünzli
  2011-02-23 13:59 ` David Allsopp
  0 siblings, 2 replies; 11+ messages in thread
From: Alan Schmitt @ 2011-02-23 13:10 UTC (permalink / raw)
  To: caml-list

Hello,

I'm trying to compile a simple program using glMLite, and I cannot seem to find a way to tell ocamlopt to use the OS X framework I specify.

If I don't say anything, I get (an expected) error:

[:)][top] % ocamlopt -I +glMLite GL.cmxa Glut.cmxa triangle.ml  -o triangle.exe
ld: library not found for -lGL
collect2: ld returned 1 exit status
File "caml_startup", line 1, characters 0-1:
Error: Error during linking

If I try to tell the linker where the library is, I still get the same error:

[:(][top] % ocamlopt -cclib "-framework OpenGL" -I +glMLite GL.cmxa Glut.cmxa triangle.ml  -o triangle.exe
ld: library not found for -lGL
collect2: ld returned 1 exit status
File "caml_startup", line 1, characters 0-1:
Error: Error during linking

In fact, it seems the "-framework" option is simply ignored:

[:(][top] % ocamlopt -cclib "-framework FOOBAR" -I +glMLite GL.cmxa Glut.cmxa triangle.ml  -o triangle.exe
ld: library not found for -lGL
collect2: ld returned 1 exit status
File "caml_startup", line 1, characters 0-1:
Error: Error during linking
 
(and no, there is no FOOBAR framework on my system, I checked ;-) ).

I feel like I'm missing something obvious here ... Is there a way to specify a Framework to link against using ocamlopt?

Thanks,

Alan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 13:10 [Caml-list] Specifying a framework to link with using ocamlopt? Alan Schmitt
@ 2011-02-23 13:33 ` Daniel Bünzli
  2011-02-23 13:40   ` Daniel Bünzli
  2011-02-23 14:12   ` Alan Schmitt
  2011-02-23 13:59 ` David Allsopp
  1 sibling, 2 replies; 11+ messages in thread
From: Daniel Bünzli @ 2011-02-23 13:33 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: caml-list

The -lGl is certainly recorded in the Gl.cmxa, see the documentation
of the -a option here [1].

You should review how this cmxa was built and installed.

Best,

Daniel

[1] http://caml.inria.fr/pub/docs/manual-ocaml/manual025.html#htoc133

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 13:33 ` Daniel Bünzli
@ 2011-02-23 13:40   ` Daniel Bünzli
  2011-02-23 14:12   ` Alan Schmitt
  1 sibling, 0 replies; 11+ messages in thread
From: Daniel Bünzli @ 2011-02-23 13:40 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: caml-list

> You should review how this cmxa was built and installed.

and/or use the -noautolink option.

Daniel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 13:10 [Caml-list] Specifying a framework to link with using ocamlopt? Alan Schmitt
  2011-02-23 13:33 ` Daniel Bünzli
@ 2011-02-23 13:59 ` David Allsopp
  2011-02-23 14:21   ` Alan Schmitt
  1 sibling, 1 reply; 11+ messages in thread
From: David Allsopp @ 2011-02-23 13:59 UTC (permalink / raw)
  To: 'Alan Schmitt', 'caml-list@inria.fr'

Alan Schmitt wrote:
> I'm trying to compile a simple program using glMLite, and I cannot seem
> to find a way to tell ocamlopt to use the OS X framework I specify.
> 
> If I don't say anything, I get (an expected) error:
> 
> [:)][top] % ocamlopt -I +glMLite GL.cmxa Glut.cmxa triangle.ml  -o
> triangle.exe
> ld: library not found for -lGL

I know very little about how OS X works internally (or externally, for that matter!) but presumably -lGL is not the appropriate way to link against this library on OSX given the error? This would imply, as Daniel said, that the .cmxa file has been incorrectly compiled (linker options are stored in the "manifest" of the file).

> If I try to tell the linker where the library is, I still get the same
> error:
> 
> [:(][top] % ocamlopt -cclib "-framework OpenGL" -I +glMLite GL.cmxa
> Glut.cmxa triangle.ml  -o triangle.exe
> ld: library not found for -lGL
> collect2: ld returned 1 exit status
> File "caml_startup", line 1, characters 0-1:
> Error: Error during linking
> 
> In fact, it seems the "-framework" option is simply ignored:

Not necessarily - even if "-framework OpenGL" is working then the linker must still obey "-lGL" (it can't simply ignore it). Try including -verbose in your ocamlopt switches - this will display the calls to all external programs and you'll be able to verify that "-framework OpenGL" is indeed being passed to the linker (it should be, though). 


David


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 13:33 ` Daniel Bünzli
  2011-02-23 13:40   ` Daniel Bünzli
@ 2011-02-23 14:12   ` Alan Schmitt
  1 sibling, 0 replies; 11+ messages in thread
From: Alan Schmitt @ 2011-02-23 14:12 UTC (permalink / raw)
  To: caml-list

(Resending, I forgot to CC the list.)

On 23 févr. 2011, at 14:33, Daniel Bünzli wrote:

> The -lGl is certainly recorded in the Gl.cmxa, see the documentation
> of the -a option here [1].
> 
> You should review how this cmxa was built and installed.


It was produced using ocamlmklib:

ocamlmklib  -o  GL  GL.cmx  -framework OpenGL -lgl_stubs

The "gl_stubs" library is available in the glMLite directory, and does not seem to be the problem.

(I just read your other message, and it helped a bit.)

The strange thing is that, if I now compile by doing a "-noautolink" and re-adding the exact same library (-cclib "-framework OpenGL"), I get further (with other errors). So it seems that doing "ocamlmklib" with a framework doesn't work, but also prevents specifying the same framework later on on the command line.

Thanks for your help!

Alan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 14:21   ` Alan Schmitt
@ 2011-02-23 14:19     ` David Allsopp
  2011-02-23 15:21       ` Alan Schmitt
  0 siblings, 1 reply; 11+ messages in thread
From: David Allsopp @ 2011-02-23 14:19 UTC (permalink / raw)
  To: 'Alan Schmitt'; +Cc: 'caml-list@inria.fr'

Alan Schmitt wrote:
> On 23 févr. 2011, at 14:59, David Allsopp wrote:
> 
> > Not necessarily - even if "-framework OpenGL" is working then the
> linker must still obey "-lGL" (it can't simply ignore it). Try including
> -verbose in your ocamlopt switches - this will display the calls to all
> external programs and you'll be able to verify that "-framework OpenGL"
> is indeed being passed to the linker (it should be, though).
> 
> The "-verbose" option is very interesting indeed!

It certainly is an invaluable platform debugging aid! ocamlmklib also supports it - perhaps using it with the command which generates the library may help further?

> It tells me the "-
> framework OpenGL" and "-framework GLUT" specified in the ocamlmklib are
> indeed taken into account. But for some reason, there are extra
> (spurious) -lGL, -lGlut, and -lGlu.

Could this arise from -lgl_stubs?

> These libraries are generated this way:
> ocamlmklib  -o  GL  GL.cmx  -framework OpenGL -lgl_stubs ocamlmklib -o
> Glu  Glu.cmx  -framework OpenGL ocamlmklib  -o  Glut  Glut.cmx  -
> framework GLUT
> 
> which do not contain such linking primitives.
> 
> Could this be related to this warning:
> ld: warning: -read_only_relocs cannot be used with x86_64 ?

http://caml.inria.fr/mantis/view.php?id=4863 (see the notes, not the bug report)


David


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 13:59 ` David Allsopp
@ 2011-02-23 14:21   ` Alan Schmitt
  2011-02-23 14:19     ` David Allsopp
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Schmitt @ 2011-02-23 14:21 UTC (permalink / raw)
  To: David Allsopp; +Cc: 'caml-list@inria.fr'

On 23 févr. 2011, at 14:59, David Allsopp wrote:

> Not necessarily - even if "-framework OpenGL" is working then the linker must still obey "-lGL" (it can't simply ignore it). Try including -verbose in your ocamlopt switches - this will display the calls to all external programs and you'll be able to verify that "-framework OpenGL" is indeed being passed to the linker (it should be, though).

The "-verbose" option is very interesting indeed! It tells me the "-framework OpenGL" and "-framework GLUT" specified in the ocamlmklib are indeed taken into account. But for some reason, there are extra (spurious) -lGL, -lGlut, and -lGlu.

These libraries are generated this way:
ocamlmklib  -o  GL  GL.cmx  -framework OpenGL -lgl_stubs
ocamlmklib -o Glu  Glu.cmx  -framework OpenGL
ocamlmklib  -o  Glut  Glut.cmx  -framework GLUT

which do not contain such linking primitives.

Could this be related to this warning:
ld: warning: -read_only_relocs cannot be used with x86_64
?

Thanks,

Alan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 14:19     ` David Allsopp
@ 2011-02-23 15:21       ` Alan Schmitt
  2011-02-23 15:48         ` David Allsopp
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Schmitt @ 2011-02-23 15:21 UTC (permalink / raw)
  To: David Allsopp; +Cc: 'caml-list@inria.fr'

[-- Attachment #1: Type: text/plain, Size: 1438 bytes --]

On 23 févr. 2011, at 15:19, David Allsopp wrote:

> It certainly is an invaluable platform debugging aid! ocamlmklib also supports it - perhaps using it with the command which generates the library may help further?

Duh, I should have thought of this!

The problem does not seem to come from gl_stubs:

[:)][top] % ocamlmklib -verbose  -oc  gl_stubs  gl.wrap.o  -framework OpenGL
+ gcc -bundle -flat_namespace -undefined suppress -read_only_relocs suppress -o ./dllgl_stubs.so gl.wrap.o -L/Users/schmitta/godi/lib -framework OpenGL   
ld: warning: -read_only_relocs cannot be used with x86_64
+ ar rc ./libgl_stubs.a  gl.wrap.o; ranlib ./libgl_stubs.a

but from GL.cmxa:
[:)][top] % ocamlmklib -verbose  -o  GL  GL.cmx  -framework OpenGL -lgl_stubs
+ /Users/schmitta/godi/bin/ocamlopt -a -o GL.cmxa  GL.cmx -cclib -lGL -ccopt -L/Users/schmitta/godi/lib -ccopt -framework -ccopt OpenGL  -cclib -lgl_stubs 

I don't understand why ocamlmklib adds the "-lGL" here. (It does the same thing with the Glut archive.)

Is this a bug?

>> Could this be related to this warning:
>> ld: warning: -read_only_relocs cannot be used with x86_64 ?
> 
> http://caml.inria.fr/mantis/view.php?id=4863 (see the notes, not the bug report)

Ah, I haven't updated to 3.12 yet. Doing so ...

So the warning have gone away, but the previous behavior still remains: ocamlmklib inserts an extra "-lGL" when creating the library.

Alan

[-- Attachment #2: Type: text/html, Size: 2696 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 15:21       ` Alan Schmitt
@ 2011-02-23 15:48         ` David Allsopp
  2011-02-23 16:08           ` Alan Schmitt
  0 siblings, 1 reply; 11+ messages in thread
From: David Allsopp @ 2011-02-23 15:48 UTC (permalink / raw)
  To: 'Alan Schmitt'; +Cc: 'caml-list@inria.fr'

Alan Schmitt wrote:
> > On 23 févr. 2011, at 15:19, David Allsopp wrote:
> > It certainly is an invaluable platform debugging aid!
> > ocamlmklib also supports it - perhaps using it with 
> > the command which generates the library may help further?
>
> Duh, I should have thought of this!
> 
> The problem does not seem to come from gl_stubs:
>
> [:)][top] % ocamlmklib -verbose  -oc  gl_stubs  gl.wrap.o  
> -framework OpenGL
> + gcc -bundle -flat_namespace -undefined suppress -read_only_relocs
>  suppress -o ./dllgl_stubs.so gl.wrap.o -L/Users/schmitta/godi/lib
> -framework OpenGL
> ld: warning: -read_only_relocs cannot be used with x86_64
> + ar rc ./libgl_stubs.a  gl.wrap.o; ranlib ./libgl_stubs.a
> but from GL.cmxa:
> [:)][top] % ocamlmklib -verbose  -o  GL  GL.cmx  -framework OpenGL
> -lgl_stubs
> + /Users/schmitta/godi/bin/ocamlopt -a -o GL.cmxa  GL.cmx -cclib 
> -lGL -ccopt 
> -L/Users/schmitta/godi/lib -ccopt -framework -ccopt OpenGL  -cclib
> -lgl_stubs 
>
> I don't understand why ocamlmklib adds the "-lGL" here. (It does the same thing with the Glut archive.)
> 
> Is this a bug?

Yes and no. I think there's a warning missing in ocamlmklib. Essentially, you're meant to pass some C object files (the stubs) whenever you use ocamlmklib - I think that what's going on is that because there are no .o files passed, it's not compiling libGL.a and so the linking instruction included is failing. ocamlmklib probably should warn that you passed no c objects and libGL.a doesn't seem to exist either. 

That said, I think it's that you're using ocamlmklib in a weird way by compiling the stubs separately and renaming the library that's causing the problems. The -lGL is added because of the -o GL. Try passing -oc gl_stubs to your second ocamlmklib call as well or alternatively do it as one:

ocamlmklib -verbose -o GL -oc gl_stubs GL.cmx -framework OpenGL GL.cmx gl.wrap.o

but you can safely omit the -oc gl_stubs if you're happy for the stub library to be libGL.a instead. Does that work?


David


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 15:48         ` David Allsopp
@ 2011-02-23 16:08           ` Alan Schmitt
  2011-02-23 16:08             ` David Allsopp
  0 siblings, 1 reply; 11+ messages in thread
From: Alan Schmitt @ 2011-02-23 16:08 UTC (permalink / raw)
  To: David Allsopp; +Cc: 'caml-list@inria.fr'

On 23 févr. 2011, at 16:48, David Allsopp wrote:

> Yes and no. I think there's a warning missing in ocamlmklib. Essentially, you're meant to pass some C object files (the stubs) whenever you use ocamlmklib - I think that what's going on is that because there are no .o files passed, it's not compiling libGL.a and so the linking instruction included is failing. ocamlmklib probably should warn that you passed no c objects and libGL.a doesn't seem to exist either. 
> 
> That said, I think it's that you're using ocamlmklib in a weird way by compiling the stubs separately and renaming the library that's causing the problems. The -lGL is added because of the -o GL. Try passing -oc gl_stubs to your second ocamlmklib call as well or alternatively do it as one:
> 
> ocamlmklib -verbose -o GL -oc gl_stubs GL.cmx -framework OpenGL GL.cmx gl.wrap.o
> 
> but you can safely omit the -oc gl_stubs if you're happy for the stub library to be libGL.a instead. Does that work?

It seems that using the gl_stubs bit is necessary. Otherwise I get:
[:)][top] % ocamlmklib -verbose -o GL -framework OpenGL GL.cmx gl.wrap.o
+ gcc -bundle -flat_namespace -undefined suppress -o ./dllGL.so gl.wrap.o -L/Users/schmitta/godi/lib -framework OpenGL   
+ ar rc ./libGL.a  gl.wrap.o; ranlib ./libGL.a
+ /Users/schmitta/godi/bin/ocamlopt -a -o GL.cmxa  GL.cmx -cclib -lGL -ccopt -L/Users/schmitta/godi/lib -ccopt -framework -ccopt OpenGL   

where the -lGL is still there.

With you other command line (removing the duplicated instance of "GL.cmx"), it works much better:

[:)][top] % ocamlmklib -verbose -o GL -oc gl_stubs GL.cmx -framework OpenGL gl.wrap.o
+ gcc -bundle -flat_namespace -undefined suppress -o ./dllgl_stubs.so gl.wrap.o -L/Users/schmitta/godi/lib -framework OpenGL   
+ ar rc ./libgl_stubs.a  gl.wrap.o; ranlib ./libgl_stubs.a
+ /Users/schmitta/godi/bin/ocamlopt -a -o GL.cmxa  GL.cmx -cclib -lgl_stubs -ccopt -L/Users/schmitta/godi/lib -ccopt -framework -ccopt OpenGL   

Applying the same recipe to the other libraries solved the issue. Thanks a bunch!

Alan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [Caml-list] Specifying a framework to link with using ocamlopt?
  2011-02-23 16:08           ` Alan Schmitt
@ 2011-02-23 16:08             ` David Allsopp
  0 siblings, 0 replies; 11+ messages in thread
From: David Allsopp @ 2011-02-23 16:08 UTC (permalink / raw)
  To: 'Alan Schmitt'; +Cc: 'caml-list@inria.fr'

Alan Schmitt wrote:
> On 23 févr. 2011, at 16:48, David Allsopp wrote:
> 
> > Yes and no. I think there's a warning missing in ocamlmklib.
> Essentially, you're meant to pass some C object files (the stubs)
> whenever you use ocamlmklib - I think that what's going on is that
> because there are no .o files passed, it's not compiling libGL.a and so
> the linking instruction included is failing. ocamlmklib probably should
> warn that you passed no c objects and libGL.a doesn't seem to exist
> either.
> >
> > That said, I think it's that you're using ocamlmklib in a weird way by
> compiling the stubs separately and renaming the library that's causing
> the problems. The -lGL is added because of the -o GL. Try passing -oc
> gl_stubs to your second ocamlmklib call as well or alternatively do it as
> one:
> >
> > ocamlmklib -verbose -o GL -oc gl_stubs GL.cmx -framework OpenGL GL.cmx
> gl.wrap.o
> >
> > but you can safely omit the -oc gl_stubs if you're happy for the stub
> library to be libGL.a instead. Does that work?
> 
> It seems that using the gl_stubs bit is necessary. Otherwise I get:
> [:)][top] % ocamlmklib -verbose -o GL -framework OpenGL GL.cmx gl.wrap.o
> + gcc -bundle -flat_namespace -undefined suppress -o ./dllGL.so gl.wrap.o
> -L/Users/schmitta/godi/lib -framework OpenGL
> + ar rc ./libGL.a  gl.wrap.o; ranlib ./libGL.a
> + /Users/schmitta/godi/bin/ocamlopt -a -o GL.cmxa  GL.cmx -cclib -lGL -
> ccopt -L/Users/schmitta/godi/lib -ccopt -framework -ccopt OpenGL
> 
> where the -lGL is still there.

No - it's now correct that the -lGL is there now. You should also have libGL.a as a result of that command - note those extra calls to ar and ranlib which I don't think you were getting before. Of course, if you want it to be called libgl_stubs.a then that's another matter but the library GL.cmxa built from this command should work (where you previous one did not).

> With you other command line (removing the duplicated instance of
> "GL.cmx"),

Oops!

> it works much better:
> 
> [:)][top] % ocamlmklib -verbose -o GL -oc gl_stubs GL.cmx -framework
> OpenGL gl.wrap.o
> + gcc -bundle -flat_namespace -undefined suppress -o ./dllgl_stubs.so
> gl.wrap.o -L/Users/schmitta/godi/lib -framework OpenGL
> + ar rc ./libgl_stubs.a  gl.wrap.o; ranlib ./libgl_stubs.a
> + /Users/schmitta/godi/bin/ocamlopt -a -o GL.cmxa  GL.cmx -cclib -
> lgl_stubs -ccopt -L/Users/schmitta/godi/lib -ccopt -framework -ccopt
> OpenGL
> 
> Applying the same recipe to the other libraries solved the issue. Thanks
> a bunch!

No probs.


David


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-02-23 16:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-23 13:10 [Caml-list] Specifying a framework to link with using ocamlopt? Alan Schmitt
2011-02-23 13:33 ` Daniel Bünzli
2011-02-23 13:40   ` Daniel Bünzli
2011-02-23 14:12   ` Alan Schmitt
2011-02-23 13:59 ` David Allsopp
2011-02-23 14:21   ` Alan Schmitt
2011-02-23 14:19     ` David Allsopp
2011-02-23 15:21       ` Alan Schmitt
2011-02-23 15:48         ` David Allsopp
2011-02-23 16:08           ` Alan Schmitt
2011-02-23 16:08             ` David Allsopp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).