I am trying to compile use a Fortran static library file with a C++ program but am getting unresolved external errors
I build the static library file using x64
subroutine bar_ftn ( len_input_file, input_file ) bind( c )
use, intrinsic :: iso_c_binding, only : c_int
implicit none
integer(c_int), value, intent(in) :: len_input_file
character(len=1), intent(in) :: input_file(len_input_file)
! Local declarations (copy c char array into fortran character)
character(len=len_input_file) :: infile
integer :: i
print *, "in bar_ftn"
print *, len_input_file
do i=1,len_input_file
end do
end subroutine bar_ftn
the C++ program is
#include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
extern "C" void bar_ftn ( int flag_len, char* flag );
static void
DisplayUsage(char* programName);
int main(int argc, char *argv[])
{
char ctext[]="helloworld abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz";
int ctext_len=sizeof(ctext);
//Call the Fortran
bar_ftn( ctext_len, ctext );
return 0;
}
but when I compile the C++ program I get the following errors
Error 2 error LNK1120: 1 unresolved externals D:\temp\ConsoleApplication1\Debug\ConsoleApplication1.exe 1 1 ConsoleApplication1
Error 1 error LNK2019: unresolved external symbol _bar_ftn referenced in function _main D:\temp\ConsoleApplication1\ConsoleApplication1\main.obj ConsoleApplication1
3 IntelliSense: cannot open source file "stdafx.h" d:\temp\main.cpp 1 1 ConsoleApplication1
could you pleat tell me what I am doing wrong?