Search code examples
gccblasumfpack

Error in Compiling a sample file using UMFPACK


I want to compile a very umfpack_simple.c from Demos of UMFPACK but I'm getting following error:

[root@localhost Test]# gcc -I../UMFPACK/Include -I../AMD/Include -

I../SuiteSparse_config -I../GotoBLAS2 umfpack_simple.c libumfpack.a libamd.a libgoto2.a libsuitesparseconfig.a libgoto2_nehalem-ra.13.a -lrt
gcc: error: libgoto2_nehalem-ra.13.a: No such file or directory
[root@localhost Test]# ls
libamd.a    libgoto2_nehalem-r1.13.a  libumfpack.a
libgoto2.a  libsuitesparseconfig.a    umfpack_simple.c
[root@localhost Test]# gcc -I../UMFPACK/Include -I../AMD/Include -I../SuiteSparse_config -I../GotoBLAS2 umfpack_simple.c libumfpack.a libamd.a libgoto2.a libsuitesparseconfig.a libgoto2_nehalem-r1.13.a -lrt
libumfpack.a(umf_di_mem_alloc_element.o): In function `umfdi_mem_alloc_element':
umf_mem_alloc_element.c:(.text+0x88): undefined reference to `ceil'
umf_mem_alloc_element.c:(.text+0xb6): undefined reference to `ceil'
libumfpack.a(umf_di_set_stats.o): In function `umf_i_set_stats':
umf_set_stats.c:(.text+0x151): undefined reference to `ceil'
umf_set_stats.c:(.text+0x185): undefined reference to `ceil'
umf_set_stats.c:(.text+0x1ae): undefined reference to `ceil'
libumfpack.a(umf_di_set_stats.o):umf_set_stats.c:(.text+0x207): more undefined references to `ceil' follow
libumfpack.a(umf_di_start_front.o): In function `umfdi_start_front':
umf_start_front.c:(.text+0x397): undefined reference to `sqrt'
umf_start_front.c:(.text+0x3b5): undefined reference to `sqrt'
libumfpack.a(umfpack_di_qsymbolic.o): In function `symbolic_analysis':
umfpack_qsymbolic.c:(.text+0x715): undefined reference to `ceil'
umfpack_qsymbolic.c:(.text+0x745): undefined reference to `ceil'
umfpack_qsymbolic.c:(.text+0x76d): undefined reference to `ceil'
umfpack_qsymbolic.c:(.text+0x79e): undefined reference to `ceil'
umfpack_qsymbolic.c:(.text+0x7d8): undefined reference to `ceil'
libumfpack.a(umfpack_di_qsymbolic.o):umfpack_qsymbolic.c:(.text+0x803): more undefined references to `ceil' follow
libumfpack.a(umfpack_di_qsymbolic.o): In function `symbolic_analysis':
umfpack_qsymbolic.c:(.text+0x4e23): undefined reference to `sqrt'
umfpack_qsymbolic.c:(.text+0x4fb4): undefined reference to `sqrt'
libumfpack.a(umf_i_colamd.o): In function `umf_i_colamd':
umf_colamd.c:(.text+0x1a82): undefined reference to `sqrt'
umf_colamd.c:(.text+0x1ab8): undefined reference to `sqrt'
umf_colamd.c:(.text+0x1aec): undefined reference to `sqrt'
libumfpack.a(umf_i_colamd.o):umf_colamd.c:(.text+0x1b15): more undefined references to `sqrt' follow
collect2: error: ld returned 1 exit status

As can be seen, I've missed some library which defines ceil and sqrt. I am using GotoBLAS2 along with UMFPACK. Please let me know where the problem is. Thanks


Solution

  • Functions like ceil and sqrt are in libmath

    All you need is -lm in your compilation string. So try:

    gcc -I../UMFPACK/Include -I../AMD/Include -I../SuiteSparse_config -I../GotoBLAS2 umfpack_simple.c libumfpack.a libamd.a libgoto2.a libsuitesparseconfig.a libgoto2_nehalem-r1.13.a -lm -lrt

    Also I want note, that you may use -L option to specify library search paths.

    UPD: answering your question in comment, no, you can not specify "default" libmath (unless you aren't editing compiler backend, where you can do it in LINK_SPECS)

    But even if you are editing backend, default libmath is bad idea, because order of libraries in command line matters. If your .c file uses library, it must be specified in command line after this file, and similar applies to interlibrary dependencies. So it not only plays role whether you specified libmath or not, it also matters where in the command line did it appear.