LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-23-2005, 05:30 PM   #1
emailbuilder88
LQ Newbie
 
Registered: May 2005
Posts: 23

Rep: Reputation: 1
newb: static linking with mcrypt


Hello all,

I am wondering if it is possible to statically link to mcrypt libraries when compiling and linking my own c code? I get these errors when I do:

gcc -I/usr/local/include -c xx.c
gcc -o xx xx.o -L/usr/local/lib -lmcrypt -static

/usr/bin/ld: cannot find -lmcrypt
collect2: ld returned 1 exit status
make: *** [filtercmd] Error 1

I removed -lmcrypt and did this instead:

gcc -o xx xx.o -static /usr/local/lib/libmcrypt.so

This seems to link OK, but when I try to run the resultant
application, I get this:

/usr/lib/libc.so.1: bad ELF interpreter: No such file or directory

Yikes! Where is it trying to dynamically link this? But I'm not sure I even linked correctly anyway.

All this is on Fedora Core 2, BTW, with libmcrypt 2.5.7 installed from source (correctly, I think, since PHP uses it perfectly fine).

The code I am compiling is just VERY simple example code to get me going:

#include <mcrypt.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
char *algo = "asdfasdf";
MCRYPT td;
td = mcrypt_module_open(algo, NULL, NULL, NULL);
}

= = = = = = = = = = = = = = = = = = = =

I also can't get it to link dynamically, which is NOT my first choice (due to other constraints):

When linking, I removed -static and the direct libmcrypt.so reference and added -lmcrypt -L/usr/local/lib:

gcc -o xx xx.o -L/usr/local/lib -lmcrypt

Which links OK, but this happens when running it:

error while loading shared libraries: libmcrypt.so.4: cannot open
shared object file: No such file or directory:

But I think this happens because I didn't compile mcrypt to use dynamic loading (see libmcrypt's README; it's not turned on by default). Again, static linking is my preference anyway.


mcrypt-devel list is ghostly quiet.... hoping there are actually ppl here.

TIA!!!!
 
Old 05-23-2005, 07:18 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
I'm guessing /usr/local/lib isn't in your system default library search path. Either add /usr/local/lib to /etc/ld.so.conf and rerun ldconfig or simply add /usr/local/lib to your LD_LIBRARY_PATH environment variable.
 
Old 05-23-2005, 07:53 PM   #3
emailbuilder88
LQ Newbie
 
Registered: May 2005
Posts: 23

Original Poster
Rep: Reputation: 1
Thank you for your help!

Unfortunately, although I did try adding /usr/local/lib to /etc/ld.so.conf, and that FIXES the problem when I link dynamically, I still cannot compile statically.

I am not clear about what environment LD_LIBRARY_PATH is in (and have NO IDEA if it will help when linking statically??). It's certainly not in a standard login shell. Is it something I should set when compiling? Linking? Any hints?

Thanks very much!

For the record:

echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

THIS WORKS:

gcc -I/usr/local/include -c xx.c
gcc -o xx xx.o -L/usr/local/lib -lmcrypt
xx

THIS *DOES NOT* WORK:

gcc -I/usr/local/include -c xx.c

gcc -o xx xx.o -static -L/usr/local/lib -lmcrypt
/usr/bin/ld: cannot find -lmcrypt
collect2: ld returned 1 exit status

gcc -o xx xx.o -static -L/usr/local/lib
xx.o(.text+0x21): In function `main':
: undefined reference to `mcrypt_module_open'
collect2: ld returned 1 exit status

gcc -o xx xx.o -static /usr/local/lib/libmcrypt.so
# links OK, but same error when running the binary:
xx
bash: ./xx: /usr/lib/libc.so.1: bad ELF interpreter: No such file or directory
 
Old 09-16-2005, 09:46 AM   #4
glvgfz
LQ Newbie
 
Registered: Sep 2005
Location: Sydney, Australia
Distribution: Vector Linux
Posts: 26

Rep: Reputation: 15
I'm having a similar problem, did you end up solving it?
 
Old 09-16-2005, 10:37 AM   #5
freegianghu
Member
 
Registered: Oct 2004
Location: somewhere in the street
Distribution: Window$
Posts: 192

Rep: Reputation: 30
Try:
Code:
gcc -o xx xx.o /usr/local/lib/libmcrypt.a
 
Old 09-16-2005, 09:52 PM   #6
glvgfz
LQ Newbie
 
Registered: Sep 2005
Location: Sydney, Australia
Distribution: Vector Linux
Posts: 26

Rep: Reputation: 15
My problem is with libc.a not libmcrypt.
I'm opening another thread for my problem.
http://www.linuxquestions.org/questi...hreadid=364076
 
Old 09-20-2005, 02:17 PM   #7
emailbuilder88
LQ Newbie
 
Registered: May 2005
Posts: 23

Original Poster
Rep: Reputation: 1
Sorry, I didn't solve the problem. The libmcrypt list was not helpful, nor was this forum. You'd think there were other people actually using this software somewhere....?

freegianghu fails to note that the point is to link statically.

I eventually gave up and found another way around what I was trying to do.... and I don't remember what that was at the moment (sorry), but it was application specific anyway.
 
Old 07-29-2009, 03:54 PM   #8
qzjake
LQ Newbie
 
Registered: Jul 2009
Posts: 1

Rep: Reputation: 0
Lightbulb mcrypt-devel

you probably got the wrong yum install.

try "yum install mcrypt-devel"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking static and shared libraries in the KDevelop Environment tristanm Programming 15 11-27-2006 09:59 PM
building glibc 2.3.5 for static linking. rekhakp Linux - Software 0 04-26-2005 12:17 PM
static linking to c library lantern Programming 1 04-19-2004 08:58 AM
Finding and Linking Static Libraries with gcc neorich Programming 15 08-10-2003 04:03 PM
Static/dynamic linking ugenn Linux - Software 0 12-15-2002 11:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration