- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could anybody provide me with a simple walkthrough of how to link a c++ function with a visual fortran main program in visual studio 2003. I'm using Intel Visual fortran 9.0.
I would like to write the following program for example:
Fortran (hello.f):
-------------------
program hello
call helloworld()
stop
end program hello
C++ (helloworld.c):
-------------------
void helloworld()
{
printf("Hello World ");
}
In all my previous attempts, I get the unresolved reference error in when trying to compile the "solution".
Thanks,
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
extern "C" void HELLOWORLD ()
I question whether you want to tackle writing to stdout using C source embedded in a C++ function called from Fortran, if you aren't willing to read about the difficulties.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the help. I finally got my program working.
- 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
Hi, pal24,
After I tried you helloworld code, error comes out:
error LNK2019: unresolved external symbol _HELLWORLD referenced in function _MAIN
Any changes in project properties
Thanks
Eric
- 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
sorry it was _HELLOWORLD
I generated test fortran project "test" than add "hellow.cpp" into the project
All the configrations are default and build the solution was not successed
here is my code:
program test ! test.f90
implicit none
! Variables
call helloworld();
! Body of test
end program test
///// "hellow.cpp""
extern "C" void helloworld();
void helloworld()
{
printf("hello world
");
}
/////build output
------ Rebuild All started: Project: test, Configuration: Debug Win32 ------
Deleting intermediate files and output files for project 'test', configuration 'Debug|Win32'.
Compiling with Intel Fortran 9.0...
test.f90
Linking...
test.obj : error LNK2019: unresolved external symbol _HELLOWORLD referenced in function _MAIN__
Debug/test.exe : fatal error LNK1120: 1 unresolved externals
Build log written to "file://C:Documents and SettingsEricMy Documents estDebugBuildLog.txt"
test build failed.
---------------------- Done ----------------------
Rebuild All: 0 succeeded, 1 failed, 0 skipped
It seems to me that it doesn't compile the c file (hellow.cpp).
any thought please, thanks
Eric
- 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
I did it exactly same.
error comes out: cannot open "ctest.lib"
When I add new c++ project, I choose win32 (console) project with static lib
and then add a hellow.cpp file into c++ project.
Do we need main() in c++ project?
Eric
- 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
Tom,
Thanks a lot
Mine is working now.
Eric

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