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

15,459

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

Share:
15,459
seg.server.fault
Author by

seg.server.fault

Email : [email protected] Love programming, reading SE books, blogs ... Knowledge of C, C++ (basic, self learning) ... Planning to learn C#, Java ... Learning linux ...

Updated on June 17, 2022

Comments

  • seg.server.fault
    seg.server.fault almost 2 years

    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.

  • seg.server.fault
    seg.server.fault over 14 years
    I try to install it doing sudo apt-get install happycoders-libsocket, and it says it is already installed
  • Glen
    Glen over 14 years
    @seg.server.fault. -lsocket tells your linker to link against the library libsocket.so. The -L option tells the linker WHERE to look for libraries