我正在尝试从英特尔MKL库(/opt/intel/mkl/examples/versionqueryc/
)编译示例程序。我将源代码(C文件)复制到一个新目录。然后我去尝试用CMake构建这个例子。
在调试过程中,我在尝试使用以下命令时遇到困难(现在与cmake隔离)。
它找不到数学库,但链接中包含-lm
。那是怎么回事?
:~/devel/mkl/MKL Test/build$ /usr/bin/gcc -m64 CMakeFiles/mkltest.dir/main.c.o \
> -o mkltest -rdynamic -L/home/myuser/src/intel/mkl/lib/intel64 \
> -lm -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lmkl_cdft_core \
> -lmkl_scalapack_lp64 \
> /home/myuser/src/intel/lib/intel64/libiomp5.so \
> -Wl,-rpath,/home/myuser/src/intel/mkl/lib/intel64:/home/myuser/src/intel/lib/intel64
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `logf'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `atan2'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `sin'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `fabs'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `exp'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `sqrtf'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `cos'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `sqrt'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_sequential.so: undefined reference to `log'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `pow'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `log10'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `ceil'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `expf'
collect2: ld returned 1 exit status
答案 0 :(得分:9)
将-lm
作为最后一个参数,链接时参数的顺序很重要。