Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can't get DLLEXPORT to work with gcc/gfortran/gfortran-4

411 views
Skip to first unread message

jens.o...@gmail.com

unread,
Apr 24, 2013, 6:53:14 AM4/24/13
to
Hello!
Im on a Windows x64 machine with i7 and Cygwin 4.5.3.
In mango.f95 I have two subroutines and only those
"
subroutine MyAdd(z, a, b) C(Bind, name = "MyAdd")
!GCC$ ATTRIBUTES DLLEXPORT::myadd
integer, intent (out) :: z
integer, intent (in) :: a
integer, intent (in) :: b
integer :: n
integer :: k
integer :: t
integer :: i
n = a
k = b
t = 1
if (k.LT.(n - k)) then
do i = n, (n - k + 1), (-1)
t = t*i/(n - i + 1)
end do
else
do i = n, (k + 1), (-1)
t = t*i/(n - i + 1)
end do
end if
z = t
end subroutine MyAdd


subroutine MyPBP( S, p, N ) C(Bind, name ="MyPBP")
!GCC$ ATTRIBUTES DLLEXPORT::mypbp
! This function computes the Poisson-Binomial distribution
! of size N using p
double precision, intent(inout) :: S(N+1)
double precision, intent(in) :: p(N)
integer, intent(in) :: N
double precision :: X(N+1)
integer i, j
X=0
S=0
X(1) = 1 - p(1)
X(2) = p(1)
do i = 2, N
S(1) = X(1)*(1-p(i))
do j = 2,i
S(j) = X(j-1)*p(i) + X(j)*(1-p(i))
end do
S(i+1) = X(i)*p(i)
X = S
end do
S = X
end subroutine MyPBP
"
Trying to compile with
gcc -c mango.f95
gfortran -c mango.f95
gfortran -c mango.f95

All three resulting in the same error

Använder inbyggda specifikationer.
COLLECT_GCC=gfortran-4
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/4.5.3/lto-wrapper.exe
Mål: i686-pc-cygwin
Konfigurerad med: /gnu/gcc/releases/respins/4.5.3-3/gcc4-4.5.3-3/src/gcc-4.5.3/configure --srcdir=/gnu/gcc/releases/respins/4.5.3-3/gcc4-4.5.3-3/src/gcc-4.5.3 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --datarootdir=/usr/share --docdir=/usr/share/doc/gcc4 -C --datadir=/usr/share --infodir=/usr/share/info --mandir=/usr/share/man -v --with-gmp=/usr --with-mpfr=/usr --enable-bootstrap --enable-version-specific-runtime-libs --libexecdir=/usr/lib --enable-static --enable-shared --enable-shared-libgcc --disable-__cxa_atexit --with-gnu-ld --with-gnu-as --with-dwarf2 --disable-sjlj-exceptions --enable-languages=ada,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite --enable-lto --enable-java-awt=gtk --disable-symvers --enable-libjava --program-suffix=-4 --enable-libgomp --enable-libssp --enable-libada --enable-threads=posix --with-arch=i686 --with-tune=generic --enable-libgcj-sublibs CC=gcc-4 CXX=g++-4 CC_FOR_TARGET=gcc-4 CXX_FOR_TARGET=g++-4 GNATMAKE_FOR_TARGET=gnatmake GNATBIND_FOR_TARGET=gnatbind --with-ecj-jar=/usr/share/java/ecj.jar
Trådmodell: posix
gcc version 4.5.3 (GCC)
COLLECT_GCC_OPTIONS='-c' '-v' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-pc-cygwin/4.5.3/f951.exe main.f95 -quiet -dumpbase main.f95 -mtune=generic -march=i686 -auxbase main -version -fintrinsic-modules-path /usr/lib/gcc/i686-pc-cygwin/4.5.3/finclude -o /tmp/cc9sIIp3.s
GNU Fortran (GCC) version 4.5.3 (i686-pc-cygwin)
kompilerad med GNU C version 4.5.3, GMP-version 4.3.2, MPFR-version 3.0.1-p4, MPC-version 0.8
GGC heuristik: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran (GCC) version 4.5.3 (i686-pc-cygwin)
kompilerad med GNU C version 4.5.3, GMP-version 4.3.2, MPFR-version 3.0.1-p4, MPC-version 0.8
GGC heuristik: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
main.f95:2:0: fel: extern länkklass krävs för symbol "myadd" på grund av attributet "dllexport"
main.f95:154:0: fel: extern länkklass krävs för symbol "mypbp" på grund av attributet "dllexport"

