473,394 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Troubles on linking C++ with Fortran at VS 2005

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 program possible, such as c++ calling a c = a + b fortran function. I am trying this on a VS 2005 c++ along with an Intel Visual Fortran.
I have been looking for some answers on this forum and I've made these routines:

c++--------
#include <stdio.h>
extern "C" {int fort(int*, int*);}
int main ()
{
int a, b, c;
a = 2;
b = 3;
c = fort(&a,&b);
return c;
}
---- end c++
fortran --------
INTEGER FUNCTION FORT (A,B)
!DEC$ ATTRIBUTES DLLEXPORT :: FORT
!DEC$ ATTRIBUTES ALIAS :'FORT' :: FORT
!DEC$ ATTRIBUTES REFERENCE :: A,B

IMPLICIT NONE
INTEGER, INTENT (IN) :: A,B
FORT = A + B
END FUNCTION FORT
----end fortran

They both compile without problems, but the linking step breaks on an LNK2019 error: unresolved external symbol _fort referenced in function _main.

I woud really appreciate if one could help.

Thanks a lot,
grspinto
May 18 '09 #1
3 2035
JosAH
11,448 Expert 8TB
Either make that function name FORT in your C code or make it fort in your Fortran code; both C and the linker are case sensitive. If that doesn't work try prepending an underscore _ in front of the Fortran name as well.

kind regards,

Jos
May 19 '09 #2
Dear Jos,

Thank you very much. I followed your both advices and the program worked pretty well.

Best regards,
grspinto
May 19 '09 #3
What settings must be set for the c++ program to compile? Includes?
Oct 6 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
2
by: sunil | last post by:
Hi, We have lot of c and fortran archive libraries that have complex dependencies. We have different server tasks that use some of these libraries. We have developed a tool inhouse that links...
13
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...
2
by: | last post by:
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)....
10
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...
52
by: Nomad.C | last post by:
Hi I've been thinking of learning Fortran as number crunching kinda language for my Physics degree......but then looking around the internet, people are saying that the libraries/ Algorithms once...
0
by: xieml2007 | last post by:
Dear Madam or Sir, I encountered one problem which is quite similiar to the discussions launched at the web site: http://www.thescripts.com/forum/thread280324.html
9
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 ...
0
by: JohnIdol | last post by:
VC++6 to VC++2003 - linking troubles -------------------------------------------------------------------------------- Hi All, I successfully ported an application from VC++6 to VS2003. Solved...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...

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.