Create W32 7-Zip sfx in Linux

7-Zip tool

7-Zip allows you to create a self extracted binary archives with the -sfx switch. But in the Linux version of 7-Zip the SFX created is a Linux binary.

So if you run the following command in a Linux box and try to run test.exe in Windows you’ll get a “Program too big to fit into memory” error.

7z a -sfx test.exe test.txt

That’s because the binary is a GNU/Linux binary.

$ file test.exe
test.exe: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

The -sfx switch in Linux will try to use 7zCon.sfx module by default and will create a Linux binary console file.

If you want to create a W32 self extracted binary in Linux you have to pick the 7z.sfx module from the windows 7-Zip version and put it in the 7z directory.

In Ubuntu you can copy 7z.sfx in the following directory:


After done this you can use the -sfx7.sfx switch to create a W32 binary SFX file.


7z a -sfx7.sfx test.exe test.txt

and you get that

$ file test.exe
 test.exe: PE32 executable for MS Windows (GUI) Intel 80386 32-bit

stringify the result of expansion of a macro argument

To strignify a c/c++ macro’s argument you just have to add a leading ‘#’ in macro’s parameter.

#define STRINGIFY(s) #s

const char * thestring = STRINGIFY(50);

The preprocessor will expand this to:

const char * thestring = "50";

But if you try to pass a macro as argument to the STRINGIFY(s) macro, the macro argument will not expand to it’s value.

#define STRINGIFY(s) #s
#define VALUE 50

const char * thestring = STRINGIFY(VALUE);

will expand to:

const char * thestring = "VALUE";

That’s because stringification and concatenation use the argument as written, in un-prescanned form.

If you want to stringify the result of a macro argument, you have to use two levels of macros.

#define STRINGIFY(s) XSTR(s)
#define XSTR(s) #s
#define VALUE 50

const char * thestring = STRINGIFY(VALUE);

so, that will expand as:

const char * thestring = "50";

resource:  Stringification – The C Preprocessor