roroco
roroco

Reputation: 449

gcc: error: libhello.so: No such file or directory

here is my code:

// hello.c
#include<stdio.h>

int main(int argc, char **argv) {
    return (0);
}

i type gcc hello.c -o -shared libhello.so in terminal and get:

gcc: error: libhello.so: No such file or directory

question: How to compile .c file to .so file with one command line

update: if i fix it with gcc hello.c -shared -o libhello.so, but i just some confused, why the error message is "gcc: error: libhello.so: No such file or directory", not "gcc: error: libhello.so: No such file or directory '-shared'"

Upvotes: 0

Views: 2825

Answers (4)

huaizhi xu
huaizhi xu

Reputation: 1

 gcc hello.c

This command generates hello.c directly into the final binary executable with the default name a.out Execution is done with

. /a

If you want to give a name instead of a.out, use

 gcc -o hello hello.c

To generate hello and execute it, use

. /hello

Upvotes: 0

BTW, a shared library should contain position independent code. So compile it with

gcc  -Wall -fPIC -shared -O -g hello.c -o libhello.so

See also this and that answers.

And a shared object should (nearly) never have a main function.

PS. Order of arguments to gcc matters a lot!

Upvotes: 1

X Zhang
X Zhang

Reputation: 307

I don't know why you do this. But maybe gcc hello.c -shared -o libhello.so.

Upvotes: 0

Klas Lindb&#228;ck
Klas Lindb&#228;ck

Reputation: 33283

The name of the output file must directly follow -o. Try this:

gcc hello.c -shared -o libhello.so

Upvotes: 1

Related Questions