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

LINK ERROR: UNRESOLVED EXTERNAL

khhong7intel
Beginner
1,169 Views

Hello Steve,

I am using Visual Fortran V.9 with Visual Studio 2005.

Got link error for C call to a Fortran routine

and no link error for Fortran call to a C routine even though there is no C routine called.

It seems that there were no communications between C-side and Fortran library side.

The two files are at the end of this message.

Actually, I made the simple example using Compaq Fortran and Visual C++ v.6 and converted it into two parts (: proj and proj_lib) under one solution using Visual Fortran V.9 with Visual Studio 2005.

C part into proj and Fortran part into proj_lib as a static library.

I got link error:

error LNK2019: unresolved external symbol _mainprog referenced in function _WinMain@16

It worked before the break up into two parts with Compaq and VC++ v.6.

Thanks.

-K. Hong

Fortran-file f1.f

subroutine mainprog( )

!DEC$ ATTRIBUTES C :: mainprog&nbs p;

interface

subroutine f2c(n1)

!DEC$ ATTRIBUTES C :: f2c

integer n1

end subroutine

end interface

n=10

call f2c(n)

return

end

C-file c1.c

#include "stdafx.h"

extern void mainprog(void);

int APIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{

// TODO: Place code here.

mainprog();

return 0;

}

0 Kudos
8 Replies
Steven_L_Intel1
Employee
1,169 Views
Two things to check. 1) Make sure that you have installed VS2005 SP1. 2) Right click on the C++ project, select Dependencies. Ensure that the Fortran project is a dependent of the C++ project.
0 Kudos
khhong7intel
Beginner
1,169 Views

Steve,

I amdpwnloadingthe SP1.

In the mean time, I followed your advice. However,

I could not make the Fortran project is a dependent of the C++ project.

I got "circular dependency" warning.

For some reason, I could do the other way only

even though I made C side main and Fortran side static.

Any idea?

Thanks.

-K. Hong

0 Kudos
Steven_L_Intel1
Employee
1,169 Views
I don't know what you've done to create the circular dependence - I didn't think one could manage that using the menus. Make sure that the C++ project is the "startup project".
0 Kudos
khhong7intel
Beginner
1,169 Views

Hello Steve,

Here are the steps taken so far:

1. Double click the existing workspace of VC++ v.6.

2. Yes to allto "Convert and open this project?"

3. I got one project under one solution.

4. In the source file, I had f1.f and c1.c

5. Right clicked on the project and selected Extract Compaq Fortran Project Items

6. I chose The Visual C++ project at the question Select the project that will be the main project. Then OK.

7. Now I got a new Fortran static library project proj_lib.

8. Set the dependencies by right mouse click on Fortran static project or C-proj.

9. I get an error regardless of the dependency.

(a) Fortran depends on C : can not file ifconsol.lib

(b) C depends on Fortran: unresolved error for a Fortran function call from C.

Thanks.

-K. Hong

0 Kudos
Steven_L_Intel1
Employee
1,169 Views
Please create a ZIP of your project(s) and attach it to a report to Intel Premier Support. We'll take a look.
0 Kudos
Intel_C_Intel
Employee
1,169 Views

I've just sent the report to Premium Support with my project files uploaded.

-K. Hong.

0 Kudos
khhong7intel
Beginner
1,169 Views

Hello Steve,

Are you working on the problem?

Please let me know?

-K.Hong

0 Kudos
Steven_L_Intel1
Employee
1,169 Views
Yes, and I responded to you through Premier Support. Check to make sure that the email notifications don't get treated as spam in your mailbox.

The sample you sent me did not show a problem, but it was different from what you described here.
0 Kudos
Reply