Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of external functions alone does not cause module to be linked #2471

Closed
vicuna opened this issue May 23, 2000 · 3 comments
Closed

Use of external functions alone does not cause module to be linked #2471

vicuna opened this issue May 23, 2000 · 3 comments
Labels

Comments

@vicuna
Copy link

vicuna commented May 23, 2000

Original bug ID: 129
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hello,

I've run into what seems to be a small bug.

I'm using the ocaml-3.00 under Redhat 6.2; I've tried this using
both OCaml installed from ocaml-3.00-2.rh61.i386.rpm and from an
OCaml I I built from source.

It appears that if you use a "external" function from a library,
without using any other normal values (like regular functions) from
that library, the O'Caml linker does not include that library's
auto-link C libraries in the final link, preventing the executable
from being built.

I don't think this behavior is documented anywhere.

There are three simple workarounds: add -cclib -llibrary to the link
command, or add -linkall, or use some normal value from that
library.

I've included some examples below, in the form of a shell script
that creates some source files and tries to compile them. The
examples are admittedly contrived, but do illustrate the problem.

Start of shell script with examples

set -x

Example using Str

cat >bug.ml <<'EOF'
let x = Str.search_forward

let _ =
print_endline "this program shows the bug!"

EOF

echo This fails
ocamlc -verbose -o bug -custom str.cma bug.ml

echo This succeeds, since we add -linkall
ocamlc -verbose -linkall -o bug -custom str.cma bug.ml

Example using Dbm

cat >bug2.ml <<'EOF'
let d = Dbm.close

let _ =
print_endline "this program also shows the bug!"
EOF

echo This fails
ocamlc -verbose -o bug2 -custom dbm.cma bug2.ml

echo This succeeds, since we add -linkall
ocamlc -verbose -linkall -o bug2 -custom dbm.cma bug2.ml

This example works; Str.regexp is not an "external" function.

cat >nobug.ml <<'EOF'
let x = Str.regexp

let _ =
print_endline "this program does not show the bug!"

EOF

echo This succeeds
ocamlc -verbose -o nobug -custom str.cma nobug.ml

End of shell script with examples

--
T. Kurt Bond, tkb@tkb.mpl.com

@vicuna
Copy link
Author

vicuna commented Jun 5, 2000

Comment author: administrator

Xavier Leroy writes:

I've run into what seems to be a small bug.
It appears that if you use a "external" function from a library,
without using any other normal values (like regular functions) from
that library, the O'Caml linker does not include that library's
auto-link C libraries in the final link, preventing the executable
from being built.

Right, this is a bug. It is fixed in the working sources. If you
wish to test the fix, a patch is appended below.

This worked perfectly for me.

Thanks for the bug report,

You are welcome!

  • Xavier Leroy

Thanks!

T. Kurt Bond, tkb@tkb.mpl.com

@vicuna
Copy link
Author

vicuna commented Jun 5, 2000

Comment author: administrator

I've run into what seems to be a small bug.
It appears that if you use a "external" function from a library,
without using any other normal values (like regular functions) from
that library, the O'Caml linker does not include that library's
auto-link C libraries in the final link, preventing the executable
from being built.

Right, this is a bug. It is fixed in the working sources. If you
wish to test the fix, a patch is appended below.

Thanks for the bug report,

  • Xavier Leroy

Index: csl/bytecomp/bytelink.ml
diff -u csl/bytecomp/bytelink.ml:1.55 csl/bytecomp/bytelink.ml:1.56
--- csl/bytecomp/bytelink.ml:1.55 Thu Apr 20 16:39:01 2000
+++ csl/bytecomp/bytelink.ml Mon Jun 5 14:19:50 2000
@@ -10,7 +10,7 @@
(* *)
(***********************************************************************)

-(* $Id: bytelink.ml,v 1.55 2000/04/20 14:39:01 doligez Exp $ )
+(
$Id: bytelink.ml,v 1.56 2000/06/05 12:19:50 xleroy Exp $ *)

(* Link a set of .cmo files and produce a bytecode executable. *)

@@ -129,6 +129,7 @@
seek_in ic pos_toc;
let toc = (input_value ic : library) in
close_in ic;

  •  add_ccobjs toc;
     let required =
       List.fold_right
         (fun compunit reqd ->
    

@@ -142,7 +143,6 @@
end else
reqd)
toc.lib_units [] in

  •  if required <> [] then add_ccobjs toc;
     Link_archive(file_name, required) :: tolink
    
    end
    else raise(Error(Not_an_object_file file_name))

@vicuna
Copy link
Author

vicuna commented Jun 5, 2000

Comment author: administrator

Fixed on 2000-06-05 by Xavier

@vicuna vicuna closed this as completed Jun 5, 2000
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant