How can I compile a standalone Ruby script into a standalone AOT compiled macruby executable? - macruby

How can I compile a standalone Ruby script into a standalone AOT compiled macruby executable?
I would like to write a command line tool in MacRuby that can be distributed.

macrubyc is your friend. The simple hello world example, In a terminal:
chris$ echo 'puts("Hello, world!")' > hello.rb
chris$ macrubyc hello.rb -o hi
chris$ ./hi
Hello, world!
chris$ file hi
hi: Mach-O 64-bit executable x86_64
chris$
There are a few things to bear in mind, the most important being that the binary needs a macruby runtime to link against. On your machine you can just run the 'hi' programme as I did above, but when you're shipping it to macs without macruby installed you'll have to statically compile it into the executable.
See the macrubyc manpage for more details.

The traditional way is to deliver your command line utility as an uncompiled ruby script. If you prefix it with
#!/usr/bin/env macruby
and set the file executable with
$ chmod a+x myfile.rb
then from the user's point of view, it just runs, as if it was a binary.
If you do want to deliver it as a binary, that question has been asked here.

Related

16-Bit Error When Developing OpenGL Application on Windows

First, the background information - the question itself follows in bold.
I am trying to learn how to write OpenGL programs on 64-Bit Windows 10 Home (Version 21H2 OS Build 19044.1706). I program using Notepad++ as a text editor, and build via batch scripts and command prompt. I do not want to use an IDE or advanced build tools as I have found minimalistic tools to be easier for me to learn.
My development environment is as follows:
I have downloaded the .zip files for GLEW and freeglut from graphics.ucdenver.edu, and extracted the files to Desktop\Graphics\Dependencies\Glew and Desktop\Graphics\Dependencies\FreeGlut, respectively.
In Desktop\Graphics, I have included the code from https://github.com/TransmissionZero/Hello-GLUT as a test, and I am trying to build it using the following batch script:
#echo off
gcc -c %1.c -o %1.exe -I"C:\Users\myusername\Desktop\Graphics\Dependencies\FreeGlut\include" -L"C:\Users\myusername\Desktop\Graphics\Dependencies\FreeGlut\lib" -I"C:\Users\myusername\Desktop\Graphics\Dependencies\Glew\include" -L"C:\Users\myusername\Desktop\Graphics\Dependencies\Glew\lib" -lopengl32 -lbz2 -Wl,--subsystem,windows -Wall
where I am passing the location of the C program (TransmissionZero\HelloGLUT\HelloGLUT) as the command line argument.
The command succeeds without errors or warnings, but when I run the exe, I get "Unsupported 16-Bit Application" and the example program does not run. How do I resolve this issue?

CMake compilation failing on MSYS2

I'm trying to set up CMake for a project I'm working on, and I'm first trying to compile a simple Hello World program in C. I'm using Windows 10 with MSYS2. If I invoke the compiler (GCC) directly in Bash, it compiles fine without warnings or errors and gives an executable as output which prints "Hello, world!" exactly as expected. My problem comes in when I try to use CMake to compile my project. When I run cmake -G Ninja .. to compile my project, it throws this error:
CMake Error at C:/msys64/mingw64/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/msys64/mingw64/bin/cc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/dylanweber/Documents/C-Projects/webapp/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/msys64/usr/bin/ninja.exe cmTC_45340 && [1/2] Building C object CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj
FAILED: CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj
C:\msys64\mingw64\bin\cc.exe -o CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj -c testCCompiler.c
/bin/sh: C:msys64mingw64bincc.exe: command not found
ninja: build stopped: subcommand failed.
Notice how it mentions C:msys64mingw64bingcc.exe... there must be some kind of path delineation problem but I've tried setting the CC environmental variable to C:\\msys64\\mingw64\\bin\\gcc.exe and C:/msys64/mingw64/bin/gcc.exe. I have been clearing the CMake caches between runs.
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.15)
project(webapp)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
file(GLOB SOURCES "main/*.c")
add_executable(webapp ${SOURCES})
My code is in a "main" folder which is currently just one "main.c" file, in addition to a build directory used to keep all the temporary files in. The most frustrating part is that CMake was just working an hour ago, and I didn't change anything. What can I do to fix this problem?
The solution was not only installing the MinGW64 version of CMake, but also the MinGW64 version of Ninja as well. Since they have different pathing schemes compared to MSYS, they didn't play well together until they were both on the same POSIX-like platform.

Is there such a thing as a MSYS script file?

