473,498 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help with linking vs7 c++ to fortran dll

Help! I'm new to c++, and am breaking my teeth on MS Visual C++ (bundled
within Visual Studio .NET 2003). Am trying to link simple c++ code to
fortran dlls created in Compaq Visual Fortran (v6.1). Posts concerning
this topic are common, but none of the posted solutions I've tried work
correctly with the above software. The linker can't seem to find the dll
(reports 'unresolved external symbol __imp__IMSL_FUN@8'; IMSL_FUN.dll is
the f77 library), although the library exists, compiled fine within CVF,
and its directory is declared in Visual C++'s Project|Properties
|Linker|Additional Library Directories. I'm hoping this is a simple
problem. The f77 and c++ source code is extremely simple and is included
below along with both the CVF and VS7 C++ compiler/linker messages,

! ------------------ begin f77
! imsl_fun.for
!
! FUNCTIONS/SUBROUTINES exported from IMSL_FUN.dll:
! IMSL_FUN - subroutine
!
double precision function IMSL_FUN(A,B)

! Expose subroutine IMSL_FUN to users of this DLL
!
!DEC$ ATTRIBUTES DLLEXPORT::IMSL_FUN

implicit none
double precision A, B
IMSL_FUN = A / B
return
end

! ------------------ end f77

Compiling Fortran...
C:\home\rolf\local\lib\imsl_fun\IMSL_FUN.for
Linking...
Creating library Debug/imsl_fun.lib and object Debug/imsl_fun.exp

imsl_fun.dll - 0 error(s), 0 warning(s)

// ------------------ begin c++
// testIMSL.NET.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
extern "C" __declspec(dllimport) short __stdcall IMSL_FUN(double* a, double*
b);

int _tmain(int argc, _TCHAR* argv[])
{
double y = -1.e-12;
double a, b;
a = 1.;
b = 1.;
std::cout << "Before calling IMSL_FUN y = " << y << std::endl;
y = IMSL_FUN(&a, &b);
std::cout << "After calling IMSL_FUN y = " << y << std::endl;
return 0;
}
// ------------------ end c++

Compiling...
testIMSL.cpp
Linking...
testIMSL.obj : error LNK2019: unresolved external symbol __imp__IMSL_FUN@8
referenced in function _main
Debug/testIMSL.exe : fatal error LNK1120: 1 unresolved externals

testIMSL.NET - 2 error(s), 0 warning(s)
Any ideas?
Nov 17 '05 #1
2 7222
For starters let me say that I know nothing about modern Fortran (having not
done any since the early 80's).

It sounds like you're missing the import library for the Fortran DLL in your
C++ project. There's no need (or value) in having the DLL itself specified
in the C++ project at all. Rather, you should have gotten a .lib file that
specifies the exported symbols from the DLL. Make sure that .lib
(imsl_fun.lib) is included in the additional library dependencies. Note
that you need to mention the library explicitly, not just the directory
where it resides.

If you've already done that (it's not clear from your description below,
since you only explicitly mention the DLL itself), then your problem is one
of naming convention. To resolve that problem, you need to become best
friends with the dumpbin utility that's included with Visual Studio.

Run dumpbin /exports IMSL_FUN.DLL to see the names of the exported
functions. You'll probably have no problem identifying your function (as
there's a good chance it's the only exported name). Off hand, I'm to to
guess that it's probably named "IMSL_FUN", while the C++ compiler wants it
to be named IMSL_FUN@8. If the Fortran function is truly compiled for the
__stdcall calling convention, then you have to resolve the name conflict by
generating a new import library that renames the function. On the other
hand, it might be that the options specified to the Fortran compiler aren't
correct and the function isn't really __stdcall.

Without having Compaq Visual Fortran, that's about the most help I can
offer. If you learn more details using dumpbin and still aren't able to
resolve the problem, post again.

-cd

