- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friends:
I build a small working prototype of a call from (Vuisual) C++ to Intel fortran. Then I tried to put in to my own project (which is very large). I am getting he symbol mismatch error:
"LNK2001 unresolved external symbol _SHOW
I inserted the following line in my .cpp file calling the function SHOW:
extern "C" float SHOW(int* in, float* out);
or
extern "C" { float SHOW(int* in, float* out); }
and then I created a static fortran library (which build succesfully) containing:
function SHOW(IN,OUT) BIND(C) use,intrinsic::ISO_C_BINDING IMPLICIT NONE REAL(C_FLOAT) :: SHOW INTEGER(C_INT) :: IN REAL(C_FLOAT) :: OUT WRITE(*,90) IN 90 FORMAT(/," from FORTRAN: in value = ",I4) OUT=199.0 SHOW=1999.0; end function SHOW
then I pointed the linker to see my generated library in the correct directory. I checked the dependencies between CPP and Fortran. I am still getting the error. My VS 2017 settings must be OK as my prototype project builds.
Any ideas how I should go about isolating this problem.
I. Konuk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran is case-insensitive, so the function name 'SHOW' appears as 'show'. Change the C++ code to this:
#include <stdio.h> extern "C" float show(int* in, float* out); int main(void) { int in = 123; float out; show(&in, &out); printf("out: %f\n",out); return(0); }
I tested this simply by creating a .obj file from the Fortran code:
ifort -c show.f90
then linking this to main.cpp:
cl -c main.cpp show.obj
Your library should behave the same way.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran is case-insensitive, so the function name 'SHOW' appears as 'show'. Change the C++ code to this:
#include <stdio.h> extern "C" float show(int* in, float* out); int main(void) { int in = 123; float out; show(&in, &out); printf("out: %f\n",out); return(0); }
I tested this simply by creating a .obj file from the Fortran code:
ifort -c show.f90
then linking this to main.cpp:
cl -c main.cpp show.obj
Your library should behave the same way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
gib wrote:Fortran is case-insensitive, so the function name 'SHOW' appears as 'show'. Change the C++ code to this: ..
Or another option will be to use the Fortran standard-supported NAME parameter with BIND:
extern "C" { float SHOW(int* in, float* out); }
function SHOW(IN,OUT) bind(C, name="SHOW")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much my friend. That was it! I should have paid attention. Inspecting the .OBJ file shows what you indicated.
By the way, I like your second suggestion too to make sure that I do not fell into a similar trap again by explicitly declaring a case sensitive name.
Cheers.
I. Konuk
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page