ocamlopt on Windows doesn't produce executable - winapi

Here's a simple OCaml program: helloworld.ml
print_string "Hello world...\n" ;;
I'm using OCaml 3.11.0 (MSVC built), VS 2008, and of course FlexDLL
Here's how I compile it (ran from the VS 2008 shell):
ocamlopt helloworld.ml -o helloworld
No executable created. Is there something wrong?
The program compiled and ran on Linux, though.

Show the full output from ocamlopt.
-o helloworld will produce binary helloworld (without extension).
If you want an .exe extension -- specify it explicitly
ocamlopt helloworld.ml -o helloworld.exe

Related

Importing a binary file into MASM (equivalent to incbin directive on NASM)

I'm looking for a simple way to produce an EXE file on Windows using the standard tools with Visual Studio e.g. ml, cl, link etc.
For example, using NASM it's possible to do:
; $ nasm -f win64 prog1.asm -o prog1.o
; $ x86_64-w64-mingw32-ld prog1.o -o prog1.exe
Global Start
Start:
incbin "img01.bin"

How to run a c++ program if unordered_map is used

I have used unordered_map in my c++ program. I complied program successfully by using :
g++ -std=c++0x source.cpp
But after that i have entered source to run program but prompt show me that source is not internal or external command.
Default output filename is a.out (a.exe on Windows)
Use -o option to specify file name, like this:
g++ -std=c++0x source.cpp -o source

Why compiling a program produces a file that is not executable?

I am using g95 to compile a fortran code. I use
C:\MinGW\bin>g95.exe -c C:\test\coil.f -o C:\test\coil.exe
It compiles and gives coil.exe which is created as 16 bit application so when ever I try to run this executable it throws an incompatibility error. I am using windows 7 64bit. I think by default it goes to 16 bit. Is there a way to get 64 bit in place of 16bit?
If you want to obtain an executable, compile it as follows:
g95.exe C:\test\coil.f -o C:\test\coil.exe
, i.e. without the -c switch. With -c you are getting an object file (.obj) which is not supposed to be executed.
From the comment by #DmitriChubarov

How can I generate an ELF file with GCC?

I am writing C and C++ code on Linux OS and I am using GCC. After finishing my code, I would like to generate an ELF file. I just can generate "a.out" file and I don't need it. How can I get ELF file ? ELF file occurs as a result of what ? or Is it possible to generate this file with this program ?
The compiler (i.e. gcc or g++) will invoke the linker (ld) which produces an ELF executable.
In practice, you will use a builder program (like make) to drive gcc commands. See this answer.
The default output file for gcc is still named a.out (for historical reasons) but is an ELF file. And you really want to ask gcc to output an executable with a more fancy name.
Simple example, you code a single-file hello-world.c program. You can compile it with e.g.
gcc -Wall -g hello-world.c -o hello-world-bin
(order of arguments to gcc matters a lot!)
and the produced hello-world-bin is an ELF executable. Check with
file hello-world-bin
then run it with
./hello-world-bin your arguments to it
Later, learn how to use the gdb debugger on it.
See also this and that answers.

Mixed language C++, C and Fortran compilation with Cmake

Using g++, gcc and gfortran on GNU/Linux, I've written a simple script to compile and link together a number of source code files written in C++, C and Fortran. Here are the complete contents of the script. This script has been tested, and works well.
g++ -c test-Q.cpp -I./boost/boost_1_52_0/ -g
gcc -c paul2.c -g
gcc -c paul2_L1.c -g
gcc -c paul6.c -g
gcc -c paul6_L1.c -g
gcc -c fit_slope.c -g
gfortran -c getqpf.F -g
g++ -o test-Q test-Q.o paul2.o paul2_L1.o paul6.o paul6_L1.o fit_slope.o getqpf.o -g -lgfortran
To make this more cross-platform, I would like to re-write the script using Cmake. How might I handle mixed-language compilation?
The following test script listed below does not work, and will only selectively compile some of the files.
Is there perhaps another cross-platform build process that might be better suited for this type of compilation?
cmake_minimum_required (VERSION 2.6)
project (q-test)
include_directories(/media/RESEARCH/SAS2-version2/test-Q/boost/boost_1_52_0)
add_executable( q-test
test-Q.cpp
paul2.c
paul2_L1.c
paul6.c
paul6_L1.c
fit_slope.c
getqpf.F
) # end
You need to enable Fortran for the project like this:
project (q-test C CXX Fortran)
Also, you might want to use find_package(Boost) instead of hard coding an include path.

Resources