C++链接xMath出错



  • 老师好:
    我已经看到了有关于xMath出错的讨论。

    我也想用链接xMath和我的C++程序,但是使用上述链接的办法不能正常使用。

    尝试1

    命令

    sw5cc -hybrid -o test_xMath main.o cg.o spmv.o SunwayAthread.o -L ${xMath_path} -lxMath -lstdc++
    

    报错

    /usr/sw-mpp/swcc/sw5gcc-binary/lib/libxMath.a(dcg_check.o): In function `dcg_check':/home/export/online1/systest/swzky/ABC123/xMath_manycore_v1.0/src/sparse_manycore/dcg_check.f:18: undefined reference to `_OPEN'
    :/home/export/online1/systest/swzky/ABC123/xMath_manycore_v1.0/src/sparse_manycore/dcg_check.f:18: undefined reference to `_OPEN'
    :/home/export/online1/systest/swzky/ABC123/xMath_manycore_v1.0/src/sparse_manycore/dcg_check.f:37: undefined reference to `_FWF'
    :/home/export/online1/systest/swzky/ABC123/xMath_manycore_v1.0/src/sparse_manycore/dcg_check.f:37: undefined reference to `_FWF'
    :/home/export/online1/systest/swzky/ABC123/xMath_manycore_v1.0/src/sparse_manycore/dcg_check.f:40: undefined reference to `_FWF'
    :/home/export/online1/systest/swzky/ABC123/xMath_manycore_v1.0/src/sparse_manycore/dcg_check.f:40: undefined reference to `_FWF'
    :/home/export/online1/systest/swzky/ABC123/xMath_manycore_v1.0/src/sparse_manycore/dcg_check.f:41: undefined reference to `_FWF'
    /usr/sw-mpp/swcc/sw5gcc-binary/lib/libxMath.a(dcg_check.o):/home/export/online1/systest/swzky/ABC123/xMath_manycore_v1.0/src/sparse_manycore/dcg_check.f:41: more undefined references to `_FWF' follow
    collect2: ld returned 1 exit status
    

    尝试2

    命令

    sw5cc -hybrid -o test_xMath main.o cg.o spmv.o SunwayAthread.o -L ${xMath_path} -lxMath -lstdc++ -lffio -lfortran
    

    报错

    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(opn.o): In function `findmatch': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(opn.o): In function `findmatch': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(opn.o): In function `__OPN': undefined reference to `__io_byteswap'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(opn.o): In function `__OPN': undefined reference to `__io_byteswap'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wf90.o): In function `_FWF': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wf90.o): In function `_FWF': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wf90.o): In function `_FWF': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wf90.o): In function `_FWF': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): more undefined references to `_unpack' follow
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(ferror.o): In function `_ferr': undefined reference to `_lmessage'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(ferror.o): In function `_ferr': undefined reference to `_lmessage'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(getdcparam.o): In function `_get_dc_param': undefined reference to `__fndc_ncfunc'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(getdcparam.o): In function `_get_dc_param': undefined reference to `__fndc_f77sz'
    ...
    

    尝试3

    命令

    sw5CC -hybrid -o test_xMath main.o cg.o spmv.o SunwayAthread.o -L ${xMath_path} -lxMath -lstdc++ -lffio -lfortran
    

    报错

    CC ERROR: cannot exec /usr/sw-mpp/swcc/sw5gcc-binary/bin/sw5g++: No such file or directory
    

    尝试4

    命令:

    mpiCC -hybrid -o test_xMath main.o cg.o spmv.o SunwayAthread.o -L ${xMath_path} -lxMath -lstdc++ -lffio -lfortran
    

    报错:

    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(opn.o): In function `findmatch': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(opn.o): In function `findmatch': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(opn.o): In function `__OPN': undefined reference to `__io_byteswap'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(opn.o): In function `__OPN': undefined reference to `__io_byteswap'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wf90.o): In function `_FWF': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wf90.o): In function `_FWF': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wf90.o): In function `_FWF': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wf90.o): In function `_FWF': undefined reference to `_string_cmp'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    /usr/sw-mpp/swcc/lib/gcc-lib/sw_64-swcc-linux/5.421-sw-500/lib/libfortran.a(wrfmt.o): In function `_wrfmt': undefined reference to `_unpack'
    ...
    

    请问老师有什么好的建议嘛?谢谢!



  • 之前代码中,我指定了xMath的路径寻找路径,从而导致了上述错误。正确的使用xMath应该让系统自己寻找合适的xMath库。

    经过超算中心老师的指导,我把提交程序修改为

    # prepare
    clear
    rm *.o
    rm test_xMath
    
    # compile master core program
    sw5cc -host -c cg.c
    sw5cc -host -c spmv.c
    sw5cc -host -c cg.c
    sw5cc -host -c SunwayAthread.c
    sw5CC -host -c main.cpp
    
    # link
    # xMath path should not be assigned, should automatically find by system
    mpic++ -hybrid -o test_xMath main.o cg.o spmv.o SunwayAthread.o -lxMath_manycore -lfortran -lffio
    
    # submit
    bsub -I -b -N 1 -q q_sw_expr -cgsp 64 ./test_xMath
    

    就可以解决问题。



  • 请问一下代码中是怎么调用xMath的呢?使用了头文件或者extern的么,我一直遇到undefined reference to `dgemm_(char*, char*, int*, int*, int*, double*, double*, int*, double*, int*, double*, double*, int*)'的问题,所以想请教一下



  • 你这个很可能是因为在链接的时候没有加上xMath库?



  • 加上-lfortran -lffio


登录后回复