Hum... for trunk on i686-linux, I do see the following. Dynamic
linking works fine:
$ gfortran -fopenmp omp_hello.f && OMP_NUM_THREADS=2 ./a.out
Hello World from thread = 0
Number of threads = 2
Hello World from thread = 1
Static linking fails:
$ gfortran -fopenmp omp_hello.f -static
/tmp/cc697VvU.o(.text+0x24): In function `MAIN__':
omp_hello.f: undefined reference to `GOMP_parallel_start'
/tmp/cc697VvU.o(.text+0x39):omp_hello.f: undefined reference to
`GOMP_parallel_end'
/tmp/cc697VvU.o(.text+0x49): In function `MAIN__.omp_fn.0':
omp_hello.f: undefined reference to `omp_get_thread_num_'
/tmp/cc697VvU.o(.text+0xe3):omp_hello.f: undefined reference to
`omp_get_num_threads_'
collect2: ld returned 1 exit status
The reading of the libgomp.spec lead me to give it explicitly the
needed libraries (although it shouldn't be necessary, I guess). But
then, it segfaults:
$ gfortran -fopenmp omp_hello.f -static -lgomp -lrt &&
OMP_NUM_THREADS=2 ./a.out
zsh: segmentation fault OMP_NUM_THREADS=2 ./a.out
And the backtrace is:
Program received signal SIGSEGV, Segmentation fault.
0x08048466 in initialize_team () at
../../../gcc/libgomp/config/posix/sem.h:75
75 ../../../gcc/libgomp/config/posix/sem.h: No such file or
directory.
in ../../../gcc/libgomp/config/posix/sem.h
(gdb) where
#0 0x08048466 in initialize_team ()
at ../../../gcc/libgomp/config/posix/sem.h:75
#1 0x080aff5e in __do_global_ctors_aux ()
#2 0x08048109 in _init ()
#3 0x080613ed in __libc_csu_init ()
#4 0x08061138 in __libc_start_main ()
#5 0x08048141 in _start ()
PS: Some details on the static linking failure:
Driving: gfortran -fopenmp omp_hello.f -static -v -lgfortranbegin
-lgfortran -lm
Using built-in specs.
Target: i386-linux
Configured with: ../gcc/configure
--prefix=/cosmic/coudert/tmp/gfortran-20060228/irun
--enable-languages=c,fortran --host=i386-linux
--with-gmp=/cosmic/coudert/tmp/gfortran-20060228/gfortran_libs
Thread model: posix
gcc version 4.2.0 20060228 (experimental)
/tmpdir/opt/gfortran/gfortran-20060228/bin/../libexec/gcc/i386-linux/
4.2.0/f951
omp_hello.f -ffixed-form -quiet -dumpbase omp_hello.f -mtune=i386
-auxbase omp_hello -version -fopenmp -I
/tmpdir/opt/gfortran/gfortran-20060228/bin/../lib/gcc/i386-linux/
4.2.0/finclude
-o /tmp/ccGKM8HT.s
GNU F95 version 4.2.0 20060228 (experimental) (i386-linux)
compiled by GNU C version 4.2.0 20060228 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param
ggc-min-heapsize=4096
as -V -Qy -o /tmp/cc08jqIE.o /tmp/ccGKM8HT.s
GNU assembler version 2.15.94.0.2.2 (i386-redhat-linux) using BFD
version 2.15.94.0.2.2 20041220
Reading specs from
/tmpdir/opt/gfortran/gfortran-20060228/bin/../lib/gcc/i386-linux/
4.2.0/../../../libgomp.spec
/tmpdir/opt/gfortran/gfortran-20060228/bin/../libexec/gcc/i386-linux/
4.2.0/collect2
-m elf_i386 -static /usr/lib/crt1.o /usr/lib/crti.o
/tmpdir/opt/gfortran/gfortran-20060228/bin/../lib/gcc/i386-linux/
4.2.0/crtbeginT.o
-lgomp -lrt
-L/tmpdir/opt/gfortran/gfortran-20060228/bin/../lib/gcc/i386-linux/
4.2.0
-L/tmpdir/opt/gfortran/gfortran-20060228/bin/../lib/gcc
-L/tmpdir/opt/gfortran/gfortran-20060228/bin/../lib/gcc/i386-linux/
4.2.0/../../..
/tmp/cc08jqIE.o -lgfortranbegin -lgfortran -lm --start-group -lgcc
-lgcc_eh -lpthread -lc --end-group
/tmpdir/opt/gfortran/gfortran-20060228/bin/../lib/gcc/i386-linux/
4.2.0/crtend.o
/usr/lib/crtn.o
/tmp/cc08jqIE.o(.text+0x24): In function `MAIN__':
omp_hello.f: undefined reference to `GOMP_parallel_start'
/tmp/cc08jqIE.o(.text+0x39):omp_hello.f: undefined reference to
`GOMP_parallel_end'
/tmp/cc08jqIE.o(.text+0x49): In function `MAIN__.omp_fn.0':
omp_hello.f: undefined reference to `omp_get_thread_num_'
/tmp/cc08jqIE.o(.text+0xe3):omp_hello.f: undefined reference to
`omp_get_num_threads_'
collect2: ld returned 1 exit status