Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
7782 Discussions

Error while using -static and -L/usr/lib/x86_64-redhat-linux5E/lib64/ on Linux x64 platform

lee_icc
Beginner
439 Views

Dear All,

I tried to compile my C code using Eclipse with Intel C/C++ compiler 13.1.1 on scientific linux 6.4 x64 platform. When linked dynamically, it was successful with no error or warnings. When linked with -static and -L/usr/lib/x86_64-redhat-linux5E/lib64/, it reported many error about undefined reference shown as follows:

make -k all
Building file: ../src/mcmc_demo.c
Invoking: Intel Intel(R) 64 C Compiler
icc -O3 -ip -mkl=parallel -openmp -MMD -MP -MF"src/mcmc_demo.d" -MT"src/mcmc_demo.d" -c -o "src/mcmc_demo.o" "../src/mcmc_demo.c"
Finished building: ../src/mcmc_demo.c
 
Building target: mcmc_demo
Invoking: Intel Intel(R) 64 C Linker
icc -static -openmp -mkl=parallel -O3 -L/usr/lib/x86_64-redhat-linux5E/lib64/ -o "mcmc_demo"  ./src/mcmc_demo.o   
./src/mcmc_demo.o: In function `main':
../src/mcmc_demo.c:(.text+0x71): undefined reference to `__isoc99_fscanf'
../src/mcmc_demo.c:(.text+0x100): undefined reference to `__isoc99_fscanf'
../src/mcmc_demo.c:(.text+0x174): undefined reference to `__isoc99_fscanf'
../src/mcmc_demo.c:(.text+0x230): undefined reference to `__isoc99_fscanf'
../src/mcmc_demo.c:(.text+0x43a): undefined reference to `__isoc99_fscanf'
../src/mcmc_demo.c:(.text+0x5ed): undefined reference to `vdLn'
../src/mcmc_demo.c:(.text+0xd00): undefined reference to `vslNewStream'
../src/mcmc_demo.c:(.text+0xd28): undefined reference to `vdRngUniform'
../src/mcmc_demo.c:(.text+0xd42): undefined reference to `vdLn'
../src/mcmc_demo.c:(.text+0xe15): undefined reference to `vdRngGaussian'
../src/mcmc_demo.c:(.text+0xeac): undefined reference to `vdLn'
../src/mcmc_demo.c:(.text+0x1561): undefined reference to `cblas_dcopy'
../src/mcmc_demo.c:(.text+0x159f): undefined reference to `cblas_dcopy'
../src/mcmc_demo.c:(.text+0x1607): undefined reference to `cblas_dcopy'
../src/mcmc_demo.c:(.text+0x1645): undefined reference to `cblas_dcopy'
../src/mcmc_demo.c:(.text+0x16b1): undefined reference to `cblas_dcopy'
../src/mcmc_demo.c:(.text+0x175f): undefined reference to `vslDeleteStream'
./src/mcmc_demo.o: In function `asm2d':
../src/mcmc_demo.c:(.text+0x8184): undefined reference to `cblas_dgemv'
./src/mcmc_demo.o: In function `logpriorfun':
../src/mcmc_demo.c:(.text+0x81c3): undefined reference to `vdLn'
./src/mcmc_demo.o: In function `proprnd':
../src/mcmc_demo.c:(.text+0x8470): undefined reference to `vdRngGaussian'
make: *** [mcmc_demo] Error 1
make: Target `all' not remade because of errors.

Does anyone have idea that how to resolve this issue? Thanks in advance.

Lee

0 Kudos
8 Replies
SergeyKostrov
Valued Contributor II
439 Views
>>... >>../src/mcmc_demo.c:(.text+0x5ed): undefined reference to `vdLn' >>../src/mcmc_demo.c:(.text+0xd00): undefined reference to `vslNewStream' >>../src/mcmc_demo.c:(.text+0xd28): undefined reference to `vdRngUniform' >>../src/mcmc_demo.c:(.text+0xd42): undefined reference to `vdLn' >>../src/mcmc_demo.c:(.text+0xe15): undefined reference to `vdRngGaussian' >>../src/mcmc_demo.c:(.text+0xeac): undefined reference to `vdLn' >>../src/mcmc_demo.c:(.text+0x1561): undefined reference to `cblas_dcopy' >>../src/mcmc_demo.c:(.text+0x159f): undefined reference to `cblas_dcopy' >>../src/mcmc_demo.c:(.text+0x1607): undefined reference to `cblas_dcopy' >>../src/mcmc_demo.c:(.text+0x1645): undefined reference to `cblas_dcopy' >>../src/mcmc_demo.c:(.text+0x16b1): undefined reference to `cblas_dcopy' >>../src/mcmc_demo.c:(.text+0x175f): undefined reference to `vslDeleteStream' >>... These are MKL functions and please verify that in that case a right path to MKL libraries is used.
lee_icc
Beginner
439 Views

Yes, the path to MKL libraries is correct. When linked dynamically (without -static or -static-intel option), it was OK with no error or warnings. These error were only reported while linking statically.

SergeyKostrov
Valued Contributor II
439 Views
>>...icc -static -openmp -mkl=parallel -O3 -L/usr/lib/x86_64-redhat-linux5E/lib64/ -o "mcmc_demo" ./src/mcmc_demo.o There is a difference between 1st command line and the 2nd ( I marked a path to some folder with 64-bit libraries ). Why don't you use that path in the 1st case? Or, why do you use the path in the 2nd case?
lee_icc
Beginner
439 Views

The log shown in my previous post was copied from the Eclipse console output. I also tested it in command line:

[sl@localhost test]$ icc -O3 -ip -mkl=parallel -openmp -static mcmc_demo.c
ld: cannot find -lm

Following the webpage http://software.intel.com/en-us/forums/topic/277227 and http://software.intel.com/en-us/articles/error-ld-cannot-find-lm/, I tested the new compile options:

[sl@localhost test]$ icc -O3 -ip -mkl=parallel -openmp -static mcmc_demo.c -L/usr/lib/x86_64-redhat-linux5E/lib64/
/tmp/iccondg4F.o: In function `main':
mcmc_demo.c:(.text+0x71): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x100): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x174): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x230): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x43a): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x5ed): undefined reference to `vdLn'
mcmc_demo.c:(.text+0xd00): undefined reference to `vslNewStream'
mcmc_demo.c:(.text+0xd28): undefined reference to `vdRngUniform'
mcmc_demo.c:(.text+0xd42): undefined reference to `vdLn'
mcmc_demo.c:(.text+0xe15): undefined reference to `vdRngGaussian'
mcmc_demo.c:(.text+0xeac): undefined reference to `vdLn'
mcmc_demo.c:(.text+0x1561): undefined reference to `cblas_dcopy'
mcmc_demo.c:(.text+0x159f): undefined reference to `cblas_dcopy'
mcmc_demo.c:(.text+0x1607): undefined reference to `cblas_dcopy'
mcmc_demo.c:(.text+0x1645): undefined reference to `cblas_dcopy'
mcmc_demo.c:(.text+0x16b1): undefined reference to `cblas_dcopy'
mcmc_demo.c:(.text+0x175f): undefined reference to `vslDeleteStream'
/tmp/iccondg4F.o: In function `asm2d':
mcmc_demo.c:(.text+0x8184): undefined reference to `cblas_dgemv'
/tmp/iccondg4F.o: In function `logpriorfun':
mcmc_demo.c:(.text+0x81c3): undefined reference to `vdLn'
/tmp/iccondg4F.o: In function `proprnd':
mcmc_demo.c:(.text+0x8470): undefined reference to `vdRngGaussian'

