Overflower
Overflower

Reputation: 61

gcc -lnsl error in socket programming on mac os

I am trying to compile my C socket programming files using gcc with -lnsl option on MAC OS but it gives me this error:

ld: library not found for -lnsl

clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is the gcc command:

gcc -o server -lnsl server.c

I looked all over the internet but I can't find sth relevant to help me. How to install the missing library? Or should I reinstall gcc? Please help!

Thanks!

Upvotes: 4

Views: 3428

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 119877

Mac OS X has no libnsl. Functions that live in libnsl on Linux are found in the standard C library on Mac OS X. No additional flags are necessary for building programs that use these functions.

If your program works on Linux and doesn't work on a Mac, then your program has a bug that is triggered on Mac OS X but not on Linux. No amout of fiddling with linker flags is likely to change that.

Upvotes: 5

Related Questions