caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] ocamlopt problem
@ 2006-06-05  8:34 EL CHAAR Rabih   SGAM/AI/SAM
  2006-06-05 10:55 ` David Allsopp
  0 siblings, 1 reply; 5+ messages in thread
From: EL CHAAR Rabih   SGAM/AI/SAM @ 2006-06-05  8:34 UTC (permalink / raw)
  To: David Allsopp, OCaml List

Hello David,
The problem that you are facing is the following:
Your c code is available through dllocamlodbc.dll which is dynamically loaded by the toplevel.

My understanding is that the capacity to load dynamically functions is only available througth the toplevel.
When generating executable (native or bytecode), you should pass the c code embedded in a static library.

You should have a libocamlodbc_.a built from ocaml_odbc_c.o, say via 
$ ar -r libocamlodbc_.a ocaml_odbc_c.o

Here maybe you should pay attention to some aspects of exporting C functions to caml via -DCAML_DLL. If this is the case, you should compile another ocaml_odbc_c.o omitting the definition of this symbol (I don't know if the 
-DODBC2 does this automatically) in order to generate the static library.

This static library should be passed to both ocamlodbc.cma and ocamlodbc.cmxa via

$ ocamlopt -a -o ocamlodbc.cmxa ocaml_odbc.ml ocamlodbc.mli
ocamlodbc.ml -cclib -lodbc32 -cclib -locamlodbc_

$ ocamlc -a -o ocamlodbc.cma ocaml_odbc.ml ocamlodbc.mli ocamlodbc.ml -dllib
-locamlodbc -cclib -locamlodbc_

Afterwards, while building executables, the -cclib directive will be extracted from the library and passed to the c linker.

Hope this helps.

Sincerely
Rabih

PS: What I've described above is the general approach. In your specific case, questioning the presence of ocaml_odbc.o, the answer is that it is not included in the .cmxa, it contains only specific caml code, and flags to pass to the external linkers. When passing a -ccopt ocaml_odbc_c.o to the library, it will be extracted at linking, supposing the corresponding .o is available.

-----Message d'origine-----
De : caml-list-bounces@yquem.inria.fr [mailto:caml-list-bounces@yquem.inria.fr] De la part de David Allsopp
Envoyé : vendredi 2 juin 2006 22:58
À : OCaml List
Objet : [Caml-list] ocamlopt problem

I'm trying to build the ocamlodbc package under Windows using Cygwin/MinGW.
It's all built and working except that I'm having one problem with the
native library. My question, I think, relates to a misunderstanding with
ocamlopt so I'm hoping someone can point out my error! 

I've adapted the INSTALL_mingw.sh script to issue the following commands:

$ gcc -mno-cygwin -c -DODBC2 -DWIN32 -I $OCAMLLIB/caml -I
/usr/include/w32api ocaml_odbc_c.c
$ gcc -mno-cygwin -shared -L $OCAMLLIB -L $OCAMLLIB/../bin -o
dllocamlodbc.dll ocaml_odbc_c.o -lodbc32 -locamlrun 

$ ocamlopt -a -o ocamlodbc.cmxa ocaml_odbc_c.o ocaml_odbc.ml ocamlodbc.mli
ocamlodbc.ml -cclib -lodbc32
$ cp ocamlodbc.cmxa ocamlodbc.a ocamlodbc.cmi $OCAMLLIB

$ ocamlc -a -o ocamlodbc.cma ocaml_odbc.ml ocamlodbc.mli ocamlodbc.ml -dllib
-locamlodbc
$ cp ocamlodbc.cmi ocamlodbc.cma $OCAMLLIB
$ cp dllocamlodbc.dll $OCAMLLIB/stublibs

The top-level library ocamlodbc.cma is working exactly as I'd expect. I then
attempt to compile a program that uses the native library (in this case
Exemples/monitor.ml) with the command

ocamlopt -o monitor.exe ocamlodbc.cmxa monitor.ml

but get the response

gcc: ocaml_odbc_c.o: No such file or directory
Error during linking

Despite trying various -ccopt flags, the only way I can make it compile is
to copy ocaml_odbc_c.o to the current directory. My understanding is that
the ocamlopt statement that built ocamlodbc.cmxa should have included
ocaml_odbc_c.o so why is gcc getting a linker problem when referencing the
library?

Sorry if it's a blindingly obvious mistake...


David

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et etablis a l'intention exclusive de ses destinataires. 
Toute utilisation ou diffusion non autorisee est interdite. 
Tout message electronique est susceptible d'alteration. 
Societe Generale Asset Management et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, deforme ou falsifie. 
  
Decouvrez l'offre et les services de Societe Generale Asset Management sur le site www.sgam.fr 
  
                                ******** 
  
This message and any attachments (the "message") are confidential and intended solely for the addressees. 
Any unauthorised use or dissemination is prohibited. 
E-mails are susceptible to alteration. 
Neither Societe Generale Asset Management nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or falsified. 
 
Find out more about Societe Generale Asset Management's proposal on www.sgam.com


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

* RE: [Caml-list] ocamlopt problem
  2006-06-05  8:34 [Caml-list] ocamlopt problem EL CHAAR Rabih   SGAM/AI/SAM
@ 2006-06-05 10:55 ` David Allsopp
  0 siblings, 0 replies; 5+ messages in thread
