Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
17060 Discussions

Common blocks and Visual C ++

Deleted_U_Intel
Employee
535 Views
Ok I've read the Mixed language programming section and tried
porting some legacy code with common blocks and C structures.
No luck. So I tried the examples and still had no luck.

Here is the link error from trying the examples. It looks like your basic name mangling.
What compiler option settings should I look at?

Compiling...
testcommon.cpp
Compiling Fortran...
F: est est1.for
Linking...
testcommon.obj : error LNK2001: unresolved external symbol 'double PI' (?PI@@3NA)
Debug/test1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

test1.exe - 2 error(s), 0 warning(s)

Here is the test code.

 
test1.for 
  PROGRAM TEST1 
      IMPLICIT NONE 
      INTEGER*4 I 
      INTEGER*4 J 
      REAL*8 PI 
      COMMON/ PI /PI 
      INTERFACE 
         INTEGER*4 FUNCTION TESTCOMMON(N) 
         INTEGER*4 N 
         END FUNCTION TESTCOMMON 
      END INTERFACE 
      PI = DATAN(1.0D0)*4.0D0 
      WRITE(*,*)' PI IN FORTRAN = ',PI 
      J = 5 
      I = TESTCOMMON(J) 
      WRITE(*,*)' I = ',I 
 
      END 
 
testcommon.h 
 
#ifndef TESTCOMMON_H 
#define TESTCOMMON_H 
extern double PI; 
#endif 
 
testcommon.cpp 
 
#include                 // input output streams header file 
#include  
#include  
#include 'testcommon.h'
 
extern 'C'{ int __stdcall TESTCOMMON(int*);}  
int __stdcall TESTCOMMON(int *n){ 
  int result_count = 1; 
  cout << endl; 
  cout << ' n = ' << *n << endl; 
  cout << ' PI = ' << PI <<  endl; 
  return(result_count); 
 
}
0 Kudos
1 Reply
Steven_L_Intel1
Employee
535 Views
You're almost there. Add 'C' to the extern declaration of PI in your C++ code.

Steve
0 Kudos
Reply