Ocamlopt and missing crt2.o file - ocaml

Having installed OCaml on Windows 7, 64 bit (self-installer), I tried to create a simple exe file with
ocamlopt HelloWorld.ml -o HelloWorld
As required I used the native-code compiler (ocamlopt) with Visual C++ (I have Visual Studio 10 installed) and the Microsoft Assembler MASM version 8 (MinGW is also installed); I have also set the path variables for OCaml (c:\ProgramFiles\Ocaml\bin), MinGW (c:\ProgramFiles\MinGW\bin) and MASM (C:\masm32\bin). However, despite my best efforts and much searching I cannot get around the error message
**Fatal error, Cannot find file "crt2.o"
File "caml_startup", line 1, characters 0-1:
Error: error during linking.
except when I place the HelloWorld.ml file in the lib folder of MinGW, where the crt2.o file is located. I appreciate the answer may be straightforward, but I am stuck. Any help would be greatly appreciated.

I guess mingw needs some way to find library files - when it is compiled from source - path to lib is hardcoded in binaries, if not - it will search in some way (environment variables). Try building either from mingw (or msys) shell which is likely to provide correct environment or set the LIB env variable manually. BTW when debugging mingw problems it will be easier to rule out ocaml first and try building simple C program first.

I kind of remember it is a known bug: contrary to what is said in the documentation, you also need Cygwin installed.
Another problem might be a 32/64 bit incompatibility, i.e. some of your tools are using 32 bits targets, while other ones use 64 bits targets.

Could you be more precise on which OCaml installer you used (URL?). Have you tried the installer present on this page? It lists several potential issues and how to setup MinGW/MSYS for native compilation.
It is very important that we understand clearly the problem you have and, eventually, the solution you found, so that we can tell the maintainers how to update the relevant documentation.

I wrote the installer.
So just to settle the matter, the detailed instructions are at http://protz.github.com/ocaml-installer/ and indeed you have to export the right FLEXLINKFLAGS as an environment variable because ocamlopt uses flexlink (which the installer packages). However, flexlink itself doesn't work out of the box in a msys environment.
The next version of the installer will encourage you to use cygwin, where everything should work flawlessly.
Cheers,
jonathan

Related

How build harfbuzz without dependencies

