Cannot compile program on Ubuntu that uses libmcrypt - c

I created a C program that uses libmcrypt. I compiled it for many times in a CentOS machine, but now, trying to do the same thing in Ubuntu, I get this:
/tmp/ccM2ugbq.o: In function `encrypt':
util.c:(.text+0xa1): undefined reference to `mcrypt_module_open'
util.c:(.text+0xc6): undefined reference to `mcrypt_enc_get_iv_size'
util.c:(.text+0x134): undefined reference to `mcrypt_generic_init'
util.c:(.text+0x1dc): undefined reference to `mcrypt_generic'
util.c:(.text+0x1fa): undefined reference to `mcrypt_module_close'
/tmp/ccM2ugbq.o: In function `decrypt':
util.c:(.text+0x288): undefined reference to `mcrypt_module_open'
util.c:(.text+0x296): undefined reference to `mcrypt_enc_get_iv_size'
util.c:(.text+0x304): undefined reference to `mcrypt_generic_init'
util.c:(.text+0x375): undefined reference to `mdecrypt_generic'
util.c:(.text+0x380): undefined reference to `mcrypt_module_close'
, although I have installed libmcrypt and have spacified the flags properly when compile (-I/usr/include -L/usr/lib -lmcrypt)
Can anyone guide me on how to get the compilation work properly with libmcrypt?
EDIT: man pages says: Compile as "cc prog.c -lmcrypt", or "cc prog.c -lmcrypt -lltdl" depending on your installation.
I also installed libltdl-dev, but it does not work.
EDIT 1:
System information:
version (running uname -r):
3.5.0-25-generic
release (running lsb_release -a):
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.10
Release: 12.10
Codename: quantal
EDIT 2:
Because #teppic requested me to show the compile command, I solved my issue, but I need some explanations. Bellow I'll detail the topic:
the command that I used and failed:
cc -Wall -I../path/to/include -lmcrypt ./a_file.c ./some/other/file.c ./some/other/files.c ./main/file.c -I/some/include/path -lother_lib -o ./bin/out
After that, I only put the -lmcrypt at the end of command and deleted it from the first place, and it worked.
In my initial question, I told you that I did compile it before in CentOS and everything worked fine. That's true, even if in CentOS the compile command were the former one (probably some files differ in order or some libraries).
Can anybody explain me how the flags order influences the compilation success or failure?

In general you should put the library dependency after the source file that references it in the command line. In older versions of gcc, this wasn't always the case.

1) Try installing libmrypt-dev
2) Locate the path of libmcrypt using "locate" command
3) If not in standard library path, try adding the path to LD_LIBRARY_PATH environment variable
4) If nothing helps try installing again using "yum install mcrypt-devel"

Related

