473,563 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Troubles on linking C++ with Fortran at VS 2005

2 New Member
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 2040
JosAH
11,448 Recognized Expert MVP
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
grspinto
2 New Member
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
2581
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 fortran program using f2py. I then start an embedded python interpreter in c code which I link against the fortran program. I invoke the fortran...
2
1676
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 server tasks by continuously iterating until it figures out the correct library order. Recently we introduced some C++ legacy libraries. I am completely...
13
2511
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 assume contiguous space). Now I am having problem again. In order to show the problem I have created small program and this time there is no data...
2
7236
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). 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...
10
2664
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 .NET2003. also, when I do not try to link the fortran library (just to see if that was the cause), it builds the exe without any problems. i don't...
52
5065
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 used for number crunching is now slowly converting into C, so do you think I should stick with C, since I know C already, or should I proceed...
0
3966
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
3686
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 /opt/gcc_4.1.2/solaris10/lib/ libgfortran.a(write.o) strtof /opt/gcc_4.1.2/solaris10/lib/...
0
1437
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 compiling issues but now I am sticking with serious Linking troubles. I got a bunch of:
0
7664
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
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 we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.