Creating Executable Files in Linux

How to create a Linux executable file using python code

Basically, to make a file executable in Unix systems, you just have to do one thing: allow it to be executed (very surprising ;) ). To do it, you must use the chmod command as follows: chmod +x youfile.py. The +x add the right to be executed.

Now, your system will allow you to execute the script, but for now it's just a simple text file... Ubuntu doesn't know that he must use the python command to run it, so you'll have undermined comportment. To resolve this, we use the sha-bang line (for more information, see the wikipedia page): at the first line of your script, you must write #! program_to_use, in your case it's python. Generally, we take benefit of the env variables, and use #! /usr/bin/env python, but you can also choose yourself the version of python you want, doing #! /usr/bin/pythonX.X where X.X is the version of python.

How to create an executable for a shell script in Ubuntu?

An executable in linux is a file with the executable bit on. Thus you simply modify it with chmod:

chmod +x decBright.sh

Then you can run it with:

./decbright.sh

You can also run it by double-clicking in many graphical linux distributions.

You also better provide a "Shebang": the first line of your script should specify the "interpreter":

#!/bin/bash

Or any other interpreter (at the first line of your file).

How to compile for Windows on Linux with gcc/g++?

mingw32 exists as a package for Linux. You can cross-compile and -link Windows applications with it. There's a tutorial here at the Code::Blocks forum. Mind that the command changes to x86_64-w64-mingw32-gcc-win32, for example.

Ubuntu, for example, has MinGW in its repositories:

$ apt-cache search mingw
[...]
g++-mingw-w64 - GNU C++ compiler for MinGW-w64
gcc-mingw-w64 - GNU C compiler for MinGW-w64
mingw-w64 - Development environment targeting 32- and 64-bit Windows
[...]


Related Topics



Leave a reply



Submit