public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* DLLEXPORT on common
@ 2017-03-05 18:08 Marco Atzeri
  0 siblings, 0 replies; only message in thread
From: Marco Atzeri @ 2017-03-05 18:08 UTC (permalink / raw)
  To: fortran

[-- Attachment #1: Type: text/plain, Size: 1422 bytes --]

Similar to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47030
but as I can not create the user on bugzilla,
I am asking here:

The code
---------------------------------------
       common /cb1/ cvar
!GCC$ ATTRIBUTES DLLIMPORT  :: /cb1/
       integer cvar
---------------------------------------
arises the error
---------------------------------------
  !GCC$ ATTRIBUTES DLLIMPORT  :: /cb1/
                                 1
Error: Invalid character in name at (1)
---------------------------------------

If used without "/"
--------------------------------------
  !GCC$ ATTRIBUTES DLLEXPORT :: cb1
                                  1
Warning: Unused variable ‘cb1’ declared at (1) [-Wunused-variable]
--------------------------------------
The variable is not recognized.

As DLLEXPRT/DLLIMPORT are not working, the shared common are
produced on the object files

$ nm *.o |grep cb1
0000000000000004 C cb1_
0000000000000004 C cb1_

but I do not find a way to declare cb1 as export in a shared library,
and properly link it during the program compilation.
There is a workaround ?


This issue is blocking the relase of PETSC shared lib on cygwin

http://lists.mcs.anl.gov/pipermail/petsc-dev/2017-February/020562.html
https://cygwin.com/ml/cygwin/2015-06/msg00352.html

Tested on latest current and experimental gfortran on cygwin

  gcc version 5.4.0
  gcc version 6.3.0 (GCC)


Thanks in advance
Marco



[-- Attachment #2: cb_test-4.sh --]
[-- Type: text/plain, Size: 1213 bytes --]

#!/bin/sh -x
cat >cb_main.f <<\EOF
      program cb_main
!GCC$ ATTRIBUTES DLLEXPORT :: cb1
      integer cvar
      common /cb1/ cvar
      cvar = 0
      call cb_func()
      if(cvar.eq.2) then
          write(*,*)'GOOD COMMON BLOCK'
      else
          write(*,*)'BAD COMMON BLOCK'
      endif
      end
EOF
cat >cb_func.f <<\EOF
      subroutine cb_func()
!GCC$ ATTRIBUTES DLLIMPORT :: cb1
      integer cvar
      common /cb1/ cvar
      cvar = 2
      cvar2 = 2
      end
EOF
################################################################################
rm -f *.o *.dll *.a *.exe
gfortran -Wall -c cb_func.f 
gfortran -Wall -c cb_main.f 
################################################################################
ar cr libcb_static.a cb_func.o
gfortran -Wall cb_main.o -L. -lcb_static -o cb_main_static
################################################################################
gfortran -Wall -shared -o libcb_dynamic.dll cb_func.o 
gfortran -Wall cb_main.o -L. -lcb_dynamic -o cb_main_dynamic 
################################################################################
./cb_main_static
./cb_main_dynamic
################################################################################

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-03-05 18:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-05 18:08 DLLEXPORT on common Marco Atzeri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).