intel mpicc linker error undefined reference to `_mm_idivrem_epi32'

I am trying to compile source of milcv7.7.8/ks_spectrum on a cluster with MPICC using version 11.1 20090511 when make the source in milcv7.7.8/ks_spectrum by 'make ks_spectrum_hisq' command then at last the error comes out as
com_mpi.o: In function initialize_machine':
../generic/com_mpi.c:(.text+0xb447): undefined reference to_mm_idivrem_epi32'
I know now that this function _mm_idivrem_epi32 is a part of ia32intrin.h file in intel compiler.
When I use the latest intel mpiicc on new cluster with 14.0.0 20130728 version of intel compiler then code compiles successfully.
So is there any way to tell linker to include function _mm_idivrem_epi32 location...
_mm_idivrem_epi32() is not a function but rather a compiler intrinsic. When properly handled, it is replaced with a call to __svml_idivrem4() from the Intel's Short Vector Math Library libsvml.
You are most likely being hit by a bug in ICC's auto-vectoriser. Try compiling the same source file with -no-vec and see it this has any effect. Or better use the newest ICC version that you have at your disposal.

gsoap client compile/link error

Now I am writing a program to call a web service. I write testMain.c. The others are generated by wsdl2h and soapcpp2.
My compiling command is like this:
gcc -Wall -g -c -L. soapC.c soapClient.c stdsoap2.c testMain.c
gcc -o testMain -L/usr/lib -lgsoap -lgsoapck -lgsoapssl soapC.o soapClient.o stdsoap2.o testMain.o
And I get these errors. Please help me.
stdsoap2.o: In function `soap_print_fault':
/test/stdsoap2.c:16279: undefined reference to `soap_check_faultsubcode'
/test/stdsoap2.c:16281: undefined reference to `soap_check_faultdetail'
stdsoap2.o: In function `soap_sprint_fault':
/test/stdsoap2.c:16341: undefined reference to `soap_check_faultdetail'
collect2: ld returned 1 exit status
Recent versions of GCC/ld/the GNU toolchain require that the object and library files be specified in a certain order, so that symbols can be found by the linker in the same order they depend on each other. This means that libraries should go to the end of the command line; your second line (when you're linking) should be
gcc -o testMain -L/usr/lib soapC.o soapClient.o stdsoap2.o testMain.o -lgsoap -lgsoapck -lgsoapssl
instead.
I search the web, and found a post which is very similar with my problem. I use this solution and have solved the problem. http://www.mail-archive.com/gsoap#yahoogroups.com/msg01022.html
You should not need to link stdsoap2.o to your project because it's already included in libgsoap (given through the gcc linker option -lgsoap). Try to exclude stdsoap2.c from your project. From the gSOAP FAQ:
I get a link error with gcc/g++ (GNU GCC). What should I do? For C
apps: use soapcpp2 option -c to generate C code, use only the
package's .c files, link with libgsoap.a (-lgsoap) or use the lib's
source stdsoap2.c (and dom.c when applicable).
I had the same problem with gsoap-2.8.16 compiled from source. (That version was shipped with CentOS 6.)
First I checked for a missing library. According to nm used on all static libraries provided by gsoap-2.8.16:
for X in /usr/local/lib/libgsoap*.a ; do echo $X; nm $X | grep soap_check_faultdetail; done`
it turned out that none of the libraries provided the missing symbols.
A brief look at the source code revealed that the expected return type of both methods soap_check_faultdetail and soap_check_faultsubcode was const char*, and that these were used to generate error messages.
It looked to me as if these are meant to be callbacks that the client must provide. Maybe their implementation is WSDL-dependent and would be supplied by the gsoap code generation utilities - that I don't know, see the answer from #ChristianAmmer above or below.
Anyway, since I knew the symbols were nowhere supplied, and that null-terminated strings were probably acceptable here, I just supplied my own no-op implementation:
// gsoap-missing-symbols.cpp
extern "C" {
const char* soap_check_faultdetail() { return 0; }
const char* soap_check_faultsubcode() { return 0; }
}
This is a brute-force solution. If you follow this solution, you should maybe check for linker warnings in the future; maybe some mechanism (eg. from the gsoap code generator) will supply conflicting implementations later during development.
For later versions of gsoap, I believe these symbols are no longer used and can be dropped (or renamed), see soap_check_faultX in https://www.genivia.com/changelog.html.

Trying to use the GNU Scientific Library, but weird linker errors occur

so i compiled the GSL from source with Cygwin. Everything went fine, i didnt get any errors. But when i try to compile some simple code, i get the following errors:
..\..\..\Programme\CodeBlocks\MinGW\lib\libgsl.a(error.o) In function `gsl_error':
\usr\include\gsl\err\error.c|43|undefined reference to `__getreent'
\usr\include\gsl\err\error.c|44|undefined reference to `__getreent'
\usr\include\gsl\err\error.c|45|undefined reference to `__getreent'
..\..\..\Programme\CodeBlocks\MinGW\lib\libgsl.a(stream.o) In function `gsl_stream_printf':
\usr\include\gsl\err\stream.c|37|undefined reference to `__getreent'
..\..\..\Programme\CodeBlocks\MinGW\lib\libgsl.a(stream.o) In function `gsl_set_stream':
\usr\include\gsl\err\stream.c|61|undefined reference to `__getreent'
I linked the libgsl.a and libgscblas.a libraries, and there are no complains about any other functions.
For future reference: Dont press cancel instead of Ok when you want to set up a toolchain in code::blocks
The error you're seeing is due to the fact that MinGW doesn't link the Cygwin DLL by default.
MinGW- and Cygwin-compiled libraries don't play that well with each other - while it's possible to get it to work, it's not really a good idea.
Choose one toolchain for your project, which, in this case, means either setting up Code::Blocks so it uses the Cygwin toolchain instead of the bundled MinGW distribution or compiling GSL with MinGW as well.
You may use the following option in Cygwin:
./configure CC=i686-w64-mingw32-gcc
Then you may use GSL in CodeBlocks.

Do I need an "so" file or what's wrong?

(I'm on Windows.)
I try to build pysox. Therefore I built libsox (part of SoX). It is said, that pysox needs "libsox.so and libsox.a in your link path." When building libsox I got "libsox.a", "libsox-1.dll", "libsox.dll.a", "libsox.la", "libsox.lai" and many other strange files. When I placed "libsox.a" in my link path, the previously shown error disappeared. But now the build script has an error when it calls mingw32-gcc which says:
C:\Programme\MinGW\bin\mingw32-gcc.exe -shared -s build\temp.win32-2.7\Release\pysox\sox.o build\temp.win32-2.7\Release\pysox\sox.def -LC:\Programme\Python\libs -LC:\Programme\Python\PCbuild -lsox -lpython27 -lmsvcr90 -o build\lib.win32-2.7\pysox\sox.pyd
build\temp.win32-2.7\Release\pysox\sox.o:sox.c:(.text+0x3a96): undefined reference to `sox_get_encodings_info'
build\temp.win32-2.7\Release\pysox\sox.o:sox.c:(.text+0x5035): undefined reference to `sox_get_encodings_info'
build\temp.win32-2.7\Release\pysox\sox.o:sox.c:(.text+0x795d): undefined reference to `bcopy'
build\temp.win32-2.7\Release\pysox\sox.o:sox.c:(.text+0xa8b3): undefined reference to `bcopy'
collect2: ld returned 1 exit status
error: command 'mingw32-gcc' failed with exit status 1
The following attempts didn't work:
Placing "libsox-1.dll" in link path
Renaming it to "libsox.dll"
Renaming it to "libsox.so"
Placing all files generated along with "libsox.a" in link path
Do I really need an "so" file on Windows (how do I get it)? Or what has to be changed?
MinGW uses a static interface library for each dynamic link library (DLL). The libsox.dll.a library is the one you need at link time, i.e. that needs to be copied into the link path. libsox-1.dll is required in the PATH at runtime, but not needed at link time.
You don't need a .so file on Windows platforms. It seems that some symbols are missing from the static library libsox.a, or that a library is missing from the link line. Windows platforms do not allow unresolved symbols in DLLs, contrary to UNIX-like .so platforms. You might have to give the library containing sox_get_encodings_info and friends explicitly on the command line, remembering precedence on the linker line.

Why am I getting the message "Single-stepping until exit . . . which has no line number information" in GDB?

I've compiled my C program using gcc 4.4.1 using the flag -g, but when I try to step through one of my functions in gdb version 7.0, I get the message:
"Single stepping until exit from function _DictionaryTree_getNodeList,
which has no line number information."
Can someone tell me why this is happening?
Just guessing, but is _DictionaryTree_getNodeList in another file that wasn't compiled with -g?
I had the same problem but in my case adding -g to the compiler wasn't enough so I used -ggdb as suggested by Manav.
In my case, the problem was version skew between gcc and gdb.
After landing here from search and none of these answers fit my situation, I figured out that (because of aliases / symlinks / Makefile / environment variables) I was accidentally using a newer GCC (4.8.x) and an older GDB (7.2). Stepping up to a newer version of GDB (7.8) fixed the problem. For some reason, using a newer GCC and older GDB didn't work.
I had this error message too but the source of my problem was different. If anyone is still having any problems, make sure you have #include <stdio.h> in your file, with the the appropriate brackets around stdio.h (the text message would not show up if I had it around stdio.h).
I had the same issue, when I compiled a file using -g option and without -g option.
For one of the file, the gdb showed line number without any issues(even when it was compiled without -g option)..
And for the other file, I had to explicitly mention -g flag...
Any ideas as to whether the source file could be loaded at run time in
GDB with cross referencing would be good solution... by mapping the
lines to the addresses :D.
I had this issue because I was debugging a shared library without pointing LD_LIBRARY_PATH to correct location with debug endstates.
you can use
export LD_LIBRARY_PATH=<location of the debug build of the .so file>:$LD_LIBRARY_PATH
Hopefully this is helpful to someone
I had the same trouble despite I was already compiling with -g2. Changing it to -g3 did the trick.
Im using GBD 12 , im not able to use any of these flags and options , also im debugging .exe file , so yes I used makefile

Resources