From: David Allsopp @ 2006-06-05 10:55 UTC (permalink / raw)
  To: OCaml List

Dear Rabih,

	Thanks for this! While combing through the bottom of the manual page
for linking with C I was looking at how ocamlmklib works and so "discovered"
the ar tool and noted that ocamlodbc.cmxa (well, via ocamlodbc.a obviously)
doesn't contain the C object file and added -cclib -locamlodbc.

	On a separate note, is there an architectural reason why ocamlmklib
is not compiled under Windows? As far as I could see if you've built OCaml
from sources using the MinGW Makefile you've got everything available that
ocamlmklib would need?

	I'm confused with your ocamlc command by the use of the static
library in building ocamlodbc.cma - CAML_DLL isn't defined anywhere in the C
code (or in its build instructions), but dllocamlodbc.dll is working fine -
is that correct? What I have noticed is that if I add -DCAML_DLL then I
don't get this message from gcc when building the DLL:

	Info: resolving _caml_local_roots by linking to
__imp__caml_local_roots (auto-import)

	When building an OCaml executable with ocamlc I thought that C
linker isn't used (because I'd have to PATH it which I only need to do for
ocamlopt). That said, even if it does, the -dllib is still going to cause
the resulting .exe to be dynamically linked with dllocamlodbc.dll (and
therefore require it on any machine that the EXE is taken to, along with
ocamlrun.dll). Slightly confused as to why the -cclib switch to ocamlc
helps... 

Regards,


David 



-----Original Message-----
From: EL CHAAR Rabih SGAM/AI/SAM [mailto:RABIH.ELCHAAR@sgam.com] 
Sent: 05 June 2006 09:34
To: David Allsopp; OCaml List
Subject: RE: [Caml-list] ocamlopt problem

Hello David,
The problem that you are facing is the following:
Your c code is available through dllocamlodbc.dll which is dynamically
loaded by the toplevel.

My understanding is that the capacity to load dynamically functions is only
available througth the toplevel.
When generating executable (native or bytecode), you should pass the c code
embedded in a static library.

You should have a libocamlodbc_.a built from ocaml_odbc_c.o, say via 
$ ar -r libocamlodbc_.a ocaml_odbc_c.o

Here maybe you should pay attention to some aspects of exporting C functions
to caml via -DCAML_DLL. If this is the case, you should compile another
ocaml_odbc_c.o omitting the definition of this symbol (I don't know if the 
-DODBC2 does this automatically) in order to generate the static library.

This static library should be passed to both ocamlodbc.cma and
ocamlodbc.cmxa via

$ ocamlopt -a -o ocamlodbc.cmxa ocaml_odbc.ml ocamlodbc.mli
ocamlodbc.ml -cclib -lodbc32 -cclib -locamlodbc_

$ ocamlc -a -o ocamlodbc.cma ocaml_odbc.ml ocamlodbc.mli ocamlodbc.ml -dllib
-locamlodbc -cclib -locamlodbc_

