C++ linking library to a library

Hi All,

My application main engine will use a shared library where we do many operation. We are trying to implement the linear algebra operation on the shared library for that I need to link my shared library to the lapack library in /usr/lib .

Below is my make file. Can you please let me know where can I link the lblas lib to this make file


IP_INCLUDE=../iplib
MKLIB_INCLUDE=../lib



LIBNAME=shared
YESBANVER=$(YESBAN_PRODUCT_MAJ)$(YESBAN_PRODUCT_MIN)
YESBANBLD=$(YESBAN_PRODUCT_BUILD_VER)
ARMAD=/home/armadillo3.4.4/armadillo-3.4.4/include
LLPAT=/usr/lib64

INCLUDEDIR=-I$(YESBAN_RWPATH_64)  -I$(YESBAN_RWINCLUDECTPATH_64) -I$(YESBAN_RWINCLUDEPATH_64) \
        -I$(YESBAN_SYBINCLUDE_64) -I$(IMS_INCLUDE) -I$(PFLIB_INCLUDE) -I. -I$(ARMAD) -I$(LLPAT)


#---------------------------------------------------------------------
# ---- Constants definitions
#               OPT_CPP                 - C++ Compiler Options
#               OPT_C                   - C Compiler Options
# ---------------------------------------------------------------------


#CPPOPTS=-D_OS_LINUX -DHPaCC -DSYB_LP64 -D_THREAD_SAFE -D__HPACC_THREAD_SAFE_RB_TREE

CPPOPTS=

# C++ Compiler

OPT_CPP=$(YESBAN_CCOPT) $(_OPT_CPP) $(INCLUDEDIR) $(YESBAN_RW_OPTS) -D_FILE_OFFSET_BITS=64 -DARMA_DONT_USE_WRAPPER


# C Compiler
# ----------
OPT_C=$(YESBAN_COPT) $(_OPT_C) $(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 -DARMA_DONT_USE_WRAPPER


.SUFFIXES: .cpp .o .c

all:clean
        make -f GNUmakefile_64 $(YESBAN_BIN_64)/lib$(LIBNAME).a

rel:
        make -f GNUmakefile_64 $(YESBAN_BIN_64)/lib$(LIBNAME).a

dbg:
        make -f GNUmakefile_64 $(YESBAN_BINDBG_64)/lib$(LIBNAME).a

$(YESBAN_BIN_64)/lib$(LIBNAME).a: $(OBJECTS)
        $(YESBAN_AR) -r $@ $(OBJECTS)

$(YESBAN_BINDBG_64)/lib$(LIBNAME).a: $(DBGOBJECTS)
        $(YESBAN_AR) -r $@ $(DBGOBJECTS)

# --> C++ compilation
$(YESBAN_BIN_64)/%.o : %.cpp
        $(YESBAN_CC_64)  $(OPT_CPP) $< -o $@
# --> C compilation.
$(YESBAN_BIN_64)/%.o : %.c
        $(YESBAN_CC_64)  $(OPT_CPP) $< -o $@
# --> C++ compilation
$(YESBAN_BINDBG_64)/%.o : %.cpp
        $(YESBAN_CC_64) $(YESBAN_CCDEBUG)  $(OPT_CPP) $< -o $@


# --> C compilation.
$(YESBAN_BINDBG_64)/%.o : %.c
        $(YESBAN_CC_64) $(YESBAN_CDEBUG)  $(OPT_CPP) $< -o $@

Below is the error I am getting when I try to link by in make file above as below

OPT_CPP=$(YESBAN_CCOPT) $(_OPT_CPP) $(INCLUDEDIR) $(YESBAN_RW_OPTS) -D_FILE_OFFSET_BITS=64 -DARMA_DONT_USE_WRAPPER -llapack

Let me understand.

You want to add your shared library module to an existing lapack library (or archive?). Aside from the fact that this is a really bad idea, short answer is: this cannot be done.

You will have to use LD_PRELOAD. Google for examples: interposing libraries.

If you have an lapack archive (.o) file then you can add another archive file to the lapack distribution, which is still a bad idea.

1 Like

Thanks . Below is my scenario. I am to do it in either , I don't want shared library to add to lapack. I want lapack to added to my shared library

MY engine (C++) ----> Use shared library -----using lapack (which is my new addition)

Now we are implementing a function in shared library which need to use lapack. All my lapack function reside in my shared library. Now the issue is when my engine require the lapack function it will access through share library. I am facing problem with this . The compiller complaining that it cannot link the lapack library on the shared library.

I linked the lapack to the engine at the execution time it is complaining that the lapack needs to be linked with my shared library Which I am not able to do

Thanks
Arun