I'm running MSYS under Windows and although it works I want to know if there is such a thing as a MSYS script file.
For example to compile a GTK program in C I need to type: gcc source.c -o executable.exe 'pkg-config --cflags --libs gtk+-3.0' to compile. Is there a way to store this in a file and run the file from MSYS without having to type in the command each time (IE like .bat, .sh files)?
If you want to automate building an application, just use a build system. The Meson build system is what the GTK+ developers recommend now (and GStreamer, and many other projects). It's multiplatform, and available as a package in MSYS2 (I used it there, works like a charm). They have a simple Meson tutorial where they build a GTK application. That's 3 lines of code.

How to create an executable C file for Windows

I know this question has been asked several times and I took a look at many of them like
Running linux gcc-compiled program under windows
How can I compile C files into an executable (.exe) file?
Unfortunately, none of them worked for me.
My situation
I've installed Ubuntu and Windows on my Notebook.
Let's say I developed a simple "Hello,World!"program using a text editor in c.
In Ubuntu, I've compiled it using GCC
$ gcc -o hello.out -g -Wall -pedantic hello.c
I executed it './output.out'
And got the result Hello, World!
What I tried
So I kind of cross-developed here. I switched to Windows and kept going.
Now, I try to make it an executable file in order to run it on Windows. I know Windows can't handle '$ ./output.out' , alright, let's make it an executable then.
Under Windows, I've
installed cygwin
In Cygwin, I compiled it using GCC
$ gcc -o hello.exe -g -Wall -pedantic hello.c
Note: I wrote hello.exe instead of hello.out or hello.c
In Cygwin, I executed it '$ ./output.exe'
And got the result Hello, World!
Note: At this point, it even works with my Shell under Windows because I installed Cygwin and set up my PATH etc. This means I can open my command line, go to the directory in which 'hello.exe' is located and execute it by typing '> hello.exe'
I thought that would be it, so I took hello.exe' and moved it to another notebook (not my local machine). I tried to execute it but it didn't work.
At first, I got an cygwin1.dll missing message. After fixing it, another error appears.
What I'm trying to accomplish
To make a long story short:
The reason I wrote so much is that I want to give you a detailed look of my situation.
Basically, I'm trying to create an executable c file, which any Windows User could execute without having any development tools.
In Eclipse and Java, you could simply export your program making it a runnable -jar file. All the User has to do is install the latest Java SE version to get it running.
Additionally, I tried to compile my program in Visual Studio but that didn't work either.
Any suggestions? Thanks a lot!
cygwin gcc produce an executable linked to the cygwin1.dll. So it is not usable without that.
gcc hello.c -o hello-cygwin.exe
$ ldd hello-cygwin.exe
ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x77bd0000)
kernel32.dll => /cygdrive/c/Windows/system32/kernel32.dll (0x77ab0000)
KERNELBASE.dll => /cygdrive/c/Windows/system32/KERNELBASE.dll (0x7fefdc60000)
SYSFER.DLL => /cygdrive/c/Windows/System32/SYSFER.DLL (0x75650000)
cygwin1.dll => /usr/bin/cygwin1.dll (0x180040000)
If you need a standalone program, a solution is to use the mingw compiler
(it is available on cygwin as cross compiler to windows)
$ x86_64-w64-mingw32-gcc.exe hello.c -o hello-mingw64.exe
$ ldd hello-mingw64.exe
ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x77bd0000)
kernel32.dll => /cygdrive/c/Windows/system32/kernel32.dll (0x77ab0000)
KERNELBASE.dll => /cygdrive/c/Windows/system32/KERNELBASE.dll (0x7fefdc60000)
SYSFER.DLL => /cygdrive/c/Windows/System32/SYSFER.DLL (0x75650000)
msvcrt.dll => /cygdrive/c/Windows/system32/msvcrt.dll (0x7fefdf40000)
You can move the resulting program on another windows machine that don't have cygwin installed.
You should use mingw which is the gcc port for windows instead of gcc under cygwin. You can get it here.

How do I execute a standard GCC "configure" script with the TDM64-GCC toolchain?

Which of the executables in the TDM bin directory will actually recognize ./configure as a valid command?
./configure is a shell script. It will be compatible with bash, sh, and maybe csh. Probably the first line in it is
#!/bin/sh
or
#!/bin/bash
If you are not on Linux or Unix, look for a configure script specifically for your operating system. Not all tools support non-Unix environments.
First thing you should read the INSTALL or README file included with the sources. Usually they describe all of the available parameters for the ./configure script (which is not "standard GCC", but specific to the project). For example for the strace project (picked it randomly, as I've cross-compiled it recently), if you want to cross-compile it with your tdm64-whatever-gcc toolchain, you have to specify it in the host parameter:
./configure --host=tdm64-whatever

Resources