c++ - 构建 Armadillo 线性代数库,无法与 Ubuntu 14.04.3 LTS 上的 SuperLU 链接。制作共享对象时不能使用X

标签 c++ c linux ubuntu makefile

我正在尝试安装最新版本的 Armadillo (6.500.5) http://arma.sourceforge.net/在 Ubuntu 14.04.3 LTS 上。

我需要求解稀疏线性系统的能力,因此根据说明,我需要安装 SuperLU 4.3 版。我安装了 SuperLU 4.3,但在尝试构建 Armadillo 时收到以下错误

Scanning dependencies of target armadillo

[100%] Building CXX object CMakeFiles/armadillo.dir/src/wrapper.cpp.o Linking CXX shared library libarmadillo.so

/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

/usr/lib/SuperLU_4.3/lib/libsuperlu_4.3.a: error adding symbols: Bad value

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[2]: *** [libarmadillo.so.6.500.5] Error 1

make[1]: *** [CMakeFiles/armadillo.dir/all] Error 2

make: *** [all] Error 2

所以我在 SuperLU makefile 中添加了 -fPIcflags并重新编译了 SuperLU,但随后得到了一个非常轻微不同的错误

Linking CXX shared library libarmadillo.so

/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

/usr/bin/ld: final link failed: Bad value

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[2]: *** [libarmadillo.so.6.500.5] Error 1

make[1]: *** [CMakeFiles/armadillo.dir/all] Error 2

make: *** [all] Error 2

我不确定从这里去哪里。 Armadillo 似乎希望找到共享库格式的 SuperLU,而 SuperLU 将自己安装为静态库。包管理器中可用的 Armdillo 版本似乎太过时了,没有我需要的功能。

这里是一些Makefile

SuperLU 的顶级 Makefile

############################################################################
#
#  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 )

SuperLU 中的 make.inc

############################################################################
#
#  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

SuperLU 中的 SRC/Makefile

# 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) $<
dlamch.o: dlamch.c ; $(CC) -c $(NOOPTS) $(CDEFS) $<
superlu_timer.o:  superlu_timer.c ; $(CC) -c $(NOOPTS) $<
##################################

.c.o:
    $(CC) $(CFLAGS) $(CDEFS) $(BLASDEF) -c $< $(VERBOSE)

.f.o:
    $(FORTRAN) $(FFLAGS) -c $<

clean:  
    rm -f *.o $(SUPERLULIB)

CMake 生成的 Armadillo Makefile

# 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

请让我知道我应该尝试什么。我对在 Linux 上编译/链接库不是很有经验,所以请尽可能提供详细信息。谢谢。

最佳答案

有同样的问题,看起来 superlu_timer.c 没有用 -fPIC 编译,即使你在 CFLAGS 中设置它也是如此/p>

出于某种原因,SuperLU 背后的人不想优化那个文件,所以他们在 SRC 文件夹的 Makefile 中为这个单个文件设置了一个特定的目标

可以在SuperLU_4.3/SRC/Makefile中看到:

##################################
# Do not optimize these routines #
##################################
slamch.o: slamch.c ; $(CC) -c $(NOOPTS) $(CDEFS) $<
dlamch.o: dlamch.c ; $(CC) -c $(NOOPTS) $(CDEFS) $<
superlu_timer.o:  superlu_timer.c ; $(CC) -c $(NOOPTS) $<
##################################

解决方案是更改 superlu_timer.o 行以包含 -fPIC:

superlu_timer.o:  superlu_timer.c ; $(CC) -fPIC -c $(NOOPTS) $<

之后,只需执行make cleanmake 即可再次生成库

关于c++ - 构建 Armadillo 线性代数库,无法与 Ubuntu 14.04.3 LTS 上的 SuperLU 链接。制作共享对象时不能使用X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35530901/

相关文章:

c - 这是未定义的行为吗?

c - 按特定字符拆分单词适用于字符串,但不适用于 argv[1]

linux - 如何杀死Linux中的特定进程?

c++ - 是否可以将 gcc 的链接器与 dlopen 结合使用?

linux - Shell 函数提前退出而不是遍历所有内容

c++ - ethtool ioctl 返回未填充的 ethtool_link_settings

c++ - 使用 ppl.h 查找最大值

c - 比较函数如何调用数组元素以及调用顺序是什么

c++ - 如何在多采样纹理中渲染颜色和深度?

c++ - 使用 ffmpeg 创建视频