So, what am I doing wrong?

Tried to add the option -std=f2003 and got the same error.

Pls advice.

I also want to add that if I remove C(Bind...) and change !GCC$ to !DEC$ I can compile...

I am so utterly confused.

Sincerely Jens

Tobias Burnus

unread,
Apr 24, 2013, 11:31:39 AM4/24/13
to
Does compiling with -shared work?

Tobias

jens.o...@gmail.com

unread,
Apr 24, 2013, 12:01:27 PM4/24/13
to
On Wednesday, April 24, 2013 5:31:39 PM UTC+2, Tobias Burnus wrote:
> Does compiling with -shared work?
>
>
>
> Tobias

No.
If I use $gfortran-4 -c -shared mango.f95 I get an error at C(Bind...). I get the same if I use $gfortan-4 -c -shared -std=f2003 mango.f95. If I comment C(Bind,...) I get an error external link needed to handle symbol due to dllexport attribute. So, I am lost. Can you help me? Pls also note I have inserted a space between dllexport and :: so it now says "dllexport ::mypbp"

Jens

e p chandler

unread,
Apr 24, 2013, 3:40:33 PM4/24/13
to
On Wednesday, April 24, 2013 12:01:27 PM UTC-4, jens.o...@gmail.com wrote:
> On Wednesday, April 24, 2013 5:31:39 PM UTC+2, Tobias Burnus wrote:
> > Does compiling with -shared work?
> No.
> If I use $gfortran-4 -c -shared mango.f95 I get an error at C(Bind...). I get the same if I use $gfortan-4 -c -shared -std=f2003 mango.f95. If I comment C(Bind,...) I get an error external link needed to handle symbol due to dllexport attribute. So, I am lost. Can you help me? Pls also note I have inserted a space between dllexport and :: so it now says "dllexport ::mypbp"

The -std=f2003 should make no difference. It just turns standards checking on.
maybe -dll would work instead of -shared. That's what I used when building 32 bit dll's under MinGW on 32 bit Windows.

--- e

Louis Krupp

unread,
Apr 25, 2013, 12:25:21 AM4/25/13
to
On Wed, 24 Apr 2013 09:01:27 -0700 (PDT), jens.o...@gmail.com
wrote:
Wild guess -- I haven't tried this myself:

Are you sure you want to use "-c" and "-shared" together? "-c"
creates .o (object) files, and "-shared" is what (as I recall) you
would use to create a .so (shared object) file. Something like:

gfortran -c f1.f95
gfortran -c f2.f95
...

gfortran -shared -o libf.so f1.o f2.o ...

might make sense.

To link the main program, something like:

gfortran -o m -L. -lf main.f95 (assuming libf.so is in your current
directory).

should work.

Hope this helps.

Louis

Erik Toussaint

unread,
Apr 30, 2013, 9:28:27 AM4/30/13
to
On 24-4-2013 12:53, jens.o...@gmail.com wrote:
> Hello!
> Im on a Windows x64 machine with i7 and Cygwin 4.5.3.
> In mango.f95 I have two subroutines and only those
> "
> subroutine MyAdd(z, a, b) C(Bind, name = "MyAdd")

I guess none of the other responders noticed this because it looks
almost right, but there's an error in this line.
This should read Bind(C, ...) instead of C(Bind, ...)

Correcting this makes the code compile (with gfortran 4.7.2), albeit
with a number of warnings for dummy arguments that may not be interoperable.

Apart from that, you're not using 'implicit none' in your code. Save
yourself a lot of unnecessary grief/lost time by always including that.

Erik.

0 new messages