linuxmakefile64-bitshared-librarieslibrary-path

how to link your project to a library of 64 bit in makefile


I am a beginner developer in makefile and have a project that includes a src directory. Inside the src directory there are some .c and .h files as follows: file1.c, file2.c, main.c, header1.h and header2.c. Main depends on file2.c while file2.c depends on file1.c. Each file should be linked to non standard libraries that I have and a non standard include directory, too. The libraries directory and the include directory are /usr/lib/srr__lib and /usr/bin/srr__bin respectively. I wrote two makefiles one at the src directory and the other one at the root directory of the project. The src makefile is as shown below:

 CC = gcc

 TARGETDIR_PR=GNU-amd64-Linux

 all: $(TARGETDIR_PR)/PR

 OBJS_PR =  \
    $(TARGETDIR_PR)/file1.o \
    $(TARGETDIR_PR)/file2.o \
    $(TARGETDIR_PR)/main.o

  AM_CPPFLAGS = \
    -DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
    -DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
    -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\"

 AM_CFLAGS =\
       -g -I/usr/bin/srr__bin 

 bin_PROGRAMS = PR

PR_4_SOURCES = \
       file1.c \
       file2.c \
       main.c 

PR_LDFLAGS = 

 PR_LDADD = -L/usr/lib/srr__lib -lsrr__ml__sharedmem_4core -lprdependency -lsrrdsl___wrapper_library__ml -lsrrdynarray -lsrrdynarray_pic -lsrrhistogram -lsrrhistogram_pic -lsrrlistofarrays -lsrrlistofarrays_pic -lsrrmalloc -lsrrparam -lsrrparam_pic -lsrrqueue -lsrrqueue_pic -lvreo_wrapper_library

 $(TARGETDIR_PR)/PR: $(TARGETDIR_PR) $(OBJS_PR)
       $(LINK.c) $(AM_CFLAGS) $(AM_CPPFLAGS) -o $@ $(OBJS_PR) $(PR_LDADD)


 $(TARGETDIR_PR)/SeedVP.o: $(TARGETDIR_PR) SeedVP.c
        $(COMPILE.c) $(AM_CFLAGS) $(AM_CPPFLAGS) -o $@ file1.c

 $(TARGETDIR_PR)/Task.o: $(TARGETDIR_PR) Task.c
        $(COMPILE.c) $(AM_CFLAGS) $(AM_CPPFLAGS) -o $@ file2.c

 $(TARGETDIR_PR)/main.o: $(TARGETDIR_PR) main.c
        $(COMPILE.c) $(AM_CFLAGS) $(AM_CPPFLAGS) -o $@ main.c

 clean:
    rm -f \
        $(TARGETDIR_PR)/PR \
        $(TARGETDIR_PR)/file1.o \
        $(TARGETDIR_PR)/file2.o \
        $(TARGETDIR_PR)/main.o
    rm -f -r $(TARGETDIR_PR)


  # Create the target directory (if needed)
 $(TARGETDIR_PR):
       mkdir -p $(TARGETDIR_PR)

  # Enable dependency checking
    .KEEP_STATE:
    .KEEP_STATE_FILE:.make.state.GNU-amd64-Linux

and the makefile of the root directory is as shown below :

SUBDIRS = src

 PRDSL_4docdir = ${prefix}/doc/PR
  PRdoc_DATA = \
  README\
  COPYING\
  AUTHORS\
  ChangeLog\
  INSTALL\
  NEWS


INTLTOOL_FILES = intltool-extract.in \
  intltool-merge.in \
  intltool-update.in

EXTRA_DIST = $(PRdoc_DATA) \
  $(INTLTOOL_FILES)

DISTCLEANFILES = intltool-extract \
intltool-merge \
intltool-update \
po/.intltool-merge-cache


# Remove doc directory on uninstall
 uninstall-local:
   -rm -r $(PRdocdir)

I run all the autotools command successfully and the ./configure then make and the project didn't complain; no error at the make but when I run the generated executable file as ./PR it complains and gave the error below:

error while loading shared libraries: libsrr__ml__sharedmem_4core.so: cannot open shared object file: No such file or directory

i think it's maybe an error in linking as the library is 64 bit and my machine is 64 also. But, how can I mention this in the makefile? Any help will be appreciated.


Solution

  • When running the program run it this way

    export LD_LIBRARY_PATH=/usr/lib/srr__lib
    ./executable_file
    

    or edit /etc/ld.so.conf and add the line

    /usr/lib/srr__lib
    

    and run ldconfig as root.