caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Linking with zlib on ubuntu
@ 2017-05-02 18:19 Alexey Egorov
  2017-05-02 19:28 ` Aziem Chawdhary
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Egorov @ 2017-05-02 18:19 UTC (permalink / raw)
  To: caml-list

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

Hello,

I'm trying to create mixed OCaml + C binary and got strange linker errors:  https://gist.github.com/anonymous/cc2b69c9e86ff2213e03f59a1ac5494b  
I have zlib1g-dev installed and linking pure C executable with gcc is working.
Also I have no problem compiling this example on Centos 7.

Any suggestions?
Thanks.


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

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

* Re: [Caml-list] Linking with zlib on ubuntu
  2017-05-02 18:19 [Caml-list] Linking with zlib on ubuntu Alexey Egorov
@ 2017-05-02 19:28 ` Aziem Chawdhary
  2017-05-02 19:59   ` Alexey Egorov
  0 siblings, 1 reply; 4+ messages in thread
From: Aziem Chawdhary @ 2017-05-02 19:28 UTC (permalink / raw)
  To: Alexey Egorov; +Cc: caml-list


I think the linker flag is in the wrong place. So (from the
github gist), instead of doing:

ocamlopt -cclib -lz main.cmx test.o -o binary

do the following:

ocamlopt test.o -cclib -lz main.cmx -o binary

This passes the linker flags to gcc in the correct order (i.e -lz before
test.o). You can see the gcc commands invoked by adding the -verbose option
to ocamlopt.


Thanks,
Aziem


Alexey Egorov <electreg@list.ru> writes:

> Hello,
>
> I'm trying to create mixed OCaml + C binary and got strange linker errors: https://gist.github.com/anonymous/cc2b69c9e86ff2213e03f59a1ac5494b 
> I have zlib1g-dev installed and linking pure C executable with gcc is working.
> Also I have no problem compiling this example on Centos 7.
>
> Any suggestions?
> Thanks.


-- 

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

* Re: [Caml-list] Linking with zlib on ubuntu
  2017-05-02 19:28 ` Aziem Chawdhary
@ 2017-05-02 19:59   ` Alexey Egorov
  2017-05-02 20:40     ` Aziem Chawdhary
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Egorov @ 2017-05-02 19:59 UTC (permalink / raw)
  To: Aziem Chawdhary; +Cc: caml-list

Thanks, it solves the problem!

Unfortunately, ocamlbuild adds lflags at the beggining of ocamlopt invocation, so a little hacking required to make it work.


>Среда,  3 мая 2017, 0:28 +05:00 от Aziem Chawdhary <aziem@chawdhary.co.uk>:
>
>
>I think the linker flag is in the wrong place. So (from the
>github gist), instead of doing:
>
>ocamlopt -cclib -lz main.cmx test.o -o binary
>
>do the following:
>
>ocamlopt test.o -cclib -lz main.cmx -o binary
>
>This passes the linker flags to gcc in the correct order (i.e -lz before
>test.o). You can see the gcc commands invoked by adding the -verbose option
>to ocamlopt.
>
>
>Thanks,
>Aziem
>
>
>Alexey Egorov < electreg@list.ru > writes:
>
>> Hello,
>>
>> I'm trying to create mixed OCaml + C binary and got strange linker errors:  https://gist.github.com/anonymous/cc2b69c9e86ff2213e03f59a1ac5494b
>> I have zlib1g-dev installed and linking pure C executable with gcc is working.
>> Also I have no problem compiling this example on Centos 7.
>>
>> Any suggestions?
>> Thanks.
>
>
>-- 


--

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

* Re: [Caml-list] Linking with zlib on ubuntu
  2017-05-02 19:59   ` Alexey Egorov
@ 2017-05-02 20:40     ` Aziem Chawdhary
  0 siblings, 0 replies; 4+ messages in thread
From: Aziem Chawdhary @ 2017-05-02 20:40 UTC (permalink / raw)
  To: Alexey Egorov; +Cc: caml-list


When using ocamlbuild, I find it much easier to pass things like linker
flags via tags, rather than passing it via the command line, as
mentioned in the ocamlbuild manual:

https://github.com/ocaml/ocamlbuild/blob/master/manual/manual.adoc#tags-and-the-code-_tags-code-file

As a side-note, for building mixed C/OCaml projects, I highly recommend
looking at OCaml-Ctypes (https://github.com/ocamllabs/ocaml-ctypes): it
has really made interfacing OCaml with C much more pleasant in my
experience.

Hope that helps!
Aziem


Alexey Egorov <electreg@list.ru> writes:

> Thanks, it solves the problem!
>
> Unfortunately, ocamlbuild adds lflags at the beggining of ocamlopt invocation, so a little hacking required to make it work.
>
>
>>Среда,  3 мая 2017, 0:28 +05:00 от Aziem Chawdhary <aziem@chawdhary.co.uk>:
>>
>>
>>I think the linker flag is in the wrong place. So (from the
>>github gist), instead of doing:
>>
>>ocamlopt -cclib -lz main.cmx test.o -o binary
>>
>>do the following:
>>
>>ocamlopt test.o -cclib -lz main.cmx -o binary
>>
>>This passes the linker flags to gcc in the correct order (i.e -lz before
>>test.o). You can see the gcc commands invoked by adding the -verbose option
>>to ocamlopt.
>>
>>
>>Thanks,
>>Aziem
>>
>>
>>Alexey Egorov < electreg@list.ru > writes:
>>
>>> Hello,
>>>
>>> I'm trying to create mixed OCaml + C binary and got strange linker errors:  https://gist.github.com/anonymous/cc2b69c9e86ff2213e03f59a1ac5494b
>>> I have zlib1g-dev installed and linking pure C executable with gcc is working.
>>> Also I have no problem compiling this example on Centos 7.
>>>
>>> Any suggestions?
>>> Thanks.
>>
>>
>>-- 


-- 

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

end of thread, other threads:[~2017-05-02 20:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-02 18:19 [Caml-list] Linking with zlib on ubuntu Alexey Egorov
2017-05-02 19:28 ` Aziem Chawdhary
2017-05-02 19:59   ` Alexey Egorov
2017-05-02 20:40     ` Aziem Chawdhary

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).