Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ ROM ➜ Compiling the server ➜ undefined reference to `crypt'

undefined reference to `crypt'

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Benodach   (2 posts)  Bio
Date Wed 07 Dec 2011 02:34 PM (UTC)
Message
Should be an easy one...but it's tripping me up. I am running ROM 2.4 on Ubuntu. The crypt() calls have never given me a problem since I always link with -lcrypt in the Makefile.

However, the most recent OS update, which I believe included a gcc/glibc update, is now giving me the "undefined reference to 'crypt'" errors when it comes time to link.

My calls to crypt() in comm.c and act_info.c remain unchanged from stock code and I have not messed with the prototypes anywhere.

I'm running the latest version of Ubuntu which uses Linux 3.0, gcc 4.6.1 and glibc 2.13.

As I said above, crypt() has never given me problems as long as I link with -lcrypt but now it is. In the past, I have not needed to include crypt.h or unistd.h but when I tried including these it didn't fix the errors (in fact, the read() and write() prototypes in unistd.h cause further problems with conflicts in comm.c).

Any insight would be greatly appreciated. Thanks!
Top

Posted by Benodach   (2 posts)  Bio
Date Reply #1 on Thu 08 Dec 2011 06:32 PM (UTC)
Message
I went back to the basics and (re)read the gcc man page...something I haven't done in well over 10 years. This paid off, as I noticed that within the command line syntax of gcc, it matters where you place the -l argument.

Thus, I adjusted my Makefile to reflect placing -lcrypt at the end of the command line and voila - problem solved. While my previous syntax was fine for earlier versions of gcc, it appears that is no longer the case.

So I presume gcc was now linking the crypt library after the object files in question and thus the call to crypt() was undefined.

I eventually figured it out but I'm re-posting here in the event someone else stumbles on this in the future.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 09 Dec 2011 03:34 AM (UTC)
Message
Oh yeah, sorry I didn't reply sooner. The positional linking of libraries can trip you up a bit. It's because if you put it too early on the (linker) command line the linker sees no need to include it, so you need to put the "main" project early, and then things it needs later.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


17,373 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.