When using 'icc -O3 -ip -mkl=parallel -openmp mcmc_demo.c', it works fine and built the executalbe 'a.out' without any error. It seem that the issue is related to the function 'fscanf' and static linking to MKL.

SergeyKostrov
Valued Contributor II
439 Views
>>...mcmc_demo.c:(.text+0x71): undefined reference to `__isoc99_fscanf' Could you try to enable support for C99 language standard?
lee_icc
Beginner
439 Views

Enabling C99 support with the option -std=c99 did not help to resolve the '__isoc99_fscanf' error:

[sl@localhost test]$ icc -O3 -ip -std=c99 -mkl=parallel -openmp -static mcmc_demo.c -L/usr/lib/x86_64-redhat-linux5E/lib64/
/tmp/icct1sV8V.o: In function `main':
mcmc_demo.c:(.text+0x71): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x100): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x174): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x230): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x43a): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x5ed): undefined reference to `vdLn'
...

Following the advice by Ying (http://software.intel.com/en-us/comment/1740145#comment-1740145), explictly linking MKL resolved the error 'undefined reference' to MKL functions.

After several test, I also found that using the option '-L/usr/lib/x86_64-redhat-linux5E/lib64/' leads to undefined reference to `__isoc99_fscanf'. Without this option, it reported 'ld: cannot find -lpthread' instead. Detailed logs are as follows:

[sl@localhost test]$ icc -O3 -ip -openmp -static mcmc_demo.c -Wl,--start-group $MKLROOT/lib/intel64/libmkl_intel_lp64.a $MKLROOT/lib/intel64/libmkl_intel_thread.a $MKLROOT/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm
ld: cannot find -lpthread

[sl@localhost test]$ icc -O3 -ip -openmp -static mcmc_demo.c -L/usr/lib/x86_64-redhat-linux5E/lib64/ -Wl,--start-group $MKLROOT/lib/intel64/libmkl_intel_lp64.a $MKLROOT/lib/intel64/libmkl_intel_thread.a $MKLROOT/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm
/tmp/iccZTzhHD.o: In function `main':
mcmc_demo.c:(.text+0x71): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x100): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x174): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x230): undefined reference to `__isoc99_fscanf'
mcmc_demo.c:(.text+0x43a): undefined reference to `__isoc99_fscanf'

SergeyKostrov
Valued Contributor II
439 Views
I see that there are two similar threads and another one is: Forum Topic: Error in static linking to MKL on Linux x64 platform Web-link: http://software.intel.com/en-us/forums/topic/393920
lee_icc
Beginner
439 Views

Yes, I also reported the issue to MKL forum to resolve the issue on static linking MKL. I am sorry for my duplicate posts. Thank you very much for your help, Sergey.

Reply