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

Transplant to Linux

Zhanghong_T_
Novice
805 Views
Hi all,
I have some problems in transplant my code from windows to linux:
1. code such as
!DEC$ ATTRIBUTES DLLEXPORT::xxx
How to change it in linux system?
2. code such as
use ifwin
...
hFile = CreateFile("temp.txt"C, GENERIC_WRITE,&
FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0)
ret = SetStdHandle(STD_OUTPUT_HANDLE, hFile)
...
ret=CloseHandle (hFile)
ret=DeleteFile ("temp.txt"C)
How to change the code?
Thanks,
Zhanghong Tang
0 Kudos
6 Replies
Intel_C_Intel
Employee
805 Views

Hello,

As far as I know Linux does not have Dynamic Load Libraries (.dll), but instead Shared Objects (.so). Please read the documentation about shared objects. You can remove the DLLEXPORT by adding #ifdef's that are not activated in Linux. In this way the same source code can work everywhere.

I hope this works,

Lars Petter Endresen

0 Kudos
Zhanghong_T_
Novice
805 Views

Hi,

Thank you very much for your reply.

In windows system the fortran code is built to a dynamic load library and called by C++ code. How can I change the code and compile the fortran code to let it be called by C++ in Linux?

Thanks,

Zhanghong Tang

0 Kudos
Jugoslav_Dujic
Valued Contributor II
805 Views
In UNIX shared objects (.so) all routines are "exported", so DLLEXPORT directive is meaningless. If you're compiling with ifort on Linux, it will be probably ignored, or maybe flagged with a warning (other compilers will just treat it as a comment). In any case (provided you're using ifort), you can isolate the system-specific codes with
!DEC$IF DEFINED(_WIN32)
Windows-specific code
!DEC$ELSE
Linux-specific code
!DEC$ENDIF
As for the question 2, (redirection of standard output), I would get rid of it entirely and simply replaced all WRITE(*) and PRINT* statements with WRITE(42), having previously OPEN(42, FILE="temp.txt"). If that's not an option for some reason (e.g. you still want standard output in some cases), better ask on Intel Linux Fortran forum about equivalent construct there (possibly some PXF* routne). Ah, I see you already did.

Jugoslav
0 Kudos
Zhanghong_T_
Novice
805 Views

Hi Jugoslav,

Thank you very much. You are always so kind. Now I simply deleted these statements, then compile and link, link error still exist. Could you tell me if any special options need when compile and link?

Thanks,

Zhanghong Tang

0 Kudos
Jugoslav_Dujic
Valued Contributor II
805 Views
Which link error?

Jugoslav
0 Kudos
Zhanghong_T_
Novice
805 Views
Oh I got it. I have not specify the /names:uppercase when compiling. Now the compile and link passed...
Thanks,
Zhanghong Tang
0 Kudos
Reply