Operating System - Linux
1752513 Members
5689 Online
108788 Solutions
New Discussion юеВ

Re: Managing Shared Libraries in Makefile

 
CA1490051
Frequent Advisor

Managing Shared Libraries in Makefile

Hi All,

I have the following problem while linking the shared library. can some one help me to solve this problem.

The Directory structure for my project is as below

MAIN -
WorkSpace -
DIR1 - Src
Hdr
lib
obj
DIR2 - Src
Hdr
lib
obj
DIR3 -Src
..
..
Workspace is the directory where i am copying all the shared libraries and the executable. My main function is present in DIR3/Src

So initillay i generated the shared libraries for each DIRs in their respective lib directories and copied it to WorkSpace in the Makefile of each directory

Now while generating the executable, in DIR3/Src/Makefile i i have specified to take the libraries present in the
../../WorkSpace

But, I am getting
ld errors because the compiler is not getting the Path. But if i give
/home/Vikram/MAIN/WorkSpace, it works.

Can any one help me to solve this problem.

Also, if i hard core the paths like this can i use the executable generated in WorkSpace as a standaloner in some other Machine.

thanks and regards
Vikram
3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: Managing Shared Libraries in Makefile

This is related to your makefile questions.
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1192611

>The directory structure for my project is as below

(You can't rely on spacing here unless you check the box. So you should list the full paths for each line.)

>I am getting ld errors because the compiler is not getting the Path.

No compilers are involved. Just ld.
Are you using -L with the correct relative path?

>if i hard code the paths like this, can I use the executable generated in WorkSpace as a standaloner in some other Machine.

Yes, there are several options.
You can use -Wl,+b,path-list to embed the location at runtime.
You can use -Wl,+s so that dld can honor SHLIB_PATH or LD_LIBRARY_PATH at runtime.

For newer linkers, you can also use $ORIGIN in the paths to it is relative to the executable.
CA1490051
Frequent Advisor

Re: Managing Shared Libraries in Makefile

Hi Dennis,

Yes, i have given the correct Path and i also displayed the contetnt of the WorkSpace Directory where all the libraries are present.

Still the linker will complain about the ld errorrs

But, I am able to compile now by setting the SHLIB_PATH to the workSpace directory.

Please find the sample of Makefile attached which i am using in the DIR3/Src/Makefile.

LINKLIB = ../../libStringTokenizer.so \
../../libStringToNumericals.so \
../../libbvfWriter.so \
../../libReadRawData.so \
../../libReadLayoutData.so \
../../libz.sl



$(TARGET) : ProberData ReadProberData.cpp wcBvfWriter.cpp
test -d $(TARGETDIR) || mkdir -p $(TARGETDIR)
pwd; ls ../../WorkSpace ; $(CXX) -o $@ $(INCPATH) ReadProberData.cpp wcBvfWriter.cpp $(LINKLIB);pwd;



thanks and regards
Vikram





Dennis Handly
Acclaimed Contributor

Re: Managing Shared Libraries in Makefile

You didn't mention specifically if you were on PA or IPF. On PA you should name your shibs as .sl, not .so.

>LINKLIB = ../../libStringTokenizer.so \ ...

The proper way to do this is with -L & -l:
LINKLIB = -L../../WorkSpace -lStringTokenizer \
-lStringToNumericals -lbvfWriter \
-lReadRawData -lReadLayoutData -lz

(The -l option requires .sl for PA.)
If you don't use -l, then +s and +b don't work, without additional chatr(1) magic.

>test -d $(TARGETDIR) || mkdir -p $(TARGETDIR)

No need for test, just do "mkdir -p".