- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I am trying to call fortran code in visual c++.
---------------------------------------------------------------------------
since my english is poor, I linked some webpages that I got helps
To test, I used a code from this link..
http://www.physiology.wisc.edu/comp/docs/notes/not017.html
In addition, to make a project & compile
Igot a help fromthis link
(the link use korean, but from the figures, I guess you can understand what I did
In addition, I use Visual studio 2005, so my configuration is a little bit diffrent.)
http://user.chollian.net/~gitae/programming/fortran/linking.htm
---------------------------------------------------------------------------------
Here is what I did in detail
1. I made a fotran project (the name is Fortran_test) witha static library option.
And, I specified output directory to my c++ project directory
(which is a ../Mixed_Lang_Test)
Both c++ and fortranRuntime Librariesare Debug Multithreaded.
2. I made a new fortran code.
SUBROUTINE FR1(N,M)
M=N*N
RETURN
END
INTEGER FUNCTION FF1(N)
FF1=N*N*N
RETURN
END
3I added a new project in the previous solution which is a console application and empty project.
the prj name is Mixed_Lang_Test.
4. I set some options..
Linker -> Input -> Fortrean_test.lib
C/C++ -> Code Generation -> Runtime Library: Debug Multithreaded.
5. I made a code in the Mixed_Lang_Test
#include
#include
extern "C"
{
void __stdcall FR1(int*,int *);
int __stdcall FF1(int *);
}
int main()
{
int n=10,nSq,nCube;
FR1(&n,&nSq);
//cout << "The square is:" << nSq << endl;
printf("the square is: %d \n",nSq);
nCube=FF1(&n);
//cout << "The Cube is:" << nCube << endl;
printf("the Cobe is: %d \n",nCube);
return 0;
}
6. I set the Mixed_Lang_Test as a start project and compile
7. Errors@!@@!!!
2>Mix_C.obj : error LNK2019: unresolved external symbol _FF1@4 referenced in function _main
2>Mix_C.obj : error LNK2019: unresolved external symbol _FR1@8 referenced in function _main
2>C:\Documents and Settings\mhkim\My Documents\Visual Studio 2005\Projects\Mixed_Lang_Test\Debug\Mixed_Lang_Test.exe : fatal error LNK1120: 2 unresolved externals
2>Build log was saved at "file://c:\Documents and Settings\mhkim\My Documents\Visual Studio 2005\Projects\Mixed_Lang_Test\Mixed_Lang_Test\Debug\BuildLog.htm"
2>Mixed_Lang_Test - 3 error(s), 0 warning(s)
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
---------------------------------------------------------------------------------------------------------------------------
How could I fix the errors???
Ahh..again, I am using visual studio 2005
and I recently downloaded the evaluation kit for fortran (v11??)
I will also add my project..
Plz help me out!!
Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intel Fortran does not use __stdcall anymore, like its predecessor Compaq Visual Fortran. Remove __stdcall (or substitute it with __cdecl) and you'll probably be fine (I didn't read thoroughly the rest of your message).
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intel Fortran does not use __stdcall anymore, like its predecessor Compaq Visual Fortran. Remove __stdcall (or substitute it with __cdecl) and you'll probably be fine (I didn't read thoroughly the rest of your message).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intel Fortran does not use __stdcall anymore,
ifort has supported iso_c_binding for a year now, so you should be able to find suitable web references, as well as the references on C interoperability in the ifort documentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intel Fortran does not use __stdcall anymore, like its predecessor Compaq Visual Fortran. Remove __stdcall (or substitute it with __cdecl) and you'll probably be fine (I didn't read thoroughly the rest of your message).
Hi~~
Thank you for your help..
After substituting it and setting some paths..
it works!!
And for static library..for some reasons (I don't know why..)
even if I didn't export anything..it worked!!
Thank you for all your help!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, you cannot "export" anything from a static library, only from dynamic ones. "Everything" in the static library is visible to the outer world. That's why they're bad in encapsulation.
The other way round, actually.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page