Sourangshu,

Since you appear to be using gcc and the gnu linker, you may be able to get static linking for certain libs w/o need to remove the .so files.  I've not tested this, but you may have luck with something like the following (assuming LAM/MPI's wrapper passes these options w/o changes or reordering):

  mpicc -o foo foo.c -Wl,-Bstatic -lsomething -Wl,-Bdynamic

The "-Wl,-Bstatic" mess tells gcc to pass "-Bstatic" to the linker.  When the linker sees that flag, it tries to use static linking for all -l options that follow ("-lsomething" in this example), until it sees the later "-Bdynamic" which restores the normal behavior (required since mpicc will append its own -l options).

-Paul


Sourangshu Bhattacharya wrote:
Hi Brian,

Thanks a lot for the help.

I got arround the problem by statically linking only those libraries
which are not available on all nodes. Did this by removing the .so
files in the library directory, so that only the .a files were left. I
wonder if the compiler provides options to selectively specify
libraries to be linked statically.

Sourangshu


On Jan 1, 2008 4:02 AM, Brian Barrett <brbarret@lam-mpi.org> wrote:
  
By default, LAM/MPI does a few things that are un-friendly to static
linking, including using some pthreads calls, using dlopen, and playing some
linker tricks.  I'd recommend compiling LAM/MPI with the options:

  --without-threads --without-memory-manager

You'll still likely get some warnings about dlopen() and gethostbyname(),
but those are mostly harmless.

Brian

On Dec 27, 2007, at 12:34 PM, Sourangshu Bhattacharya wrote:

Dear Everybody,

I was trying to compile my program into a static binary with lam/mpi.
The program compiles perfectly when compiled without the static
switch. However, it gives the following errors when trying to compile
with the -static switch.

I have seen a similar query on this mailing list, but no satisfactory
replies. Please let me know if someone has faced a similar problem and
succeded in solving it.

Thank you.
Regards,
Sourangshu
-------------------------------------------------------
[sourangshu@ramanujan parcode]$ make kernel
mpicc -static -I
/home/sourangshu/experiments/lib/gsl/gsl-install//include -I
/home/sourangshu/experiments/lib/glpk/glpk-install//include -L
/home/sourangshu/experiments/lib/gsl/gsl-install//lib -L
/home/sourangshu/experiments/lib/glpk/glpk-install//lib -c -o main.o
main.c
mpicc -static -I
/home/sourangshu/experiments/lib/gsl/gsl-install//include -I
/home/sourangshu/experiments/lib/glpk/glpk-install//include -L
/home/sourangshu/experiments/lib/gsl/gsl-install//lib -L
/home/sourangshu/experiments/lib/glpk/glpk-install//lib -c -o
fullstr.o fullstr.c
mpicc -static -I
/home/sourangshu/experiments/lib/gsl/gsl-install//include -I
/home/sourangshu/experiments/lib/glpk/glpk-install//include -L
/home/sourangshu/experiments/lib/gsl/gsl-install//lib -L
/home/sourangshu/experiments/lib/glpk/glpk-install//lib -c -o substr.o
substr.c
mpicc -static -I
/home/sourangshu/experiments/lib/gsl/gsl-install//include -I
/home/sourangshu/experiments/lib/glpk/glpk-install//include -L
/home/sourangshu/experiments/lib/gsl/gsl-install//lib -L
/home/sourangshu/experiments/lib/glpk/glpk-install//lib -c -o
substrlimitker.o substrlimitker.c
mpicc -static -I
/home/sourangshu/experiments/lib/gsl/gsl-install//include -I
/home/sourangshu/experiments/lib/glpk/glpk-install//include -L
/home/sourangshu/experiments/lib/gsl/gsl-install//lib -L
/home/sourangshu/experiments/lib/glpk/glpk-install//lib -c -o eig.o
eig.c
mpicc -static -I
/home/sourangshu/experiments/lib/gsl/gsl-install//include -I
/home/sourangshu/experiments/lib/glpk/glpk-install//include -L
/home/sourangshu/experiments/lib/gsl/gsl-install//lib -L
/home/sourangshu/experiments/lib/glpk/glpk-install//lib -o kernel
main.o fullstr.o substr.o substrlimitker.o eig.o \
/home/sourangshu/experiments/lib/CLAPACK//tmglib_LINUX.a \
        /home/sourangshu/experiments/lib/CLAPACK//lapack_LINUX.a
