goldenmean
goldenmean

Reputation: 19036

Linking a shared library using gcc

I have a shared library (*.so) created using Real View Compiler Tools (RVCT 3.2) on windows target. Then I try to link this *.so file with my application using gcc on linux system.

What is the gcc option to link this shared library with my application linux?

My question is, is the -shared option, which is used as

gcc -shared myfile.so

..., used to create the SO file or to link the SO file? I believe it creates something like:

gcc -lmyfile.so

Is this enough? Or is there any other switch to tell the linker that it's a dynamic library (shared object)?

Upvotes: 53

Views: 137271

Answers (2)

mluc
mluc

Reputation: 881

What worked for me was:

gcc -L. -l:myfile.so

Upvotes: 72

jpalecek
jpalecek

Reputation: 47770

gcc -lmyfile should be enough (provided that your library is named libmyfile.so). The linker searches for shared objects when possible and AFAIK prefers them.

Upvotes: 29

Related Questions