Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does GCC create a shared object instead of an executable binary according to file?

I have a library I am building. All of my objects compile and link successively when I run either one of: ar rcs lib/libryftts.a $^

gcc -shared $^ -o lib/libryftts.so

in my Makefile. I also am able to successfully install them into /usr/local/lib When I test the file with nm, all the functions are there. My problem is that when I run gcc testing/test.c -lryftts -o test && file ./test or gcc testing/test.c lib/libryftts.a -o test && file ./test it says:

test: ELF 64-bit LSB shared object instead of test: ELF 64-bit LSB executable as I would expect. What am I doing wrong?

like image 900
Luke Smith Avatar asked Dec 29 '15 21:12

Luke Smith


People also ask

What does shared do in GCC?

As per Difference between -shared and -Wl,-shared of the GCC options Passing -shared to GCC may enable or disable other flags at link time. As per my understanding if an executable has shared library, size of executable is very less. The executable will not run until the shared library is present and correctly linked.

Is a shared object an executable?

There's no difference, aside from the fact that a compiled executable might be linked against a shared object but not against an executable.

What is dyn shared object?

A dynamic shared object (DSO) is an object file that is meant to be used simultaneously (or shared) by multiple applications (a. out files) while they are executing.


1 Answers

What am I doing wrong?

Nothing.

It sounds like your GCC is configured to build -pie binaries by default. These binaries really are shared libraries (of type ET_DYN), except they run just like a normal executable would.

So your should just run your binary, and (if it works) not worry about it.

Or you could link your binary with gcc -no-pie ... and that should produce a non-PIE executable of type ET_EXEC, for which file will say ELF 64-bit LSB executable.

like image 81
Employed Russian Avatar answered Sep 25 '22 02:09

Employed Russian