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

call c++ staic lib

ppthelion
Beginner
2,326 Views
Dear ones
I have create a static c++ libraries , and test well under vcc environment. Then I want to use the function which inherented in the c++ lib.it notes that function has been added an underscore beforeit as 'fit' to '_fit',so it's notrecognized of ifort . Usually ,we can create an interface which announce the function to be used for fortran. But this static lib contains so many function , it would be a huge work!! Is there a shortcut way to solve this problem?
Any answer is appreciated!
Thanks !
0 Kudos
1 Solution
Jugoslav_Dujic
Valued Contributor II
2,326 Views
Quoting - ppthelion
Thanks for your fully and clearly answer.here I want to use JPL software fitsio which programmed in C language. They supply the source code and the BAT file toproduce the lib file. so I follow the instruction ,and createastatic library and dynamic library successfully .I can run testprog.c program successfully,but for testf77.f,it can'tfind function init .For example,ERROR 'can't resolve the external flag <_FTUCKS>', butuse command 'dumbpin',I can find some similar subroutine : 2EEFTUCKS@8,2EE_imp_FTUCKS@8,28194_FTUCKS@8 in the lib. In addition,the author also supply us a free C code named 'cfortran.h' which could do this task automatically ,but I don't know how to use it ,could your give me some suggestions: Thanks for your constructiveadvice (attached file : cfortran.h,cfitsio.lib,fitsio.h,testprog.c ,testf77.f...which used when compile and run)
CMD I used: ifort /c /MD /libs:dll cfitsio.lib testf77.f /fpp /extfpp:cfortran.h,fitsio.h /names:UPPERCASE
ifort /MD /libs:dll cfitsio.lib testf77.obj /out:testf77.exe /fpp /extfpp:cfortran.f,fitsio.h

Well, how is C code compiled? I see stdcall symbols in there, but no __stdcall keyword in the code.

