Skip to content

Commit

Permalink
On MSVC, link libfoo.lib or foo.lib for -lfoo (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
dra27 authored and alainfrisch committed Sep 14, 2017
1 parent c1177e8 commit 22888b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Next Version
- Add Unicode support (patch by Nicolás Ojeda Bär)
- Workaround apparent bug in VS 2017.3 link (patch by David Allsopp)
- Additional heuristic for -lfoo on MSVC: try libfoo.lib but then try foo.lib (David Allsopp)

Version 0.35
- Fixes for clang (patch by Roven Gabriel)
Expand Down
21 changes: 17 additions & 4 deletions reloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ let find_file fn =
| Some x -> Some x
| None -> if !use_cygpath then find_file_in (cygpath l) else None

let rec map_until_found f = function
| [] ->
None
| x::xs ->
match f x with
| None ->
map_until_found f xs
| r ->
r

let find_file =
let memo = Hashtbl.create 16 in
Expand All @@ -269,12 +278,16 @@ let find_file =
with Not_found ->
try Hashtbl.find memo (k ^ ".lib")
with Not_found ->
let fn =
let fns =
if String.length fn > 2 && String.sub fn 0 2 = "-l" then
"lib" ^ (String.sub fn 2 (String.length fn - 2))
else fn in
let base = String.sub fn 2 (String.length fn - 2) in
if !toolchain = `MSVC || !toolchain = `MSVC64 then
["lib" ^ base; base]
else
["lib" ^ base]
else [fn] in
let r =
match find_file fn with
match map_until_found find_file fns with
| Some fn -> fn
| None ->
failwith (Printf.sprintf "Cannot find file %S" fn)
Expand Down

0 comments on commit 22888b5

Please sign in to comment.