Trouble linking program with -lcrypt

Using Slackware 64 14.1 (kernel 3.10.17), and Slackware 13.37.0 (kernel 2.6.37.6)

Any idea why I can't get the following to link? It work on a version older than 13.37 - or I built it differently back in 2005. Now, I can't get it to link with either of these versions of Slackware

I'm doing `make crypt -lcrypt` and get:

$ make crypt -lcrypt
cc   crypt.o   -o crypt
crypt.o: In function `main':
crypt.c:(.text+0x3b): undefined reference to `crypt'
collect2: error: ld returned 1 exit status
make: *** [crypt] Error 1
#define _XOPEN_SOURCE
#include <string.h>
#include <unistd.h>
#include <stdio.h>

main(int argc, char *argv[])
{

    if ((argc > 1) && strlen(argv[1]))
    {
        printf("%s\n", crypt(argv[1], "MF") + 2);
    }
}

Open in new window

LVL 1
jmarkfoleyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
Your Makefile should contain something like the following target:

all:
<tab>gcc crypt.c -o crypt -lcrypt

Open in new window


Note: <tab> MUST be a tab character - it cannot be just white space!

You can't just pass the linker arguments direct to make like that, they need to be passed to the compiler/linker as part of the Makefile.

https://www.gnu.org/software/make/manual/make.html#Running
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jmarkfoleyAuthor Commented:
Yup! That did the trick. Actually I just used `gcc crypt.c -o crypt -lcrypt` on the command line.

I knew all this once. It's been too long since I've done C!!!
0
evilrixSenior Software Engineer (Avast)Commented:
Glad to have been able to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.