rs*****@earthlink.net wrote:
Help! I'm new to c++, and am breaking my teeth on MS Visual C++
(bundled within Visual Studio .NET 2003). Am trying to link simple
c++ code to fortran dlls created in Compaq Visual Fortran (v6.1).
Posts concerning
this topic are common, but none of the posted solutions I've tried
work correctly with the above software. The linker can't seem to find
the dll (reports 'unresolved external symbol __imp__IMSL_FUN@8';
IMSL_FUN.dll is the f77 library), although the library exists,
compiled fine within CVF, and its directory is declared in Visual
C++'s Project|Properties
Linker|Additional Library Directories. I'm hoping this is a simple

problem. The f77 and c++ source code is extremely simple and is
included below along with both the CVF and VS7 C++ compiler/linker
messages,

! ------------------ begin f77
! imsl_fun.for
!
! FUNCTIONS/SUBROUTINES exported from IMSL_FUN.dll:
! IMSL_FUN - subroutine
!
double precision function IMSL_FUN(A,B)

! Expose subroutine IMSL_FUN to users of this DLL
!
!DEC$ ATTRIBUTES DLLEXPORT::IMSL_FUN

implicit none
double precision A, B
IMSL_FUN = A / B
return
end

! ------------------ end f77

Compiling Fortran...
C:\home\rolf\local\lib\imsl_fun\IMSL_FUN.for
Linking...
Creating library Debug/imsl_fun.lib and object Debug/imsl_fun.exp

imsl_fun.dll - 0 error(s), 0 warning(s)

// ------------------ begin c++
// testIMSL.NET.cpp : Defines the entry point for the console
application. //

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
extern "C" __declspec(dllimport) short __stdcall IMSL_FUN(double* a,
double* b);

int _tmain(int argc, _TCHAR* argv[])
{
double y = -1.e-12;
double a, b;
a = 1.;
b = 1.;
std::cout << "Before calling IMSL_FUN y = " << y << std::endl;
y = IMSL_FUN(&a, &b);
std::cout << "After calling IMSL_FUN y = " << y << std::endl;
return 0;
}
// ------------------ end c++

Compiling...
testIMSL.cpp
Linking...
testIMSL.obj : error LNK2019: unresolved external symbol
__imp__IMSL_FUN@8 referenced in function _main
Debug/testIMSL.exe : fatal error LNK1120: 1 unresolved externals

testIMSL.NET - 2 error(s), 0 warning(s)
Any ideas?

Nov 17 '05 #2
Carl --
Thanks very much for your reply -- explicitly specifying the .lib file
dependency, and correcting for name decoration by making the following
changes to the f77 export declaration fixed it:

!DEC$ ATTRIBUTES DLLEXPORT :: IMSL_FUN
!DEC$ ATTRIBUTES ALIAS:'_IMSL_FUN@8' :: IMSL_FUN

Thanks again!
--Rolf

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:ez**************@tk2msftngp13.phx.gbl...
For starters let me say that I know nothing about modern Fortran (having not done any since the early 80's).

It sounds like you're missing the import library for the Fortran DLL in your C++ project. There's no need (or value) in having the DLL itself specified in the C++ project at all. Rather, you should have gotten a .lib file that specifies the exported symbols from the DLL. Make sure that .lib
(imsl_fun.lib) is included in the additional library dependencies. Note
that you need to mention the library explicitly, not just the directory
where it resides.

If you've already done that (it's not clear from your description below,
since you only explicitly mention the DLL itself), then your problem is one of naming convention. To resolve that problem, you need to become best
friends with the dumpbin utility that's included with Visual Studio.

Run dumpbin /exports IMSL_FUN.DLL to see the names of the exported
functions. You'll probably have no problem identifying your function (as
there's a good chance it's the only exported name). Off hand, I'm to to
guess that it's probably named "IMSL_FUN", while the C++ compiler wants it
to be named IMSL_FUN@8. If the Fortran function is truly compiled for the
__stdcall calling convention, then you have to resolve the name conflict by generating a new import library that renames the function. On the other
hand, it might be that the options specified to the Fortran compiler aren't correct and the function isn't really __stdcall.

Without having Compaq Visual Fortran, that's about the most help I can
offer. If you learn more details using dumpbin and still aren't able to
resolve the problem, post again.

-cd