I want build latest harfbuzz-ng library on Windows 7. But in build system by default I must go through long quest to gain: ragel, pkg-config, gtkdocize and other stuff. Even in the end if I get all what need for build system I get errors (sorry cannot say which concrete errors), last time I tried to build this library 2 month ago). Maybe on Linux system it is easy to get and build all this stuff but on Windows always something doesn't want to be compiled. Or the problem is that I don't find instructions which guide me on Windows, only Linux.
What I want to get is simple instructions how build only harfbuzz-ng with freetype dependency (and maybe add ICU) by MinGW compiler on Windows.
Thanks you very much.
For anyone reading this, have a look at harfbuzz.cc in the project which makes you able to use harfbuzz without any build system, just include it in one of your sources, no build system is required, define HB_NO_MT or even HB_TINY (which brings a minimal harfbuzz) if you don't use harfbuzz in multithread mode.
I don't know i this is the answer you are looking for. I am trying to work with Harfbuzz as well and did this through several attempts which did not work out for various reasons.
One (old) example you could use as a starter is: HarfBuzz static lib. The .lib-file generated works with UCDN and just needs this file plus a source for the Freetype-functions to provide the necessary FT_Face-parameter (i did this by compiling another .lib via the freetype-sourcecode (freetype.org/download.html).
But I am unsure if this will work out for the MinGW-compiler (you don't use VC++ as IDE do you??).
You may find of interest the MSYS2 build system. It is essentially a linux-style packaging system built on top of Windows(TM). You can download and install binary packages with simple commands (including automatic dependency solving). If you want to download a source package you can do that as well. http://msys2.github.io

What is MakeFile in Eclipse?

What is MakeFile in Eclipse? From the documentation:
A makefile is a text file that is referenced by the make command that
describes the building of targets, and contains information such as
source-level dependencies and build-order dependencies. The CDT can
generate a makefile for you, such projects are called Managed Make
projects. Some projects, known as Standard Make projects, allow you to
define your own makefile.
But the explanation does not help me understand what a MakeFile is. I am moving from VisualStudio/C# to Eclipse/C++. Is MakeFile analogous to Visual Studio's Metadata? When do I need to write a MakeFile, and why do I need it besides the C++ code?
[EDIT]
I used to develop on Windows with VS and C#. And now trying Eclipse/C++ on a Mac. I have never build anyone on Linux. So the answer I have read so far does not help explain anything at all.
A makefile in the simplest terms is a file that builds a program. These are normally used from the command line. If you have ever built something on linux you may have run ./configure ; make ; make install. You are using a makefile there.
More info...
https://en.wikipedia.org/wiki/Make_(software)
In simple terms: Make helps you create cross-platform configuration settings in one file, and it will work on surprisingly many platforms, including Windows or Mac OS-es.
Mentioning Windows, you should have Make installed on the computer you're installing on (on Windows, Cygwin and MinGW include Make). It's required only if the user will actually build the code from the source.
But of course, you should include Make code for each different platform (e.g. one for Unix-like, one for Windows, etc.)

Making flex.exe on windows

I have downloaded the source code for flex from the Flex repository. The file is flex version 2.5.35 in tar.gz. Now how can I make flex.exe from this source code?
Just download the binary packages instead, they are available here: http://gnuwin32.sourceforge.net/packages/flex.htm alternatively you need to use the makefile the source comes with to compile it (by passing as a parameter to gcc's make.exe).
You have two options:
Download this instead and follow the directions in the link to download the installer and dependencies.
Use something like 7-Zip to extract the files and follow the included instructions for compilation (much more difficult).
The former sounds like the right answer for you unless you need a feature of the latest version and have the GNU toolchain available on your platform. I don't know if flex will compile with the MS compiler without lots of pain.
If you really want to build it from source by yourself on a Windows machine (which may or may not work), you will want to install Cygwin first.
You can try this: http://sourceforge.net/projects/winflexbison/
This is latest flex-bison tools ported to windows without extra dependencies (like m4.exe or Cygwin dlls)

Setting up midiIO library on Windows

I've downloaded the midiIO library and in the readme it says:
edit the file Makefile.library and set the OSTYPE and OSSUBTYPE to match your hardware/os setup.
type "make library" to compile the library. It will be created as lib/libmidiio.a in unix.
edit the file Makefile.examples and set the OSTYPE and OSSUBTYPE to match your hardware/os setup.
Also, if you are using ALSA, then uncomment out the POSTFLAG to use the alsa library (-lasound).
type "make examples" to compile the example programs in the examples directory. The example programs will be place in the bin directory.
1 + 3 are fine but 2 + 4 are over my head. I've worked in a unix environment before and have used gcc with flags but I need to get this done in Windows. I typically use Visual Studio but don't know how to achieve this with that.. I've downloaded Dev-C++ if that's any use but I don't know what to do with the makefiles?
Ignore the makefiles and set up a fresh project in Visual C++. Make your target a static library (which will be a .lib file in Win32, not a .a file as in unix as you probably know). It is unlikely that the project will build out of the box, so you might have to deal with some compilation errors relating to unix-specific symbols. I took a quick look at the source code, and it looks fairly well-written, so I don't think you should have many problems building it directly in Windows.
Alternately, you could build the source using the real make tool in cygwin, but this means that you would need to distribute the cygwin library with your final product. This may or may not be more trouble than it's worth, especially if you are already using VC++ for the rest of your project's code.

How to prepare a codebase for compiling on both Windows and Unix-based systems

I am wondering about different solutions to easily compile my cross-platform application for both windows and unix.
Right now I am using a makefile on Ubuntu, but before my codebase grows larger I'd like to perform the steps necessary to compile it on Windows, and then continue doing so regularly to see that it still works.
I'd preferably not contaminate my SVN codebase repository with multiple "makefile" solutions, such as VC++ solutions and so on, I'd like a more automatic way. I tried using mingw with make for windows, but it seems my secondexpansion awesomeness doesn't work on the Windows version (or something like that). It wouldn't compile, and also complained about _winNT or something like that not being defined.
How should I prepare my codebase for cross-platform easy compiling? Things like buildtools, perhaps autogenerate VS file from makefile, or something similar. Some preprocessor magic in a stdinc file perhaps?
Thanks!
I will point you to CMake which is used by high-profile projects, such as MySQL, KDE, or Compiz.
It has the ability to generate native build files for the target system, such as Makefiles for Unix-based platforms, and Visual C++ project and solution files for Windows.
In order to deal with platform differences, I invite you to see my previous post on this subject: C++: Platform dependent types - best pattern
I would go for boost build: http://www.boost.org/doc/tools/build/doc/html/index.html
You can choose your platform and your compiler from the command line (dos command prompt on Windows) and everything else works.
e.g
bjam release gcc,
or
bjam debug msvc
You can add extra flags for each compiler (if you so wish) or different versions of the compiler.