V
V
valentin_dev2020-08-13 17:55:09
linux
valentin_dev, 2020-08-13 17:55:09

Need help cross compiling a binary for different Linux systems?

The task is:

  1. There is a simple console program, without libraries and dependencies
  2. It needs to be compiled into a binary so that it can be run on different versions of Linux (Ubuntu, CentOS, Fedora, etc.) mostly 64 bits. Just copied and used.
  3. To solve this problem, I tried using Holy Build Box + Docker, compiling statics, etc., but the problem remains. After transferring the binary to another Linux host and running it, I get an error: segmentation fault .


The code for a simple test program:

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

int main()
{
   std::cout << "TEST BUILDS FOR RUN LINUX" << std::endl;
   return 0;
}


Additionally:

You can even look not in the direction of C / C ++ (this, of course, changes the logic of work, but I'm ready to sacrifice its change, since portability is in question).
The main task to be solved: I need to send a request (number) to the executable file, get an answer (key - generation based on the number passed). But the executable code must be hidden. Options??

I really need help on this!

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Alexander Ananiev, 2020-08-13
@SaNNy32

Just build the executable on a system with the minimum ABI version. Will run on most systems.

T
Ternick, 2020-08-13
@Ternick

I think the easiest way to solve the problem is to use an interpreter. Take some python3 or Dart. Dart, by the way, is possible (compiled), but python3 is many times faster.
I think if you transfer your project to python you will not regret it, BUT it is desirable that python3 be installed on all machines if you want to transfer it in the form of source code or you can package the project through pyinstaller into an executable file.

F
falconandy, 2020-08-13
@falconandy

It is possible to rewrite in Go and compile a static binary without dependencies.
https://www.arp242.net/static-go.html
The newly released Go 1.15 will have a smaller binary size than previous versions.
To compile the 32-bit version, just set a couple of variables:
GOOS=linux GOARCH=386 go build

S
shurshur, 2020-08-13
@shurshur

Compile as a static binary (it is possible even under x86 to work on 32-bit and 64-bit machines).

$ echo 'int main(){ printf("Hello, World\n"); }' > xxx.c
$ gcc -static xxx.c -o xxx
xxx.c: In function ‘main’:
xxx.c:1:13: warning: implicit declaration of functionprintf’ [-Wimplicit-function-declaration]
 int main(){ printf("Hello, World\n"); }
             ^~~~~~
xxx.c:1:13: warning: incompatible implicit declaration of built-in functionprintf’
xxx.c:1:13: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
$ ./xxx 
Hello, World
$ ls -l xxx
-rwxrwxr-x 1 shurik shurik 844696 авг 13 22:04 xxx
$ ldd ./xxx
        не является динамическим исполняемым файлом

But if you use a lot of different libraries, you will need their static versions, which can be stressful.

P
pvsam, 2020-08-20
@pvsam

Compile static g++ -static.
A segmentation fault, this is somewhere an error, all calls must be checked for the returned data.

V
ValdikSS, 2020-09-03
@ValdikSS

* [amd64] Enable LEGACY_VSYSCALL_NONE instead of LEGACY_VSYSCALL_EMULATE.
This breaks (e)glibc 2.13 and earlier, and can be reverted using the kernel
parameter: vsyscall=emulate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question