Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Simple mixed Fortran/C++ project

alphajet
Beginner
409 Views
Hi, I've been usig Intel visual fortran for a while, but I don't have strong background in using C++, so I was trying to make a simple example to learn about linking, I've been trying to call a simple Fortran routine from C++ (I intend to do the opposite anyways, to use CUDA in my intel visual fortran projects)
[cpp]#include #include #include #include #include using namespace std; //Fortran subroutine definition "translated" to C++ extern "C" { void matrix_multiply(double *A, int *rows_A, int *cols_A, double *B, int *rows_B, int *cols_B, double *C, int *rows_C, int *cols_C, double *time); } void pause() { cout << "Press to continue . . ."; // Clears the input stream. cin.clear(); /* This will tell the console to wait for the maximum number of characters that can be entered into the input stream or for a newline character, hence, the key. */ cin.ignore(numeric_limits::max(), '\n'); /* This has been tested in various programs throughout my C++ course in college and has worked every time. */ } //Print matrix V(rows, cols) storage in column-major format void print_matrix(vector const &V, int rows, int cols) { for(int i = 0; i < rows; ++i){ for(int j = 0; j < cols; ++j){ //std::cout << V[j * rows + i] << " "; printf("%2.3f ",V[j * rows + i]) ; } std::cout << std::endl; } std::cout << std::endl; } int main(void) { size_t N = 1000 ; // no. rows size_t M = 1000 ; // no. columns vector A(N * N), B(N * N), C(N * N); //Fill A and B (column major format) for (unsigned int i=0; i

so I firstly used a command prompt approach:

ifort -c fprog.f90
cl /EHsc fprog.obj cprog.cpp

with both fprog.f90 and cprog.cpp in the same directory, it worked fine

but since this approach was intended for training, I then attempted to make a mixed solution in MS visual studio 2010, with the fprog.f90 file in Fortran project & cprog.cpp in a C++ project, it seems like the C++ project can't see the compiled object file of the fprog.f90, when I try to build the whole soultion it throws the following error messages:

Error 1 error LNK2019: unresolved external symbol _MAIN__ referenced in function _main libifcoremt.lib(for_main.obj)

Error 2 fatal error LNK1120: 1 unresolved externals Debug\\F90P.exe

Error 3 error LNK2019: unresolved external symbol _matrix_multiply referenced in function _main c:\\Users\\bahaa\\documents\\visual studio 2010\\Projects\\mixingTest_1\\mixingTest_1\\cprog.obj CppP

Error 4 error LNK1120: 1 unresolved externals c:\\users\\bahaa\\documents\\visual studio 2010\\Projects\\mixingTest_1\\Debug\\CppP.exe 1 1 CppP
0 Kudos
6 Replies
mecej4
Honored Contributor III
409 Views
You have not told VS if/how the two projects are related. Therefore, it is to be expected that they are considered independent.
0 Kudos
alphajet
Beginner
409 Views
Actually I've never done so before, and I've been researching but to no avail yet, so I'd appreciate it so much if you could let me know how to implement this is VS 2010.
Thanks in advance
0 Kudos
FortranFan
Honored Contributor II
409 Views
As mecej4 points out, you may need to specify project dependencies for your mixed language solution. I find it easier to specify this in the Visual Studio IDE by going to Project->Project Dependencies and specifying the dependencies and build order.
0 Kudos
alphajet
Beginner
409 Views
Firstly, thanks for your prompt reply.
The C++ project is: CppP
The Fortran project is: F90P
I've already done that, I opened project dependencies in CppP and checked on F90P as a dependency, and the build order was:
1- F90P
2- CppP
but I'm getting the mentioned errors
0 Kudos
FortranFan
Honored Contributor II
409 Views
Can you first confirm your Visual Studio setup is configured for mixed language solutions as explained on this Intel website link:

http://software.intel.com/en-us/articles/configuring-visual-studio-for-mixed-language-applications/
0 Kudos
alphajet
Beginner
409 Views
Thanks for your prompt reply, I'll try this as soon as I can and I'll post the feedback, thanks again
0 Kudos
Reply