rs*****@earthlink.net wrote:
Help! I'm new to c++, and am breaking my teeth on MS Visual C++
(bundled within Visual Studio .NET 2003). Am trying to link simple
c++ code to fortran dlls created in Compaq Visual Fortran (v6.1).
Posts concerning
this topic are common, but none of the posted solutions I've tried
work correctly with the above software. The linker can't seem to find
the dll (reports 'unresolved external symbol __imp__IMSL_FUN@8';
IMSL_FUN.dll is the f77 library), although the library exists,
compiled fine within CVF, and its directory is declared in Visual
C++'s Project|Properties
Linker|Additional Library Directories. I'm hoping this is a simple

problem. The f77 and c++ source code is extremely simple and is
included below along with both the CVF and VS7 C++ compiler/linker
messages,

! ------------------ begin f77
! imsl_fun.for
!
! FUNCTIONS/SUBROUTINES exported from IMSL_FUN.dll:
! IMSL_FUN - subroutine
!
double precision function IMSL_FUN(A,B)

! Expose subroutine IMSL_FUN to users of this DLL
!
!DEC$ ATTRIBUTES DLLEXPORT::IMSL_FUN

implicit none
double precision A, B
IMSL_FUN = A / B
return
end

! ------------------ end f77

Compiling Fortran...
C:\home\rolf\local\lib\imsl_fun\IMSL_FUN.for
Linking...
Creating library Debug/imsl_fun.lib and object Debug/imsl_fun.exp

imsl_fun.dll - 0 error(s), 0 warning(s)

// ------------------ begin c++
// testIMSL.NET.cpp : Defines the entry point for the console
application. //

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
extern "C" __declspec(dllimport) short __stdcall IMSL_FUN(double* a,
double* b);

int _tmain(int argc, _TCHAR* argv[])
{
double y = -1.e-12;
double a, b;
a = 1.;
b = 1.;
std::cout << "Before calling IMSL_FUN y = " << y << std::endl;
y = IMSL_FUN(&a, &b);
std::cout << "After calling IMSL_FUN y = " << y << std::endl;
return 0;
}
// ------------------ end c++

Compiling...
testIMSL.cpp
Linking...
testIMSL.obj : error LNK2019: unresolved external symbol
__imp__IMSL_FUN@8 referenced in function _main
Debug/testIMSL.exe : fatal error LNK1120: 1 unresolved externals

testIMSL.NET - 2 error(s), 0 warning(s)
Any ideas?


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2575
by: Jeff Hagelberg | last post by:
I'm trying to create a python module which can be used by a python interpreter embedded inside a fortran program I have. To do this, I first created python wrappers for all the functions in my...
1
1633
by: Pakea | last post by:
Dear all, I'm trying compile MSV .NET with IFC v8. In my c++ source I write .... extern "C" void _stdcall ROUTINE (...) ... main {....
13
2492
by: NM | last post by:
Sometimes ago I was having a problem in linking between C++ and Fortran program. That was solved (using input from this newsgroup) using the Fortran keyword "sequence" with the derived types (to...
4
3906
by: Kevin Wan | last post by:
Hi, I have encountered a linking problem while using g++ to link our product. There are Fortran, C, C++ code in our product. The error listed below: /usr/bin/ld: final link failed: Bad value...
10
2651
by: Julian | last post by:
I get the following error when i try to link a fortran library to a c++ code in .NET 2005. LINK : fatal error LNK1104: cannot open file 'libc.lib' the code was working fine when built using...
22
4685
by: James Stroud | last post by:
Hello All, This is annoying. I am trying to build scipy right now but every .so file requires my adding "-lpython2.5 -lpthread -lm -lutil -ldl -shared" to the ld flags. Main Question: When...
3
1961
by: Matt | last post by:
Hey guys. I'm currently working through a number of C programming exercises to get me up to speed with the syntax. Before now I have been using Fortran and I've found Plato3 in Windows to be an...
9
3682
by: a-lbi | last post by:
I use gcc compiler (version 2.8.1). During linking I get the following error message: Undefined first referenced symbol in file log10l ...
3
2038
by: grspinto | last post by:
Hi there, I am not very used to programming and I am trying to call a Fortran function/subroutine with a C++ main program, but it haven't worked. Untill now, I've been trying to build the easiest...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.