In any case, try (no guarantees, didn't test it myself):

fort /c /MD /libs:dll cfitsio.lib testf77.f /fpp /extfpp:cfortran.h,fitsio.h /iface:CVF

View solution in original post

0 Kudos
6 Replies
Jugoslav_Dujic
Valued Contributor II
2,326 Views
Quoting - ppthelion
Dear ones
I have create a static c++ libraries , and test well under vcc environment. Then I want to use the function which inherented in the c++ lib.it notes that function has been added an underscore beforeit as 'fit' to '_fit',so it's notrecognized of ifort . Usually ,we can create an interface which announce the function to be used for fortran. But this static lib contains so many function , it would be a huge work!! Is there a shortcut way to solve this problem?
Any answer is appreciated!
Thanks !

No, manual adding of the underscore is not required (and is actually harmful). Both Visual C++ and Intel Fortran apply the underscore in the same manner: it is used for __cdecl functions on Win32, and not used on functions on x64.

However, the functions must be built as C (i.e. not as C++, meaning that you should use extern "C" or appropriate C++ compiler settings), and the uppercase/lowercase names must match (Intel fortran expects UPPERCASE names by default, although it can be made to expect lowercase via /names:lowercase). If C++ names are MixedCase, you must write an INTERFACE .

All in all, you should write an INTERFACE block for C functions, though you could get away without it in some special cases. If you make a mismatch in number or type of arguments, such errors are extremely hard to find in mixed-lnaguage environments.

There are some free C code parsers which could even semi-automate the task (if it's really huge), but let's not go there prematurely...
0 Kudos
ppthelion
Beginner
2,326 Views
Thanks for your fully and clearly answer.here I want to use JPL software fitsio which programmed in C language. They supply the source code and the BAT file toproduce the lib file. so I follow the instruction ,and createastatic library and dynamic library successfully .I can run testprog.c program successfully,but for testf77.f,it can'tfind function init .For example,ERROR 'can't resolve the external flag <_FTUCKS>', butuse command 'dumbpin',I can find some similar subroutine : 2EEFTUCKS@8,2EE_imp_FTUCKS@8,28194_FTUCKS@8in the lib. In addition,the author also supply us a free C code named 'cfortran.h' which could do this task automatically ,but I don't know how to use it ,could your give me some suggestions: Thanks for your constructiveadvice (attached file : cfortran.h,cfitsio.lib,fitsio.h,testprog.c ,testf77.f...which used when compile and run)
CMD I used: ifort /c /MD /libs:dll cfitsio.lib testf77.f /fpp /extfpp:cfortran.h,fitsio.h /names:UPPERCASE
ifort /MD /libs:dll cfitsio.lib testf77.obj /out:testf77.exe /fpp /extfpp:cfortran.f,fitsio.h
0 Kudos
anthonyrichards
New Contributor III
2,326 Views
The FITSIO library is (or certainly WAS)available as a Fortran version (maybe no longer supported with updates as the C++ version may be). I have downloaded it in the past and compiled it OK into a static libraryusing Compaq Visual Fortran. The FITSIO test program TESTPROG.F compiled and ran OK as well with no errors reported. I have since written several Fortran programs to process FITS files using it. Perhaps you could try that route using IVF?

0 Kudos
Jugoslav_Dujic
Valued Contributor II
2,327 Views
Quoting - ppthelion
Thanks for your fully and clearly answer.here I want to use JPL software fitsio which programmed in C language. They supply the source code and the BAT file toproduce the lib file. so I follow the instruction ,and createastatic library and dynamic library successfully .I can run testprog.c program successfully,but for testf77.f,it can'tfind function init .For example,ERROR 'can't resolve the external flag <_FTUCKS>', butuse command 'dumbpin',I can find some similar subroutine : 2EEFTUCKS@8,2EE_imp_FTUCKS@8,28194_FTUCKS@8 in the lib. In addition,the author also supply us a free C code named 'cfortran.h' which could do this task automatically ,but I don't know how to use it ,could your give me some suggestions: Thanks for your constructiveadvice (attached file : cfortran.h,cfitsio.lib,fitsio.h,testprog.c ,testf77.f...which used when compile and run)
CMD I used: ifort /c /MD /libs:dll cfitsio.lib testf77.f /fpp /extfpp:cfortran.h,fitsio.h /names:UPPERCASE
ifort /MD /libs:dll cfitsio.lib testf77.obj /out:testf77.exe /fpp /extfpp:cfortran.f,fitsio.h

Well, how is C code compiled? I see stdcall symbols in there, but no __stdcall keyword in the code.

In any case, try (no guarantees, didn't test it myself):

fort /c /MD /libs:dll cfitsio.lib testf77.f /fpp /extfpp:cfortran.h,fitsio.h /iface:CVF
0 Kudos
ppthelion
Beginner
2,326 Views
Quoting - anthonyrichards
The FITSIO library is (or certainly WAS)available as a Fortran version (maybe no longer supported with updates as the C++ version may be). I have downloaded it in the past and compiled it OK into a static libraryusing Compaq Visual Fortran. The FITSIO test program TESTPROG.F compiled and ran OK as well with no errors reported. I have since written several Fortran programs to process FITS files using it. Perhaps you could try that route using IVF?


Thanks for your suggestion ! But when you want to use more tools of this software and be more confident of it when you use ,I think using the latest version is a good idea.Follow the advice of Jugoslav Dujic,the Fitsio test program testprog.fcan alsocompiled and ran ok aswell with no errors reported.Today is a nice day!
0 Kudos
ppthelion
Beginner
2,326 Views
Quoting - Jugoslav Dujic

Well, how is C code compiled? I see stdcall symbols in there, but no __stdcall keyword in the code.

In any case, try (no guarantees, didn't test it myself):

fort /c /MD /libs:dll cfitsio.lib testf77.f /fpp /extfpp:cfortran.h,fitsio.h /iface:CVF

Thanks for your constructive advice,I have test the fortran program successfully!!
0 Kudos
Reply