0

I was trying to compile a mixed programming lanaguage (C++/Fortran) sample project provided by Intel Compiler 2013 under Eclipse IDE. I can run this project successfully under Visual Studio IDE (on Windows OS system), but I have not figured out how to run the same project under Eclipse on Linux. The configuration of linking the Fortran to the C++ project in Eclipse IDE is the main issue that troubles me.

Could anyone please tell me how to link these two projects? Thanks. The output should be simple "Testing...123."

Li


The source codes are as follows: (1) the main program, fmain.f90

PROGRAM fmain
USE, INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
INTERFACE
SUBROUTINE c_routine (int_arg, str_in, str_out, str_out_len) BIND(C)
IMPORT ! Use declarations from host  
INTEGER(C_INT), VALUE,INTENT(IN) :: int_arg
    CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(IN) :: str_in
    CHARACTER(KIND=C_CHAR), DIMENSION(*), INTENT(OUT) :: str_out  
    INTEGER(C_INT), VALUE, INTENT(IN) :: str_out_len
END SUBROUTINE c_routine
END INTERFACE
CHARACTER(80) OUTPUT_TEXT
INTEGER IN_ARG, OUTPUT_LEN
CHARACTER(80) INPUT_TEXT
INPUT_TEXT = "Testing..."//C_NULL_CHAR 
IN_ARG = 123
CALL c_routine (IN_ARG, INPUT_TEXT, OUTPUT_TEXT, LEN(OUTPUT_TEXT))
OUTPUT_LEN = INDEX(OUTPUT_TEXT," ")
IF (OUTPUT_LEN == 0) OUTPUT_LEN = len(OUTPUT_TEXT)
WRITE (*,*) OUTPUT_TEXT(1:OUTPUT_LEN)
END

(2) csub.cpp

#include <stdio.h>
extern "C" void c_routine (
    int int_arg, // integer to convert
    char* input_text, // text to prepend to converted integer
    char* output_text, // output buffer
    int output_text_len // length of output buffer
    )

{
sprintf_s(output_text,output_text_len,"%s%i ",input_text,int_arg);
}
GameDroids
  • 5,584
  • 6
  • 40
  • 59
Li-Pin Juan
  • 1,156
  • 1
  • 13
  • 22
  • A possible workaround: Is there an option to create a makefile project? – Stefan Feb 11 '14 at 12:18
  • @Stefan, I knew this method you suggested but I am just curious about how to make Eclipse IDE be able to handle this mixed language project as visual studio did on my desktop (it takes only a few steps to tell visual studio to perform the mixed language compilation). Thanks for replying to my question. – Li-Pin Juan Feb 11 '14 at 14:40

0 Answers0