How To Resolve Undefined Reference To Symbol Library Linking Problem Linux C | C++

What is Undefined Reference Error

while compiling any source code it may written in c(.c) or c++(.cpp).it needs to use the system existing library function,symbol,exten variable. when it is unable to find this obejct we were getting is undefined reference symbol error
Example after compile while make some open source I got below undefine reference to symbol error
$ make ex4
/app/intel/impi/ -o ex4 ex4.o -g -Wall -L/app/hypre-2.9.0b/lib -lHYPRE -lm -lstdc++
point_relax.c:(.text+0x94f): undefined reference to `__svml_idiv4'
struct_vector.c:(.text+0x2ee4): undefined reference to `_intel_fast_memset'
/app/hypre-2.9.0b/lib/libHYPRE.a(mpistubs.o): In function `hypre_MPI_Group_incl':
mpistubs.c:(.text+0x144): undefined reference to `__intel_ssse3_rep_memcpy'
coarsen.c:(.text+0x39b): undefined reference to `__svml_idiv4'
coarsen.c:(.text+0x470): undefined reference to `__svml_idiv4'
/(.text+0x2ef0): more undefined references to `__intel_ssse3_rep_memcpy' follow
collect2: ld returned 1 exit status
make: *** [ex4] Error 1

$ icc -Wl,-yompi_mpi_int
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
[roddam@login1 sample_jet]$ icc -Wl,-yompi_mpi_comm_world

How To Resolve these undefined symbol Problem.
coarsen.c:(.text+0x39b): undefined reference to `__svml_idiv4'
coarsen.c:(.text+0x470): undefined reference to `__svml_idiv4'

How To resolve Undefined Reference Error in C and C++

For this first we need to identify where is required object is located.

How To Find Which Library Has the Request Symbol | Function

1)# nm /app/intel/composer_xe_2013.1.117/compiler/lib/intel64/ | grep __svml_idiv4
How can we identify "__svml_idiv4" symbol located at the which library.
in another way how can we search this symbol located at which library.
using grep command find symbol located at which library.
# grep -r -w __svml_idiv4 /app/intel/composer_xe_2013.1.117
Binary file /app/intel/composer_xe_2013.1.117/compiler/lib/intel64/ matches
Binary file /app/intel/composer_xe_2013.1.117/compiler/lib/intel64/libsvml.a matches
NOTE: symbol should matches with .so dynamic library.

2)Once find then verify with gcc compiler is able to FIND the symbol.
gcc -L/app/intel/composer_xe_2013.1.117/compiler/lib/intel64 -lsvml
Through that we can confirm __svml_idiv4 is cleared in the above method.

After that configure into the LFLAGS.
LFLAGS = $(LINKOPTS) $(LIBS) -lstdc++ -lirc -lsvml
#$ make ex4
/app/intel/impi/ -o ex4 ex4.o -g -Wall -L/app/hypre-2.9.0b/lib -lHYPRE -lm -lstdc++ -lirc -lsvml


1)grep -r -w "_intel_fast_memcpy" /app/* 2>&1 | tee /tmp/grep-nm.log
2)cat /tmp/grep-nm.log | awk '{print "nm -A "$3"| grep  '"'T _intel_fast_memcpy'"'"}' | sh
# nm /app/intel/composer_xe_2013.1.117/compiler/lib/ia32/irml/ | grep intel_fast_memcpy
0000bb10 t _intel_fast_memcpy
0000bab0 t _intel_fast_memcpy.A
0000baf0 t _intel_fast_memcpy.H
0000bad0 t _intel_fast_memcpy.J
# nm /app/intel/composer_xe_2013.1.117/compiler/lib/ia32/ | grep intel_fast_memcpy
0000eb70 T _intel_fast_memcpy
0000ea80 T _intel_fast_memcpy.A
0000eb40 T _intel_fast_memcpy.H
0000eab0 T _intel_fast_memcpy.J
0000eae0 T _intel_fast_memcpy.M
0000eb10 T _intel_fast_memcpy.P/app/intel/composer_xe_2013.1.117/compiler/lib/ia32/
-t Local Text Symbol.
-T Global Text Symbol.
We have to use the Global Text Symbol library.Then only the undefined reference problem will be solved.
#gcc -L/app/intel/composer_xe_2013.1.117/compiler/lib/ia32/ -lintlc

NOTE: If the processor is intel then if we are using intel compiler then it will give good performance.
Intel Compiler Flags

Increase the performance 30 % Using Intel Compiler for hypre Application.
#icc -O2 -xavx.
-O2 (Maxmize Speed)

What is Compiling?

Computer Program written in Source code convert from high-level programming language into low-level language(assemble language,object code or machine code) to generate binary executable program.

Post a Comment