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

Trouble using a fortran static library in C++

Juan_David_V_
Beginner
430 Views

Hello everyone.

I have a fortran static library which I need to call from C++. I added the library to the C++ project and when I run the programI get this:

error LNK2019: símbolo externo Coresolver sin resolver al que se hace referencia en la función main.

 

This is my code:

extern "C"{
	void Coresolver
		(int *Puntosnp,
		int *PuntosKr,
		double *Sw,
		double *Kro,
		double *Krw,
		double *Vp,
		double *Npcalc,
		double *DeltaPcalc);
}


int main()
{
	int Puntosnp = 2;
	int PuntosKr = 2;
	double Sw[2];
	double Krw[2];
	double Kro[2];
	double Vp[2];
	double Npcalc[2];
	double DeltaPcalc[2];

	Sw[0] = 0.2, Sw[1] = 0.8;
	Krw[0] = 0.0, Krw[1] = 0.8;
	Kro[0] = 0.8, Kro[1] = 0.0;
	Vp[0] = 0.2, Vp[1] = 1.0;
	Npcalc[0] = 0.0, Npcalc[1] = 0.0;
	DeltaPcalc[0] = 0.0, DeltaPcalc[1] = 0.0;

	Coresolver(&Puntosnp, &PuntosKr, Sw, Kro, Krw, Vp, Npcalc, DeltaPcalc);
	return 0;
}

 

0 Kudos
3 Replies
mecej4
Honored Contributor III
430 Views

The names of Fortran external symbols are subject to "decoration", i.e., changing of case and adding an underscore as a prefix, depending on whether the code is for a 32-bit CPU or a 64-bit CPU. If you did not use the ISO-C interoperability features or the "legacy" directives when you built the Fortran library, the C name should be  "CORESOLVER" for 64-bit and "_CORESOLVER" for 32-bit. For details, see the Intel Fortran documentation.

0 Kudos
Juan_David_V_
Beginner
430 Views

Hi.

Thnaks, that worked. But I´m having other problem, Npcalc and DeltaPcalc are arrays and when I call CORESOLVER they should change their values but they remain in value cero.

0 Kudos
mecej4
Honored Contributor III
430 Views

You will have to show the Fortran source code of CORESOLVER (or at least the parts of it that set Npcalc and DeltaPcalc) in order for us to see what could have happened.

0 Kudos
Reply