title: Building Armadillo linear algebra library, failing to link with SuperLU on Ubuntu 14.04.3 LTS. X cannot be used when making a shared object
body: <p>I am trying to install the latest version of Armadillo (6.500.5) <a href="http://arma.sourceforge.net/" rel="nofollow">http://arma.sourceforge.net/</a> on Ubuntu 14.04.3 LTS.</p>
  
  <p>I require the ability to solve sparse linear systems, so as per the instructions I need SuperLU version 4.3 installed. I installed SuperLU 4.3, but when trying to build Armadillo I receive the following error</p>
  
  <blockquote>
    <p>Scanning dependencies of target armadillo</p>
    
    <p>[100%] Building CXX object CMakeFiles/armadillo.dir/src/wrapper.cpp.o
    Linking CXX shared library libarmadillo.so</p>
    
    <p>/usr/bin/ld: /usr/lib/SuperLU_4.3/lib/libsuperlu_4.3.a(sgssv.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC</p>
    
    <p>/usr/lib/SuperLU_4.3/lib/libsuperlu_4.3.a: error adding symbols: Bad value</p>
    
    <p>clang: error: linker command failed with exit code 1 (use -v to see invocation)</p>
    
    <p>make[2]: *** [libarmadillo.so.6.500.5] Error 1</p>
    
    <p>make[1]: *** [CMakeFiles/armadillo.dir/all] Error 2</p>
    
    <p>make: *** [all] Error 2</p>
  </blockquote>
  
  <p>So I added the -fPIC flag to the SuperLU makefile and recompiled SuperLU, but then get a very slightly different error</p>
  
  <blockquote>
    <p>Linking CXX shared library libarmadillo.so</p>
    
    <p>/usr/bin/ld: /usr/lib/SuperLU_4.3/lib/libsuperlu_4.3.a(superlu_timer.o): relocation R_X86_64_PC32 against undefined symbol `sysconf@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC</p>
    
    <p>/usr/bin/ld: final link failed: Bad value</p>
    
    <p>clang: error: linker command failed with exit code 1 (use -v to see invocation)</p>
    
    <p>make[2]: *** [libarmadillo.so.6.500.5] Error 1</p>
    
    <p>make[1]: *** [CMakeFiles/armadillo.dir/all] Error 2</p>
    
    <p>make: *** [all] Error 2</p>
  </blockquote>
  
  <p>I am not sure where to go from here. It seems that Armadillo expects to find SuperLU in a shared library format, wheras SuperLU installs itself as a static library. The version of Armdillo available in the package manager seems to be too out of date and does not have the features that I need.</p>
  
  <p>Here are some of the Makefiles</p>
  
  <p><strong>Top Level Makefile for SuperLU</strong></p>
  
  <pre><code>############################################################################
  #
  #  Program:         SuperLU
  #
  #  Module:          Makefile
  #
  #  Purpose:         Top-level Makefile
  #
  #  Creation date:   October 2, 1995
  #
  #  Modified:        February 4,  1997  Version 1.0
  #           November 15, 1997  Version 1.1
  #           September 1, 1999  Version 2.0
  #           October 15,  2003  Version 3.0
  #           August 1,    2008  Version 3.1
  #
  ############################################################################
  
  include make.inc
  
  all: install lib testing
  
  lib: superlulib tmglib
  
  clean: cleanlib cleantesting
  
  install:
      ( cd INSTALL; $(MAKE) )
  #   ( cd INSTALL; cp lsame.c ../SRC/; \
  #     cp dlamch.c ../SRC/; cp slamch.c ../SRC/ )
  
  blaslib:
      ( cd CBLAS; $(MAKE) )
  
  superlulib:
      ( cd SRC; $(MAKE) )
  
  tmglib:
      ( cd TESTING/MATGEN; $(MAKE) )
  
  matlabmex:
      ( cd MATLAB; $(MAKE) )
  
  testing:
      ( cd TESTING ; $(MAKE) )
  
  doc:
      doxygen Doxyfile
  
  cleanlib:
      ( cd SRC; $(MAKE) clean )
      ( cd TESTING/MATGEN; $(MAKE) clean )
      ( cd CBLAS; $(MAKE) clean )
  
  cleantesting:
      ( cd INSTALL; $(MAKE) clean )
      ( cd TESTING; $(MAKE) clean )
      ( cd MATLAB;  $(MAKE) clean )
      ( cd EXAMPLE; $(MAKE) clean )
      ( cd FORTRAN; $(MAKE) clean )
  </code></pre>
  
  <p><strong>make.inc in SuperLU</strong></p>
  
  <pre><code>############################################################################
  #
  #  Program:         SuperLU
  #
  #  Module:          make.inc
  #
  #  Purpose:         Top-level Definitions
  #
  #  Creation date:   October 2, 1995
  #
  #  Modified:        February 4, 1997  Version 1.0
  #           November 15, 1997 Version 1.1
  #           September 1, 1999 Version 2.0
  #
  ############################################################################
  #
  #  The machine (platform) identifier to append to the library names
  #
  PLAT = _linux
  
  #
  #  The name of the libraries to be created/linked to
  #
  SuperLUroot = /usr/lib/SuperLU_4.3
  SUPERLULIB      = $(SuperLUroot)/lib/libsuperlu_4.3.a
  
  #BLASLIB    = $(SuperLUroot)/lib/libblas.a
  
  ## ATLAS BLAS causes single-precision to fail
  #BLASDEF = -DUSE_VENDOR_BLAS
  #BLASLIB = /usr/lib/libopenblas.a
  
  ## This BLAS causes single-precision to fail the test in SuperLU
  # BLASDEF   = -DUSE_VENDOR_BLAS
  BLASLIB = ../lib/blas$(PLAT).a
  
  TMGLIB          = libtmglib.a
  LIBS        = $(SUPERLULIB) $(BLASLIB)
  
  #
  #  The archiver and the flag(s) to use when building archive (library)
  #  If your system has no ranlib, set RANLIB = echo.
  #
  ARCH         = ar
  ARCHFLAGS    = cr
  RANLIB       = ranlib
  
  CC           = gcc
  CFLAGS       = -O3 -fPIC
  NOOPTS       = 
  FORTRAN      = g77
  FFLAGS       = -O2 -fPIC
  LOADER       = $(CC)
  LOADOPTS     = -fPIC
  
  #
  #  C preprocessor defs for compilation for the Fortran interface
  #  (-DNoChange, -DAdd_, -DAdd__, or -DUpCase)
  #
  CDEFS        = -DAdd_
  #
  # The directory in which Matlab is installed
  #
  MATLAB       = /usr/local/MATLAB/R2015b
  </code></pre>
  
  <p><strong>SRC/Makefile in SuperLU</strong></p>
  
  <pre><code># makefile for sparse supernodal LU, implemented in ANSI C
  include ../make.inc
  
  #######################################################################
  #  This is the makefile to create a library for SuperLU.
  #  The files are organized as follows:
  #
  #       ALLAUX -- Auxiliary routines called from all precisions of SuperLU
  #   LAAUX  -- LAPACK auxiliary routines called from all precisions
  #   SLASRC -- LAPACK single precision real routines
  #   DLASRC -- LAPACK double precision real routines
  #   CLASRC -- LAPACK single precision complex routines
  #   ZLASRC -- LAPACK double precision complex routines
  #       SCLAUX -- LAPACK Auxiliary routines called from both real and complex
  #       DZLAUX -- LAPACK Auxiliary routines called from both double precision
  #                 and complex*16
  #   SLUSRC -- Single precision real SuperLU routines
  #       DLUSRC -- Double precision real SuperLU routines
  #   CLUSRC -- Single precision complex SuperLU routines
  #       ZLUSRC -- Double precision complex SuperLU routines
  #
  #  The library can be set up to include routines for any combination
  #  of the four precisions.  To create or add to the library, enter make
  #  followed by one or more of the precisions desired.  Some examples:
  #       make single
  #       make single double
  #       make single double complex complex16
  #  Alternatively, the command
  #       make
  #  without any arguments creates a library of all four precisions.
  #  The library is called
  #       superlu.a
  #  and is created at the next higher directory level.
  #
  #  To remove the object files after the library is created, enter
  #       make clean
  #
  #######################################################################
  
  ### LAPACK 
  LAAUX   = lsame.o xerbla.o
  SLASRC  = slacon.o 
  DLASRC  = dlacon.o
  CLASRC  = clacon.o scsum1.o icmax1.o
  ZLASRC  = zlacon.o dzsum1.o izmax1.o
  SCLAUX  = slamch.o
  DZLAUX  = dlamch.o
  
  ### SuperLU 
  ALLAUX  = superlu_timer.o util.o memory.o get_perm_c.o mmd.o \
        sp_coletree.o sp_preorder.o sp_ienv.o relax_snode.o \
        heap_relax_snode.o colamd.o \
        ilu_relax_snode.o ilu_heap_relax_snode.o mark_relax.o \
        mc64ad.o qselect.o
  
  SLUSRC = \
      sgssv.o sgssvx.o \
      ssp_blas2.o ssp_blas3.o sgscon.o  \
      slangs.o sgsequ.o slaqgs.o spivotgrowth.o \
      sgsrfs.o sgstrf.o sgstrs.o scopy_to_ucol.o \
      ssnode_dfs.o ssnode_bmod.o \
      spanel_dfs.o spanel_bmod.o \
      sreadhb.o sreadrb.o sreadtriple.o \
      scolumn_dfs.o scolumn_bmod.o spivotL.o spruneL.o \
      smemory.o sutil.o smyblas2.o \
      sgsisx.o sgsitrf.o sldperm.o \
      ilu_sdrop_row.o ilu_ssnode_dfs.o \
      ilu_scolumn_dfs.o ilu_spanel_dfs.o ilu_scopy_to_ucol.o \
      ilu_spivotL.o sdiagonal.o
  
  DLUSRC = \
      dgssv.o dgssvx.o \
      dsp_blas2.o dsp_blas3.o dgscon.o \
      dlangs.o dgsequ.o dlaqgs.o dpivotgrowth.o  \
      dgsrfs.o dgstrf.o dgstrs.o dcopy_to_ucol.o \
      dsnode_dfs.o dsnode_bmod.o dpanel_dfs.o dpanel_bmod.o \
      dreadhb.o dreadrb.o dreadtriple.o \
      dcolumn_dfs.o dcolumn_bmod.o dpivotL.o dpruneL.o \
      dmemory.o dutil.o dmyblas2.o \
      dgsisx.o dgsitrf.o dldperm.o \
      ilu_ddrop_row.o ilu_dsnode_dfs.o \
      ilu_dcolumn_dfs.o ilu_dpanel_dfs.o ilu_dcopy_to_ucol.o \
      ilu_dpivotL.o ddiagonal.o 
          ## dgstrsL.o dgstrsU.o
  
  CLUSRC = \
      scomplex.o cgssv.o cgssvx.o csp_blas2.o csp_blas3.o cgscon.o \
      clangs.o cgsequ.o claqgs.o cpivotgrowth.o  \
      cgsrfs.o cgstrf.o cgstrs.o ccopy_to_ucol.o \
      csnode_dfs.o csnode_bmod.o \
      cpanel_dfs.o cpanel_bmod.o \
      creadhb.o creadrb.o creadtriple.o \
      ccolumn_dfs.o ccolumn_bmod.o cpivotL.o cpruneL.o \
      cmemory.o cutil.o cmyblas2.o \
      cgsisx.o cgsitrf.o cldperm.o \
      ilu_cdrop_row.o ilu_csnode_dfs.o \
      ilu_ccolumn_dfs.o ilu_cpanel_dfs.o ilu_ccopy_to_ucol.o \
      ilu_cpivotL.o cdiagonal.o
  
  ZLUSRC = \
      dcomplex.o zgssv.o zgssvx.o zsp_blas2.o zsp_blas3.o zgscon.o \
      zlangs.o zgsequ.o zlaqgs.o zpivotgrowth.o  \
      zgsrfs.o zgstrf.o zgstrs.o zcopy_to_ucol.o \
      zsnode_dfs.o zsnode_bmod.o \
      zpanel_dfs.o zpanel_bmod.o \
      zreadhb.o zreadrb.o zreadtriple.o \
      zcolumn_dfs.o zcolumn_bmod.o zpivotL.o zpruneL.o \
      zmemory.o zutil.o zmyblas2.o \
      zgsisx.o zgsitrf.o zldperm.o \
      ilu_zdrop_row.o ilu_zsnode_dfs.o \
      ilu_zcolumn_dfs.o ilu_zpanel_dfs.o ilu_zcopy_to_ucol.o \
      ilu_zpivotL.o zdiagonal.o
  
  all:    single double complex complex16
  
  single: $(SLUSRC) $(ALLAUX) $(LAAUX) $(SLASRC) $(SCLAUX)
      $(ARCH) $(ARCHFLAGS) $(SUPERLULIB) \
          $(SLUSRC) $(ALLAUX) $(LAAUX) $(SLASRC) $(SCLAUX)
      $(RANLIB) $(SUPERLULIB)
  
  double: $(DLUSRC) $(ALLAUX) $(LAAUX) $(DLASRC) $(DZLAUX)
      $(ARCH) $(ARCHFLAGS) $(SUPERLULIB) \
                  $(DLUSRC) $(ALLAUX) $(LAAUX) $(DLASRC) $(DZLAUX)
      $(RANLIB) $(SUPERLULIB)
  
  complex: $(CLUSRC) $(ALLAUX) $(LAAUX) $(CLASRC) $(SCLAUX)
      $(ARCH) $(ARCHFLAGS) $(SUPERLULIB) \
          $(CLUSRC) $(ALLAUX) $(LAAUX) $(CLASRC) $(SCLAUX)
      $(RANLIB) $(SUPERLULIB)
  
  complex16: $(ZLUSRC) $(ALLAUX) $(LAAUX) $(ZLASRC) $(DZLAUX)
      $(ARCH) $(ARCHFLAGS) $(SUPERLULIB) \
          $(ZLUSRC) $(ALLAUX) $(LAAUX) $(ZLASRC) $(DZLAUX)
      $(RANLIB) $(SUPERLULIB)
  
  
  ##################################
  # Do not optimize these routines #
  ##################################
  slamch.o: slamch.c ; $(CC) -c $(NOOPTS) $(CDEFS) $&lt;
  dlamch.o: dlamch.c ; $(CC) -c $(NOOPTS) $(CDEFS) $&lt;
  superlu_timer.o:  superlu_timer.c ; $(CC) -c $(NOOPTS) $&lt;
  ##################################
  
  .c.o:
      $(CC) $(CFLAGS) $(CDEFS) $(BLASDEF) -c $&lt; $(VERBOSE)
  
  .f.o:
      $(FORTRAN) $(FFLAGS) -c $&lt;
  
  clean:  
      rm -f *.o $(SUPERLULIB)
  </code></pre>
  
  <p><strong>Armadillo Makefile generated by CMake</strong></p>
  
  <pre><code># CMAKE generated file: DO NOT EDIT!
  # Generated by "Unix Makefiles" Generator, CMake Version 2.8
  
  # Default target executed when no arguments are given to make.
  default_target: all
  .PHONY : default_target
  
  #=============================================================================
  # Special targets provided by cmake.
  
  # Disable implicit rules so canonical targets will work.
  .SUFFIXES:
  
  # Remove some rules from gmake that .SUFFIXES does not remove.
  SUFFIXES =
  
  .SUFFIXES: .hpux_make_needs_suffix_list
  
  # Suppress display of executed commands.
  $(VERBOSE).SILENT:
  
  # A target that is always out of date.
  cmake_force:
  .PHONY : cmake_force
  
  #=============================================================================
  # Set environment variables for the build.
  
  # The shell in which to execute make rules.
  SHELL = /bin/sh
  
  # The CMake executable.
  CMAKE_COMMAND = /usr/bin/cmake
  
  # The command to remove a file.
  RM = /usr/bin/cmake -E remove -f
  
  # Escaping for special characters.
  EQUALS = =
  
  # The program to use to edit the cache.
  CMAKE_EDIT_COMMAND = /usr/bin/cmake-gui
  
  # The top-level source directory on which CMake was run.
  CMAKE_SOURCE_DIR = /home/daniel/Downloads/armadillo-6.500.5
  
  # The top-level build directory on which CMake was run.
  CMAKE_BINARY_DIR = /home/daniel/Downloads/armadillo-6.500.5
  
  #=============================================================================
  # Targets provided globally by CMake.
  
  # Special rule for the target edit_cache
  edit_cache:
      @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
      /usr/bin/cmake-gui -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
  .PHONY : edit_cache
  
  # Special rule for the target edit_cache
  edit_cache/fast: edit_cache
  .PHONY : edit_cache/fast
  
  # Special rule for the target install
  install: preinstall
      @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
      /usr/bin/cmake -P cmake_install.cmake
  .PHONY : install
  
  # Special rule for the target install
  install/fast: preinstall/fast
      @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
      /usr/bin/cmake -P cmake_install.cmake
  .PHONY : install/fast
  
  # Special rule for the target install/local
  install/local: preinstall
      @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
      /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
  .PHONY : install/local
  
  # Special rule for the target install/local
  install/local/fast: install/local
  .PHONY : install/local/fast
  
  # Special rule for the target list_install_components
  list_install_components:
      @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\" \"dev\""
  .PHONY : list_install_components
  
  # Special rule for the target list_install_components
  list_install_components/fast: list_install_components
  .PHONY : list_install_components/fast
  
  # Special rule for the target rebuild_cache
  rebuild_cache:
      @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
      /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
  .PHONY : rebuild_cache
  
  # Special rule for the target rebuild_cache
  rebuild_cache/fast: rebuild_cache
  .PHONY : rebuild_cache/fast
  
  # The main all target
  all: cmake_check_build_system
      $(CMAKE_COMMAND) -E cmake_progress_start /home/daniel/Downloads/armadillo-6.500.5/CMakeFiles /home/daniel/Downloads/armadillo-6.500.5/CMakeFiles/progress.marks
      $(MAKE) -f CMakeFiles/Makefile2 all
      $(CMAKE_COMMAND) -E cmake_progress_start /home/daniel/Downloads/armadillo-6.500.5/CMakeFiles 0
  .PHONY : all
  
  # The main clean target
  clean:
      $(MAKE) -f CMakeFiles/Makefile2 clean
  .PHONY : clean
  
  # The main clean target
  clean/fast: clean
  .PHONY : clean/fast
  
  # Prepare targets for installation.
  preinstall: all
      $(MAKE) -f CMakeFiles/Makefile2 preinstall
  .PHONY : preinstall
  
  # Prepare targets for installation.
  preinstall/fast:
      $(MAKE) -f CMakeFiles/Makefile2 preinstall
  .PHONY : preinstall/fast
  
  # clear depends
  depend:
      $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
  .PHONY : depend
  
  #=============================================================================
  # Target rules for targets named armadillo
  
  # Build rule for target.
  armadillo: cmake_check_build_system
      $(MAKE) -f CMakeFiles/Makefile2 armadillo
  .PHONY : armadillo
  
  # fast build rule for target.
  armadillo/fast:
      $(MAKE) -f CMakeFiles/armadillo.dir/build.make CMakeFiles/armadillo.dir/build
  .PHONY : armadillo/fast
  
  # Manual pre-install relink rule for target.
  armadillo/preinstall:
      $(MAKE) -f CMakeFiles/armadillo.dir/build.make CMakeFiles/armadillo.dir/preinstall
  .PHONY : armadillo/preinstall
  
  src/wrapper.o: src/wrapper.cpp.o
  .PHONY : src/wrapper.o
  
  # target to build an object file
  src/wrapper.cpp.o:
      $(MAKE) -f CMakeFiles/armadillo.dir/build.make CMakeFiles/armadillo.dir/src/wrapper.cpp.o
  .PHONY : src/wrapper.cpp.o
  
  src/wrapper.i: src/wrapper.cpp.i
  .PHONY : src/wrapper.i
  
  # target to preprocess a source file
  src/wrapper.cpp.i:
      $(MAKE) -f CMakeFiles/armadillo.dir/build.make CMakeFiles/armadillo.dir/src/wrapper.cpp.i
  .PHONY : src/wrapper.cpp.i
  
  src/wrapper.s: src/wrapper.cpp.s
  .PHONY : src/wrapper.s
  
  # target to generate assembly for a file
  src/wrapper.cpp.s:
      $(MAKE) -f CMakeFiles/armadillo.dir/build.make CMakeFiles/armadillo.dir/src/wrapper.cpp.s
  .PHONY : src/wrapper.cpp.s
  
  # Help Target
  help:
      @echo "The following are some of the valid targets for this Makefile:"
      @echo "... all (the default if no target is provided)"
      @echo "... clean"
      @echo "... depend"
      @echo "... armadillo"
      @echo "... edit_cache"
      @echo "... install"
      @echo "... install/local"
      @echo "... list_install_components"
      @echo "... rebuild_cache"
      @echo "... src/wrapper.o"
      @echo "... src/wrapper.i"
      @echo "... src/wrapper.s"
  .PHONY : help
  
  
  
  #=============================================================================
  # Special targets to cleanup operation of make.
  
  # Special rule to run CMake to check the build system integrity.
  # No rule that depends on this can have commands that come from listfiles
  # because they might be regenerated.
  cmake_check_build_system:
      $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
  .PHONY : cmake_check_build_system
  </code></pre>
  
  <p>Please let me know what I should try. I am not very experienced with compiling/linking libraries on Linux, so please provide details if possible. Thank you.</p>