caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Mingw-ocaml and C++
@ 2013-03-24 11:43 Romain Beauxis
  2013-03-25  2:22 ` [Caml-list] " Romain Beauxis
  0 siblings, 1 reply; 2+ messages in thread
From: Romain Beauxis @ 2013-03-24 11:43 UTC (permalink / raw)
  To: OCaml List; +Cc: Samuel Mimram

Hi all,

I have extracted the debian-specific build for mingw-ocaml into a
standalone build:
  https://github.com/savonet/mingw-ocaml

You should be able to use it to build mingw-ocaml for windows 32 and
64 bit. It has been updated with the latest ocaml (4.00.1) and flexdll
(0.30)

However, I am having some serious trouble with C++ FlexDLL linking on
Debian wheezy and sid.

This is a problem that occurs when building OCaml modules based on C++
libraries. Here's a simple way to reproduce. It does not involve OCaml
but showcases the exact issue I am having with libraries and is damn
simple:

- Install mingw-ocaml or compile it from the sources above. Doesn't
matter the version, bug is the same.

- Create this file:

% cat hello.cpp
#include <iostream>

int main()
{
  std::cout << "Hello World!" << std::endl;
  return 0;
}

- Compile it:

% i686-w64-mingw32-g++ -c hello.cpp

- Link it with gcc:
% i686-w64-mingw32-gcc -o hello.exe ./hello.o -lstdc++

- Try to link it with flexlink:

% flexlink -exe -chain mingw -L/usr/i686-w64-mingw32/lib  -o
hello-flexlink.exe -lstdc++ hello.o -v -v -v
** Use cygpath: false
** Search path:
/usr/i686-w64-mingw32/lib
/usr/lib/gcc/i686-w64-mingw32/4.6
/mingw/lib
** Default libraries:
crt2.o
-lmingw32
-lgcc
-lmoldname
-lmingwex
-lmsvcrt
-luser32
-lkernel32
-ladvapi32
-lshell32
** Cannot resolve symbols for hello.o:
 __ZSt4cout
** open: /usr/i686-w64-mingw32/lib/crt2.o
** open: /usr/i686-w64-mingw32/lib/libmingw32.a
** open: /usr/lib/gcc/i686-w64-mingw32/4.6/libgcc.a
** open: /usr/i686-w64-mingw32/lib/libmoldname.a
** open: /usr/i686-w64-mingw32/lib/libmingwex.a
** open: /usr/i686-w64-mingw32/lib/libmsvcrt.a
** open: /usr/i686-w64-mingw32/lib/libuser32.a
** open: /usr/i686-w64-mingw32/lib/libkernel32.a
** open: /usr/i686-w64-mingw32/lib/libadvapi32.a
** open: /usr/i686-w64-mingw32/lib/libshell32.a
zsh: exit 2     flexlink -exe -chain mingw -L/usr/i686-w64-mingw32/lib
-o hello.exe -lstdc++

Any input or directions to grab more information would be greatly
welcome as I am pretty dry on how to fix this issue currently..

Thanks!
Romain

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

* [Caml-list] Re: Mingw-ocaml and C++
  2013-03-24 11:43 [Caml-list] Mingw-ocaml and C++ Romain Beauxis
@ 2013-03-25  2:22 ` Romain Beauxis
  0 siblings, 0 replies; 2+ messages in thread
From: Romain Beauxis @ 2013-03-25  2:22 UTC (permalink / raw)
  To: OCaml List; +Cc: Samuel Mimram

2013/3/24 Romain Beauxis <toots@rastageeks.org>:
> Hi all,
>
> I have extracted the debian-specific build for mingw-ocaml into a
> standalone build:
>   https://github.com/savonet/mingw-ocaml
>
> You should be able to use it to build mingw-ocaml for windows 32 and
> 64 bit. It has been updated with the latest ocaml (4.00.1) and flexdll
> (0.30)
>
> However, I am having some serious trouble with C++ FlexDLL linking on
> Debian wheezy and sid.
>
> This is a problem that occurs when building OCaml modules based on C++
> libraries. Here's a simple way to reproduce. It does not involve OCaml
> but showcases the exact issue I am having with libraries and is damn
> simple:
>
> - Install mingw-ocaml or compile it from the sources above. Doesn't
> matter the version, bug is the same.
>
> - Create this file:
>
> % cat hello.cpp
> #include <iostream>
>
> int main()
> {
>   std::cout << "Hello World!" << std::endl;
>   return 0;
> }
>
> - Compile it:
>
> % i686-w64-mingw32-g++ -c hello.cpp
>
> - Link it with gcc:
> % i686-w64-mingw32-gcc -o hello.exe ./hello.o -lstdc++
>
> - Try to link it with flexlink:
>
> % flexlink -exe -chain mingw -L/usr/i686-w64-mingw32/lib  -o
> hello-flexlink.exe -lstdc++ hello.o -v -v -v
> ** Use cygpath: false
> ** Search path:
> /usr/i686-w64-mingw32/lib
> /usr/lib/gcc/i686-w64-mingw32/4.6
> /mingw/lib
> ** Default libraries:
> crt2.o
> -lmingw32
> -lgcc
> -lmoldname
> -lmingwex
> -lmsvcrt
> -luser32
> -lkernel32
> -ladvapi32
> -lshell32
> ** Cannot resolve symbols for hello.o:
>  __ZSt4cout
> ** open: /usr/i686-w64-mingw32/lib/crt2.o
> ** open: /usr/i686-w64-mingw32/lib/libmingw32.a
> ** open: /usr/lib/gcc/i686-w64-mingw32/4.6/libgcc.a
> ** open: /usr/i686-w64-mingw32/lib/libmoldname.a
> ** open: /usr/i686-w64-mingw32/lib/libmingwex.a
> ** open: /usr/i686-w64-mingw32/lib/libmsvcrt.a
> ** open: /usr/i686-w64-mingw32/lib/libuser32.a
> ** open: /usr/i686-w64-mingw32/lib/libkernel32.a
> ** open: /usr/i686-w64-mingw32/lib/libadvapi32.a
> ** open: /usr/i686-w64-mingw32/lib/libshell32.a
> zsh: exit 2     flexlink -exe -chain mingw -L/usr/i686-w64-mingw32/lib
> -o hello.exe -lstdc++

I have been able to build a working binary by adding manually the stdc++ DLL:
% flexlink -exe -chain mingw -L/usr/i686-w64-mingw32/lib  -o
hello-flexlink.exe /usr/lib/gcc/i686-w64-mingw32/4.6/libstdc++-6.dll
hello.o

This produces a working hello-flexlink.exe binary.

with OCaml modules using C++ bindings, I've had to also add
-noreexport and to sometimes also add gcc_s_sjlj DLL.

It seems to me that flexlink does not seem to be fit for using C++
symbols or that it should restrict some of its magic when dealing with
C++ symbols but alas I have no idea how to properly patch it for that
purpose.

Romain

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

end of thread, other threads:[~2013-03-25  2:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-24 11:43 [Caml-list] Mingw-ocaml and C++ Romain Beauxis
2013-03-25  2:22 ` [Caml-list] " Romain Beauxis

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