Afterwards, while building executables, the -cclib directive will be
extracted from the library and passed to the c linker.

Hope this helps.

Sincerely
Rabih

PS: What I've described above is the general approach. In your specific
case, questioning the presence of ocaml_odbc.o, the answer is that it is not
included in the .cmxa, it contains only specific caml code, and flags to
pass to the external linkers. When passing a -ccopt ocaml_odbc_c.o to the
library, it will be extracted at linking, supposing the corresponding .o is
available.

-----Message d'origine-----
De : caml-list-bounces@yquem.inria.fr
[mailto:caml-list-bounces@yquem.inria.fr] De la part de David Allsopp
Envoyé : vendredi 2 juin 2006 22:58
À : OCaml List
Objet : [Caml-list] ocamlopt problem

I'm trying to build the ocamlodbc package under Windows using Cygwin/MinGW.
It's all built and working except that I'm having one problem with the
native library. My question, I think, relates to a misunderstanding with
ocamlopt so I'm hoping someone can point out my error! 

I've adapted the INSTALL_mingw.sh script to issue the following commands:

$ gcc -mno-cygwin -c -DODBC2 -DWIN32 -I $OCAMLLIB/caml -I
/usr/include/w32api ocaml_odbc_c.c
$ gcc -mno-cygwin -shared -L $OCAMLLIB -L $OCAMLLIB/../bin -o
dllocamlodbc.dll ocaml_odbc_c.o -lodbc32 -locamlrun 

$ ocamlopt -a -o ocamlodbc.cmxa ocaml_odbc_c.o ocaml_odbc.ml ocamlodbc.mli
ocamlodbc.ml -cclib -lodbc32
$ cp ocamlodbc.cmxa ocamlodbc.a ocamlodbc.cmi $OCAMLLIB

$ ocamlc -a -o ocamlodbc.cma ocaml_odbc.ml ocamlodbc.mli ocamlodbc.ml -dllib
-locamlodbc
$ cp ocamlodbc.cmi ocamlodbc.cma $OCAMLLIB
$ cp dllocamlodbc.dll $OCAMLLIB/stublibs

The top-level library ocamlodbc.cma is working exactly as I'd expect. I then
attempt to compile a program that uses the native library (in this case
Exemples/monitor.ml) with the command

ocamlopt -o monitor.exe ocamlodbc.cmxa monitor.ml

but get the response

gcc: ocaml_odbc_c.o: No such file or directory
Error during linking

Despite trying various -ccopt flags, the only way I can make it compile is
to copy ocaml_odbc_c.o to the current directory. My understanding is that
the ocamlopt statement that built ocamlodbc.cmxa should have included
ocaml_odbc_c.o so why is gcc getting a linker problem when referencing the
library?

Sorry if it's a blindingly obvious mistake...


David

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
Ce message et toutes les pieces jointes (ci-apres le "message") sont
confidentiels et etablis a l'intention exclusive de ses destinataires. 
Toute utilisation ou diffusion non autorisee est interdite. 
Tout message electronique est susceptible d'alteration. 
Societe Generale Asset Management et ses filiales declinent toute
responsabilite au titre de ce message s'il a ete altere, deforme ou
falsifie. 
  
Decouvrez l'offre et les services de Societe Generale Asset Management sur
le site www.sgam.fr 
  
                                ******** 
  
This message and any attachments (the "message") are confidential and
intended solely for the addressees. 
Any unauthorised use or dissemination is prohibited. 
E-mails are susceptible to alteration. 
Neither Societe Generale Asset Management nor any of its subsidiaries or
affiliates shall be liable for the message if altered, changed or falsified.

 
Find out more about Societe Generale Asset Management's proposal on
www.sgam.com


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

* Re: [Caml-list] ocamlopt problem
  2005-10-06  7:07 ` Rasool Karimi
@ 2005-10-06  9:13   ` Jacques Garrigue
  0 siblings, 0 replies; 5+ messages in thread
From: Jacques Garrigue @ 2005-10-06  9:13 UTC (permalink / raw)
  To: rkarimi; +Cc: caml-list

