Reputation: 3423
I installed libmcrypt on my system by using the following commands:-
avinash@ak-pc:~/Documents/network_lab/tut7$ cd libmcrypt-2.5.8
avinash@ak-pc:~/Documents/network_lab/tut7/libmcrypt-2.5.8$ ./configure --prefix=/usr --disable-posix-threads
avinash@ak-pc:~/Documents/network_lab/tut7/libmcrypt-2.5.8$ make
avinash@ak-pc:~/Documents/network_lab/tut7/libmcrypt-2.5.8$ sudo make install
As a result headers went to /usr/include and the libraries to /usr/lib. Now, when I include < mcrypt.h> into a .cpp file and use functions provided by libmcrypt, the compiler announces
/tmp/ccCot4nH.o: In function `main':
q3.cpp:(.text+0x64): undefined reference to `mcrypt_module_open'
q3.cpp:(.text+0xb9): undefined reference to `mcrypt_generic_init'
q3.cpp:(.text+0xd6): undefined reference to `mcrypt_generic'
q3.cpp:(.text+0x110): undefined reference to `mdecrypt_generic'
q3.cpp:(.text+0x13a): undefined reference to `mcrypt_generic_deinit'
q3.cpp:(.text+0x147): undefined reference to `mcrypt_module_close'
collect2: ld returned 1 exit status
Can anybody tell me where the problem is? Was there something wrong with the installation procedure?
Upvotes: 0
Views: 641
Reputation: 81404
Including the header files of a library only provides declarations so that the compiler is aware of function signatures and global variable types, but you also need to indicate to the linker the library your program is to be dynamically linked with.
With most compilers, use the -l
flag followed by the library's name, without the lib
prefix. For example, your linking command may look something like this:
g++ -o myprogram obj1.o obj2.o ... obj.o -lmcrypt
Upvotes: 2