Hi,

I am trying to call a simple fortran subroutine from a C++ interface and in turn call this C++ function from a C# application.

Here is the fortran subroutine :

program hello_world2
       implicit none
c
       call hello
       call hello

       end

       subroutine hello
       !DEC$ ATTRIBUTES DLLEXPORT :: hello
       implicit none
       character*32 text
       integer n , k
c
       text = 'Hello World'      
       end

C++ :

TestInterface.h :

#pragma once

using namespace System;

namespace TestInterface
{
	extern "C" __declspec(dllimport) void __stdcall hello(void);
	public ref class TestInterfaceClass
	{	
			

		public:
			//For making it singleton implementataion
			static TestInterfaceClass^ Instance = gcnew TestInterfaceClass();

			//Destructor to free the memory used
			~TestInterfaceClass();		
			int CallEngine();
            

		private:
			//For making it singleton implementataion
			TestInterfaceClass();
	};
}

TestInterface.cpp :

// This is the main DLL file.

#include "stdafx.h" 
#include "TestInterface.h"

using namespace TestInterface;

TestInterfaceClass::TestInterfaceClass()
{
	
}

TestInterfaceClass::~TestInterfaceClass()
{
	
}
int TestInterfaceClass::CallEngine()
{
	hello(); /* entry to the hello world program*/
	return 1;
}

The fortran library builds successfully , but when i try to refer this fortran lib in the AdditionalDependencies in the C++ project and build it I am getting the below error. I know i am missing something basic ,

Error 1 error LNK2028: unresolved token (0A000006) "extern "C" void __stdcall hello(void)" (?hello@@$$J10YGXXZ) referenced in function "public: int __clrcall TestInterface::TestInterfaceClass::CallEngine(void)" (?CallEngine@TestInterfaceClass@TestInterface@@$$FQ$AAMHXZ) TestInterface.obj HelloWorldTestInterface

ANy help or suggesstions are greatly welcome!

Thanks,
Keerti

Does fortran use the C style calling-convention for exporting or the Pascal?
...as in extern "Pascal"

[header]
void PASCAL _extern hello(void);

I'll have to check the syntax, byt you probably know what I mean.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.