From: Rasool Karimi <rkarimi@gmail.com>

> When I compile a .ml file with ocamlopt compiler, an error message is shown
> with this message:"Der Befehl "as" ist entweder falsch geschrieben oder
> konnte nicht gefunden werden, Assembler error, input left in file
> C:\DOKUME~1\karinu\LOKALE~1\Temp\camlasm9312 7a.s". Part of this message is
> in german and translation of it in english is : "The instruction "as" is
> either wrongly written or could not not be found". But when I compile a .mli
> file, this message is not shown and file is compiled successfully. Also when
> I compile a .ml file with ocamlc compiler, there is no error and compilation
> is done successfully. So there is not error in my program and this error
> maybe is related to ocamlopt compiler.

The message is to be understood literally: in order to compile
assembly code to machine code, ocamlopt relies on an external
assembler. I suppose you use either the mingw or cygwin version, so
the name of the assembler is "as". You must make sure you installed it
with cygwin.
With a .mli, there is no object created, so no external command is
required. Similarly ocamlc generates bytecode all by itself, so there
is no such problem (as long as you don't use the -custom option.)

Jacques Garrigue


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

* Re: [Caml-list] ocamlopt problem
  2005-10-06  6:55 Rasool Karimi
  2005-10-06  7:07 ` Rasool Karimi
  2005-10-06  7:25 ` David MENTRE
@ 2005-10-06  9:09 ` Pierre Etchemaite
  2 siblings, 0 replies; 5+ messages in thread
From: Pierre Etchemaite @ 2005-10-06  9:09 UTC (permalink / raw)
  To: caml-list

Le Thu, 6 Oct 2005 08:55:19 +0200, Rasool Karimi <rkarimi@gmail.com> a écrit
:
> with this message:"Der Befehl "as" ist entweder falsch geschrieben oder
> konnte nicht gefunden werden, Assembler error, input left in file
> C:\DOKUME~1\karinu\LOKALE~1\Temp\camlasm9312 7a.s". Part of this message
> is
> in german and translation of it in english is : "The instruction "as" is
> either wrongly written or could not not be found". 

Looks like as (the GNU portable assembler) is not installed, or at least not
in your $PATH...


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

* Re: [Caml-list] ocamlopt problem
  2005-10-06  6:55 Rasool Karimi
  2005-10-06  7:07 ` Rasool Karimi
@ 2005-10-06  7:25 ` David MENTRE
  2005-10-06  9:09 ` Pierre Etchemaite
  2 siblings, 0 replies; 5+ messages in thread
From: David MENTRE @ 2005-10-06  7:25 UTC (permalink / raw)
  To: Rasool Karimi; +Cc: caml-list

Hello,

2005/10/6, Rasool Karimi <rkarimi@gmail.com>:
> this message is in german and translation of it in english is : "The
> instruction "as" is either wrongly written or could not not be found". But
> when I compile a .mli file, this message is not shown and file is compiled
> successfully. Also when I compile a .ml file with ocamlc compiler, there is
> no error and compilation is done successfully. So there is not error in my
> program and this error maybe is related to ocamlopt compiler.

There is no reason that a particular error occurs with ocamlopt and
not ocamlc, especially as the syntax and typing phases are common to
both compilers (moreover, bugs in ocaml compilers are quite rare. Rule
of thumb: never suspect a bug in the compiler, always in your code).
So I would suspect an issue with your particular file or your
compiling environment. We cannot say much more without (1) having your
particular .ml and .mli file and (2) knowing in which environment your
are compiling.

Yours,
d.


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

end of thread, other threads:[~2006-06-05 11:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-05  8:34 [Caml-list] ocamlopt problem EL CHAAR Rabih   SGAM/AI/SAM
2006-06-05 10:55 ` David Allsopp
  -- strict thread matches above, loose matches on Subject: below --
2005-10-06  6:55 Rasool Karimi
2005-10-06  7:07 ` Rasool Karimi
2005-10-06  9:13   ` [Caml-list] " Jacques Garrigue
2005-10-06  7:25 ` David MENTRE
2005-10-06  9:09 ` Pierre Etchemaite

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