/home/sourangshu/experiments/lib/CLAPACK//blas_LINUX.a \
        /home/sourangshu/experiments/lib/CLAPACK//libF77.a
/home/sourangshu/experiments/lib/CLAPACK//libI77.a \
        -lgsl -lgslcblas -lglpk -lm -lc
/opt/lam/gnu/lib/liblam.a(ltdl.o)(.text+0x472): In function `sys_dl_open':
: warning: Using 'dlopen' in statically linked applications requires
at runtime the shared libraries from the glibc version used for
linking
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libpthread.a(lockfile.o)(.text+0x0):
In function `flockfile':
: multiple definition of `_IO_flockfile'
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libc.a(flockfile.o)(.text+0x0):
first defined here
/usr/bin/ld: Warning: size of symbol `_IO_flockfile' changed from 24
in
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libc.a(flockfile.o)
to 12 in
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libpthread.a(lockfile.o)
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libpthread.a(lockfile.o)(.text+0x0):
In function `flockfile':
: multiple definition of `__flockfile'
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libc.a(flockfile.o)(.text+0x0):
first defined here
/usr/bin/ld: Warning: size of symbol `__flockfile' changed from 24 in
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libc.a(flockfile.o)
to 12 in
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libpthread.a(lockfile.o)
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libpthread.a(lockfile.o)(.text+0x10):
In function `funlockfile':
: multiple definition of `_IO_funlockfile'
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libc.a(funlockfile.o)(.text+0x0):
first defined here
/usr/bin/ld: Warning: size of symbol `_IO_funlockfile' changed from 24
in
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libc.a(funlockfile.o)
to 12 in
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libpthread.a(lockfile.o)
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libpthread.a(lockfile.o)(.text+0x10):
In function `funlockfile':
: multiple definition of `__funlockfile'
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libc.a(funlockfile.o)(.text+0x0):
first defined here
/usr/bin/ld: Warning: size of symbol `__funlockfile' changed from 24
in
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libc.a(funlockfile.o)
to 12 in
/usr/lib/gcc/x86_64-redhat-linux/3.4.5/../../../../lib64/libpthread.a(lockfile.o)
/opt/lam/gnu/lib/liblam.a(kill.o)(.text+0x595): In function
`lam_tmpdir_init_opt':
: warning: Using 'getpwuid' in statically linked applications requires
at runtime the shared libraries from the glibc version used for
linking
/opt/lam/gnu/lib/liblam.a(lam_gethostby.o)(.text+0x11): In function
`lam_gethostbyaddr':
: warning: Using 'gethostbyaddr' in statically linked applications
requires at runtime the shared libraries from the glibc version used
for linking
/opt/lam/gnu/lib/liblam.a(lam_gethostby.o)(.text+0x1): In function
`lam_gethostbyname':
: warning: Using 'gethostbyname' in statically linked applications
requires at runtime the shared libraries from the glibc version used
for linking
collect2: ld returned 1 exit status
mpicc: No such file or directory
make: *** [kernel] Error 1


--
"I have never taken any exercise except sleeping and resting." - Mark Twain

Sourangshu Bhattacharya
PhD Student,
Dept. of Computer Science & Automation,
Indian Institute of Science,
Bangalore, India.

http://people.csa.iisc.ernet.in/sourangshu
_______________________________________________
This list is archived at http://www.lam-mpi.org/MailArchives/lam/



--
  Brian Barrett
  LAM/MPI Developer
  Make today a LAM/MPI day!


_______________________________________________
This list is archived at http://www.lam-mpi.org/MailArchives/lam/

    



  


-- 
Paul H. Hargrove                          PHHargrove@lbl.gov
Future Technologies Group
HPC Research Department                   Tel: +1-510-495-2352
Lawrence Berkeley National Laboratory     Fax: +1-510-486-6900