Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. SUBROUTINE TESTCPP ( II, JJ, KK, LL )
  2. INCLUDE 'COMON4.INS'
  3.  
  4. integer*4, external :: CPPFUNCTION
  5.  
  6. INTEGER a, b, c, test
  7.  
  8. IF (.NOT. IFLAG) RETURN
  9.  
  10. a = ICON(II)
  11. b = ICON(II + 1)
  12. test = CPPFUNCTION( a , b, c )
  13. WRITE ( ITERM, * ) 'C = ', c
  14. RETURN
  15. END
  16.  
  17. extern "C" {
  18. void _CPPFUNCTION(int a, int b, int *c);
  19. }
  20.  
  21. void _CPPFUNCTION(int a, int b, int *c) {
  22. *c = a + b;
  23. }
  24.  
  25. cl /nologo /MD /c /W3 /O2 /FD /EHsc /errorReport:prompt /D"MSWINDOWS" /D"WIN32" ^
  26. /D"_WINDOWS" /D"NDEBUG" "cpp_code.cpp"
  27.  
  28. IFORT /nologo /Od /Oy- /assume:buffered_io /traceback /libs:dll /threads /c /Qip ^
  29. /extend_source:132 /noaltparam /fpscomp:logicals /warn:nodeclarations ^
  30. /warn:unused /warn:truncated_source /Qauto /Op /iface:cvf /define:DLLI ^
  31. /include:"C:Program Files (x86)PTIPSSE32PSSLIB" ^
  32. /object:"fort_code.OBJ" ^
  33. "fort_code.f"
  34.  
  35. lib /out:fort_cpp.lib fort_code.obj cpp_code.obj
  36.  
  37. ifort /nologo /assume:buffered_io /traceback /libs:dll /threads /c /Qip /extend_source:132 /noaltparam /fpscomp:logicals /Qprec /warn:declarations /warn:unused /warn:truncated_source /Qauto /fp:source /iface:cvf /define:DLLI /include:"C:Program Files (x86)PTIPSSE32PSSLIB" /object:"C:tempINIT_62028911hw2ap_conec.obj" /module:"C:tempINIT_620289" "11hw2ap_conec.f"
  38.  
  39.  
  40. ifort /nologo /assume:buffered_io /traceback /libs:dll /threads /c /Qip /extend_source:132 /noaltparam /fpscomp:logicals /Qprec /warn:declarations /warn:unused /warn:truncated_source /Qauto /fp:source /iface:cvf /define:DLLI /include:"C:Program Files (x86)PTIPSSE32PSSLIB" /object:"C:tempINIT_62028911hw2ap_conet.obj" /module:"C:tempINIT_620289" "11hw2ap_conet.f"
  41.  
  42.  
  43. link /INCREMENTAL:NO /NOLOGO /DLL /SUBSYSTEM:WINDOWS /MACHINE:X86 /ERRORREPORT:PROMPT @"C:tempINIT_620289linkfilestod9p1.txt" /OUT:"C:tempINIT_62028911hw2ap_dsusr.dll" /map:"C:tempINIT_62028911hw2ap_dsusr.map"
  44.  
  45. fort_cpp.lib(fort_code.obj) : error LNK2019: unresolved external symbol _CPPFUNCTION@12 referenced in function _TESTCPP
  46. C:tempINIT_62028911hw2ap_dsusr.dll : fatal error LNK1120: 1 unresolved externals
  47.  
  48. ERROR during link(1)... Aborted
  49.  
  50. SUBROUTINE CONEC
  51. C
  52. INCLUDE 'COMON4.INS'
  53. C
  54. CALL TESTCPP ( 55791, 0, 0, 0)
  55. C
  56. RETURN
  57. END
  58. SUBROUTINE CONET
  59. C
  60. INCLUDE 'COMON4.INS'
  61. C
  62. IF (.NOT. IFLAG) GO TO 9000
  63. C
  64. C NETWORK MONITORING MODELS
  65. C
  66. C
  67. 9000 CONTINUE
  68. C
  69. RETURN
  70. END
  71.  
  72. program example
  73.  
  74. use iso_c_binding
  75. implicit none
  76.  
  77. interface
  78. integer(c_int) function add1(x) bind(C,name="add1")
  79. !DEC$ ATTRIBUTES DLLEXPORT :: add1
  80. use iso_c_binding
  81. integer(c_int), value :: x
  82. end function add1
  83. end interface
  84.  
  85. call callingadd1()
  86. contains
  87. subroutine callingadd1()
  88. write(*,*) '1+1=', add1(1)
  89. end subroutine callingadd1
  90. end program example
  91.  
  92. extern "C" {
  93. int add1(int x);
  94. }
  95.  
  96. int add1(int x) {
  97. return(x+1);
  98. }
  99.  
  100. subroutine callingadd1() bind(C, name="callingadd1")
  101. !DEC$ ATTRIBUTES DLLEXPORT :: callingadd1
  102. use iso_c_binding
  103. implicit none
  104. interface
  105. integer(c_int) function add1(x) bind(C,name="add1")
  106. !DEC$ ATTRIBUTES DLLEXPORT :: add1
  107. use iso_c_binding
  108. integer(c_int), value :: x
  109. end function add1
  110. end interface
  111. write(*,*) '1+1=', add1(1)
  112. end subroutine callingadd1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement