- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I WOULD LIKE TO COMPILE MY .F FILE INTO A .DLL. I KNOW THE PROGRAM WORKS BECAUSE I HAVE COMPILED WITH 32-BIT VISUAL FORTRAN.
MY PROGRAM STARTS LIKE THIS:
#include "cfx5ext.h"
dllexport(pt_mom_source64)
SUBROUTINE PT_MOM_SOURCE64(NLOC,NRET,NARG,RET,ARG,CRESLT,
& CZ,DZ,IZ,LZ,RZ)
CC
I INSTALLED LINUX INTEL FORTRAN 64-BIT. THE WORKING DIRECTORY IS /opt/intel/Compiler/11.1/073/bin/intel64/
I COPIED MY .F AND SUPPORTING .h FILES TO THE ../intel64/ DIRECTORY.
# ./ifort pt_mom_source64.F GIVES THE FOLLOWING ERROR
/opt/intel/Compiler/11.1/073/lib/intel64/for_main.o: In function `main':
/export/users/nbtester/efi2linux_nightly/branch-11_1/20100807_000000/libdev/frtl/src/libfor/for_main.c:(.text+0x38): undefined reference to `MAIN__'
# ./ifort -nofor-main pt_mom_source64.F GIVES THE FOLLOWING ERROR
/opt/intel/Compiler/11.1/073/lib/intel64/libifcore.a(for_main.o): In function `main':
for_main.c:(.text+0x4a): undefined reference to `MAIN__'
What is the correct command to compile a .F program with .h files into a .dll?
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First of all: you shouldn't mess with the compiler's directory ---i.e., don't add your own files to the "/opt/intel/..." directory. To use any other directory as your current one, for bash terminals, add the following at the end of your ~/.bashrc file instead:
[bash]. /opt/intel/Compiler/11.1/073/bin/ifortvars.sh [/bash]
Second: Avoid using a root terminal if possible (since there's no undo in the terminal, and humans make mistakes... sometimes).
Third: There are no DLLs in UNIX(-like), and therefore dllexport is not useful here. What you want is a shared object, in which case the compiler needs the -shared switch ---otherwise, it will assume you want an executable and try to look for a (MAIN__) program unit---. The -fPIC switch might also be necessary.
Fourth: you can isolate the Windows-related portions of your code using the _WIN32 symbol, e.g.:
[fxfortran]#ifdef __WIN32 cDEC$ATTRIBUTES DLLEXPORT :: PT_MOM_SOURCE64 #endif[/fxfortran]
I hope that helps.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First of all: you shouldn't mess with the compiler's directory ---i.e., don't add your own files to the "/opt/intel/..." directory. To use any other directory as your current one, for bash terminals, add the following at the end of your ~/.bashrc file instead:
[bash]. /opt/intel/Compiler/11.1/073/bin/ifortvars.sh [/bash]
Second: Avoid using a root terminal if possible (since there's no undo in the terminal, and humans make mistakes... sometimes).
Third: There are no DLLs in UNIX(-like), and therefore dllexport is not useful here. What you want is a shared object, in which case the compiler needs the -shared switch ---otherwise, it will assume you want an executable and try to look for a (MAIN__) program unit---. The -fPIC switch might also be necessary.
Fourth: you can isolate the Windows-related portions of your code using the _WIN32 symbol, e.g.:
[fxfortran]#ifdef __WIN32 cDEC$ATTRIBUTES DLLEXPORT :: PT_MOM_SOURCE64 #endif[/fxfortran]
I hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. This seems to work.
First, .bashrc worked after adding intel64.... ./opt/intel/Compiler/11.1/073/bin/ifortvars.sh intel64 was necessary for my release.
Second, OK
Third, -shared gives error as you expected; However -shared -fPIC has no errors!
Fourth, also compiles without error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I forgot the "intel64" part. I'm glad you figured it out.
You'll need to recompile your application in order to use it in your UNIX(-like) box. By default, Windows and UNIX applications use different formats for their respective executables and libraries, so you cannot use them interchangeably (unless you have any compatibility layer installed). You compile your application just like you did in Windows, e.g.:
[bash]ifort -o myApp -L{path-to-shared-object} -l{shared-object} mainfile.F ...[/bash]So, if your shared is called libpt_mom.so, and is located inthe "/export/users/nbtester/lib" directory, your command would be:
[bash]ifort -o myApp -L/export/users/nbtester/lib -lpt_mom mainfile.F ...[/bash]
Here, I'm assuming that the PROGRAM unit is in a file called mainfile.F and that the name you want for your application is "myApp"; change accordingly. Keep in mind that since there was no "dllexport", there's no .lib to link with (so the .so file must be used directly). Also, the -l
switch assumes that the name of your shared object starts with "lib" and has the ".so" extension.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the -l
switch assumes that the name of your shared object starts with "lib" and has the ".so" extension.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page