I am having a rather puzzling problem. Recently, whenever I compile a program using GCC or G++, the compiler creates a shared library rather than an executable file. The library still runs if I execute it via CLI, but the system still treats it as a shared library in all other aspects. I have tested this problem with multiple files, and have found that while it always happens with GCC or G++, it never happens with clang. Help is appreciated. Thanks!
Asked
Active
Viewed 2,239 times
2
-
You say "the system still treats it as a shared library in all other aspects". What specifically do you notice it doing? – Joseph Sible-Reinstate Monica Mar 03 '17 at 19:53
-
Is this on Linux? What does `file` say on your object files? Can we see the command line that your compiler is used with? – dhag Mar 03 '17 at 20:08
-
@JosephSible Namely, when I click on the file, it says "Could not display
. There is no application installed for "shared library" files." – Techgineer Mar 03 '17 at 21:09 -
@dhag `file` outputs the following: `test.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped`. I compiled it with `g++ -c test.cpp && g++ test.o -o test`. – Techgineer Mar 03 '17 at 21:12
-
@MarkPlotnick I'm running Ubuntu 16.10. – Techgineer Mar 03 '17 at 21:14
-
1Can you confirm that the file has the execute bit set? If so, it seems like a bug in Nautilus (or whatever file manager you're using to try to open it), and not an issue with the compiler. – Joseph Sible-Reinstate Monica Mar 03 '17 at 21:21
-
@JosephSible It does have the execute bit set. How do I go about remedying the problem with Nautilus? – Techgineer Mar 03 '17 at 21:51
-
@JosephSible Actually, the problem is not with Nautilus. I installed Konqueror and I still have the problem. – Techgineer Mar 03 '17 at 22:03
-
Are you sure you have an `int main` function? – Cosine Mar 03 '17 at 22:16
-
@Cosine Yes, I'm sure. – Techgineer Mar 03 '17 at 22:17
-
`test.o` really ought to be relocatable, so all is well there. Your actual executable is `test`. Is there a problem with `test`? – Mark Plotnick Mar 05 '17 at 08:21
-
@MarkPlotnick Yes. It's treated as a shared library, not an executable. – Techgineer Mar 05 '17 at 23:20
-
I installed Ubuntu 16.10 and tested it. Its gcc is built with the `--enable-default-pie` flag, so it will build **p**osition-**I**ndependent **e**xecutables. This is typically done to improve security - the executable's code segment can be loaded at a random address each time the program is exec'ed. The file command reports these executables as shared objects. – Mark Plotnick Mar 07 '17 at 16:55