Tune Visual Studio Fortran,Multi Linking, error LNK2019

Tune Visual Studio Fortran,Multi Linking, error LNK2019

Hello,

It' s been a few time that i don't poste.

I am working, in interprocedural programming for Fortran with C.

I had a big Fortran programm who "drive" all the programm.

There is the toto.fortran programm, a Wrapper.C wich is a C programm; and a C++ programm Archi.

I created : ARCHI-RLD-1D-Wrap-3-.obj  which is the C++ object compiled with Intel C++

I created the : WRAPPER-3-.obj  which is the C object, compiled with the Intel C++; compiled as C programm

And i had the big Fortran project which I had the two object.

The Fortran "call" WRAPPER-3-.obj, and the Wrapper "call" ARCHI-RLD-1D-Wrap-3-.obj 

I had those errors :

---------------------------------------------------------------------------------------------------------------------------------------------------

1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>WRAPPER-3-.obj : error LNK2019: unresolved external symbol __init_ referenced in function __init_from_wrapper_
1>WRAPPER-3-.obj : error LNK2019: unresolved external symbol __developpe_pas_temps_ referenced in function __update_tableau_
1>WRAPPER-3-.obj : error LNK2019: unresolved external symbol __mise_a_jour_SR_ referenced in function __update_tableau_
1>WRAPPER-3-.obj : error LNK2019: unresolved external symbol __update_vecteur_densitees_racinaires_ referenced in function __update_tableau_
1>WRAPPER-3-.obj : error LNK2019: unresolved external symbol __step_imcremente_temps_archi_ referenced in function __update_tableau_
1>WRAPPER-3-.obj : error LNK2019: unresolved external symbol __get_vecteur_densitees_racinaires_ referenced in function __update_tableau_
1>ARCHI-RLD-1D-Wrap-3-.obj : error LNK2019: unresolved external symbol "float * __cdecl init_orig(void)" (?init_orig@@YAPAMXZ) referenced in function "void __cdecl _init_(void)" (?_init_@@YAXXZ)
1>Release\MIN3P-Root-BIND-V5.1.exe : fatal error LNK1120: 7 unresolved externals
1>
1>Build log written to  "file://D:\PROJET--COUPLAGE-VISUAL-SOURCES--\MIN3P-Rld-MAI-2014\MIN3P-Rld-V1-\MIN3P-Root-BIND-V5.1-\MIN3P-Root-BIND-V5.1\MIN3P-Root-BIND-V5.1\Release\BuildLog.htm"
1>MIN3P-Root-BIND-V5.1 - 8 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Any one could help ??

 

Thanks in advance

Best regards

 

 

12 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

The undefined symbols are coming from the C and C++ programs, not from the Fortran program.

Where are these routines declared?  Are they Fortran routines?  C routines?  C++ routines?

The naming conventions are different between these three languages, and it's possible that the external name being generated for the routine does not match the "expected" name requested by Wrapper or Archi.

We will need more info before we can actually help.

             --Lorri

 

Hello Lorri, hello everyone

 

 

 update_tableau is a C function inside WRAPPER-3-.c

It 's programm like this:

void update_tableau( ){

..................

.....mise_a_jour_SR
update_vecteur_densitees_racinaires
step_imcremente_temps_archi r
get_vecteur_densitees_racinaires

...................

}

Futhermore :

mise_a_jour_SR
update_vecteur_densitees_racinaires
step_imcremente_temps_archi r
get_vecteur_densitees_racinaires

are C++ functions programmed (implemented) inside : ARCHI-RLD-1D-Wrap-3.cpp which is a C ++ programm

and moreover update_tableau is interoperable with an interface inside the Fortran

Thanks in advance

Best Regards

 

The C++ functions require extern "C" definitions (no mangling, no overloading) in order to be called from C or Fortran.
 

Hello Tim, Hello Lorri, Hello alls

I write extern "C" inside the  but it's still doesn't work.

I have a C++ file, a Header declaring the fonction inside the C++;

and a C programm including the Header.

Do I have to do anything else anywhere ?

 

Sheers

Laurent L.

"update_tableau" is not one of the missing symbols --- it is the routine that contains the references to the missing variables.

IF you look at the error messages again, please, after the string 'unresolved external symbol' is the name that cannot be found.   Where are those routines declared?

 

Hello

those function are declared inside ARCHI-RLD-1D-Wrap-3.cpp

 

 

Sheers

Laurent L.

Best Reply

If you aren't using bind(c.;name=...') , most linux Fortrans append the _ by default. On Windows, ifort defaults to upper case without appended underscore, so you need the bind declaration to make it work the same as linux or gfortran.  On the C side, however, the _ must be declared explicitly, and this doesn't change between Windows and linux.  There are plenty of web references showing how iso_c_binding.works.

Those functions are declared inside ARCHI-RLD-1D-Wrap-3.cpp where I wrote a extern "C" { .....}

But in order to used them inside WRAPPER-3-.c , I made a header ARCHI-RLD-1D-Wrap-3.h

which is include in WRAPPER-3-c, so I also need to write extern "C" { .... } inside header ARCHI-RLD-1D-Wrap-3.h

to ????

 

Please can you give some link about "plenty of web references showing how iso_c_binding.works."

Thanks in advance

Best REgards.

laurent L.

 

Hi Laurent -

     Let me see if I understand your situation here ...

     WRAPPER-3-.c contains routine update_tableau, which calls routines in ARCHI-RLD-1D-Wrap-3.cpp, and those are undefined.

     WRAPPER-3-.c has #include "ARCHI-RLD-1D-Wrap-3.h" and inside this file you have declared all the routines in ARCHI-RLD-1D-Wrap-3.cpp as "extern C {}".

     But, what about in the actual source file for ARCHI-RLD-1D-Wrap-3.cpp?   If the interesting routines are not declared as extern C() there, then the C/C++ compiler will not generate the simple external names for them.

     To confirm this for yourself, use a command window, and issue this command:

                    link /dump /symbols ARCHI-RLD-1D-Wrap-3.obj

Look at the external names.   Are they as simple as "__update_vecteur_densitees_racinaires_" or are there extra symbols such as "@@" and various uppercase letters in there too?

                        --Lorri
 

 

One more thing - when you look at the external names, check the number of underscores.   The reference I cut-and-pasted from your original post has two underscores at the front, one at the end.    Check the name of the routine.   I assume you are building on Windows IA-32, which will prepend an extra underscore at the front of the name, and so the actual name in the source code should have one leading underscore, one trailing underscore.

 

Citation :

laurent L. a écrit :

 

Please can you give some link about "plenty of web references showing how iso_c_binding.works."

 

 

 

For example, on Intel's own site, if you look for "Interoperability of Procedures"

https://software.intel.com/sites/products/documentation/hpc/composerxe/e...

In order to specify the same linkage as gfortran or other linux compilers, append the underscore in the NAME specification:

USE iso_c_binding

......

FUNCTION FUNC(I, J, K, L, M), BIND(C, NAME=’func_’)

Then your Fortran linkage works with the lower case C function with appended underscore, regardless of the varying defaults.

 

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui