Linking to a library in mixed C/Fortran 77 code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a test OpenMP application whose source mixes Fortran 77 with C, and I am having a problem in linking to libgomp, the Gnu OpenMP support library that comes with GCC.  The application has two files, "prog.f" (Fortran 77), containing the main program, and "helper.c."  The application uses routines defined in my version of libgomp, which I have altered.  (My altered libgomp links and works fine with OpenMP applications written simply in C, linking both dynamically and statically.)  I am building and attempting to link using GCC 4.6.2, with the libgomp and gcc/omp-low.c altered, but everything else is the same as in the release.  (This is under Ubuntu Linux 2.6 for x86.)  Below is a simplified version of the code and my Makefile.  The problem is in the call to "foo" in function "foo_f," defined in "helper.c":  "foo" is defined in my altered libgomp, but, if I try to build with dynamic linkage (without the "-static" option), ld reports "undefined reference to 'foo.'"  If I build using the "-static" keyword, since OpenMP uses pthreads, I also have to pass ld the linker script "-Wl,--whole-archive -lpthread -Wl,--no-whole-archive."  When I do this, my application builds and runs correctly, but I get this warning at build time:

/usr/lib/../lib64/libpthread.a(sem_open.o): In function `sem_open':
/build/buildd/eglibc-2.11.1/nptl/sem_open.c:333: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'

Here's a simplified version of the source code.  Note that "head.s" and "tail.s" are tiny assembly files that define labels, which my special version of OpenMP uses.

***** prog.f *********

      program prog
      integer x_store
      pointer(x, x_val)
      x = loc(x_store)
     x_val = 42
     call foo_f(x)
!$omp parallel num_threads(2)
      call foo_f(x)
!$omp end parallel
      print *, "x == ", x_val
      stop
      end

**********************

/**** helper.c ********/
static int idty_store = 0;
static int * idty = &idty_store;

extern foo(void ** x, void ** y);

void foo_f(void ** input) {
    foo(input, (void **)&idty);
}

/***************************/

#****** Makefile ******

CC = /my_gcc/gcc_install/bin/gcc
CFLAGS = -Wall -g -fopenmp
F77 = /my_gcc/gcc_install/bin/gfortran
FFLAGS = -Wall -g -fcray-pointer -fno-underscoring -fno-common -fopenmp
LDFLAGS = -L/my_gcc/gcc_install/lib64
LDFLAGS += -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive
TARGET = prog
HELPER = helper
      
$(TARGET): head.s $(TARGET).o $(HELPER).o tail.s
        $(F77) $(FFLAGS) $(LDFLAGS) $^ -o $@

$(TARGET).o: $(TARGET).f
        $(F77) $(FFLAGS) -c $^
        
$(HELPER).o: $(HELPER).c
        $(CC) $(CFLAGS) -c $^

#*******************************************************

Thanks!


Amittai Aviram
PhD Student in Computer Science
Yale University
646 483 2639
amittai.aviram@xxxxxxxx
http://www.amittai.com




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux