0

I have a simple source-file 'source.cpp:

#include <iostream>
using namespace std;

int main() {
    int ival(0);
    cout << "Bitte eine Ganzzahl: ";
    cin >> ival;
    cout << "Sie gaben die Zahl " << ival << " ein\n";
    cout << "Ein Monster mit "
        << "zwei Zeilen\n";
    return 0;
}

Now i'm compiling it with:

g++ source.cpp -o out

The result is shown in Thunar as Type 'shared library'. I can run it in Shell with ./out but I can't run it in Thunar by Double-Click.

ldd says:

linux-vdso.so.1 (0x00007fffb55be000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fd5d4387000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007fd5d403b000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fd5d3e24000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007fd5d3a6d000)
/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007fd5d4910000)

When I set the -static Flag I get a Typ 'Program' and it works in Thunar as expected but certainly it's bigger. ldd says 'The Program is not linked dynamically'

A few years ago I compiled this source but I can't remember the compiler-options and i've got a result in Typ 'Program' which was not statically linked. ldd said the same as in the first example.

So, what can i do to get a executable with the type 'Program' which can be executed by double-click in the File-Manager.

(I've certainly set the executable-Flag in all examples)

YSC
  • 38,212
  • 9
  • 96
  • 149

1 Answers1

0

I had a similar problem with Thunar because an executable I was building would be compiled to a "Shared Library" instead of executable. When I compiled using -fno-pie I would get the error: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE. Of course, -fPIE causes the executable to be compiled as a "shared library". In other words, I couldn't fix the problem by changing compiler switches. So I wrote a bash script as a work around.

runsharedlibraryasexe.sh

#!/bin/bash
"$1" &

Then when I double clicked in Thunar to run the "exe/shared library" I told Thunar to open it with this script.

Note: The bash script must be marked as executable.

I hope this helps. I really wish I could find a way to compile my application to an executable but for now this works.

AtomClock
  • 96
  • 1
  • 6