Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find -lsocket, compiling problem in client-server program?

I am trying to do some socket programming, writing a simple client-server program. But when I try to compile the program, I get this error.

gcc -o showip showip.c -lnsl -lsocket -lresolv
showip.cc: In function ‘int main(int, char**)’:
/usr/bin/ld.real: cannot find -lsocket
collect2: ld returned 1 exit status

I try to install lib doing this,

sudo apt-get install happycoders-libsocket-dev 

and when I compile, I still get the same error.

How can I get rid of this ? Thanks.

like image 930
seg.server.fault Avatar asked Sep 17 '09 12:09

seg.server.fault


People also ask

Why is Java saying Cannot find symbol?

The “cannot find symbol” error occurs mainly when we try to reference a variable that is not declared in the program which we are compiling, it means that the compiler doesn't know the variable we are referring to.

What does error Cannot find symbol mean?

Any error that starts "cannot find symbol" means that the compiler doesn't know what that symbol (which can be a variable or a class name) refers to. In the second line of the error, where it says "symbol: class Scanner", that indicates that it doesn't know what the Scanner class is.

What is server socket with example?

Sockets are bound to the port numbers and when we run any server it just listens on the socket and waits for client requests. For example, tomcat server running on port 8080 waits for client requests and once it gets any client request, it responds to them.


1 Answers

Normally the library binary comes with one package and the headers with another one with tha same name and a "-dev" behind.

Maybe you are missing plain happycoders-libsocket.

You are missing this package happycoders-libsocket, assuming you are in ubuntu.

Apparently happycoders-libsocket package in ubuntu is placing the libsocket.so libreary in /usr/lib/happycoders/ and that is not a standard place for libs, it should be directly inside /usr/lib/. Using -L you instruct the compiler, or linker in this case, to search for library files in that extra directory

like image 193
Arkaitz Jimenez Avatar answered Sep 18 '22 10:09

Arkaitz Jimenez