0
votes

I am trying to compile a Fortran file with an external precompiled module. First I compile the module file with:

ifort /c KDTree_mod.f90

it generates some .mod files (kdtree2_module.mod, kdtree2_precision_module.mod, kdtree2_priority_queue_module.mod).

At the beginning of the subroutine I have:

subroutine film(h,tinf,ts,n,time)
use kdtree2_module

but when I launch the program it gives me this error:

user_film.obj : error LNK2019: unresolved external symbol KDTREE2_MODULE_mp_KDTREE2_CREATE referenced in function FILM
user_film.obj : error LNK2019: unresolved external symbol KDTREE2_MODULE_mp_KDTREE2_N_NEAREST referenced in function FILM
user_film.exe : fatal error LNK1120: 2 unresolved externals
link failed for user_film.obj

Procedure:
1. compile the module with ifort /c KDTree_mod.f90
2. launch MSC Marc with user subroutine film.
run_marc -j name_input_file -u user_subroutine
3. Error

MSC Marc is a commercial software that has the possibility to create user subroutine.

Update:
I tried:
1. ifort /c KDTree_mod.f90 --> generate .obj file
run_marc -j name_input_file -obj name_obj.obj -u name_input_file
It compiles fine but suddenly error:

forrtl: severe (170): Program Exception - stack overflow Image
PC Routine Line Source

user_film.exe 0000000141D63717 Unknown Unknown Unknown user_film.exe 000000013FD45C96 Unknown
Unknown Unknown user_film.exe 000000013FF1CCC7 Unknown
Unknown Unknown user_film.exe 000000013FD9495E Unknown
Unknown Unknown user_film.exe 00000001405A819A Unknown
Unknown Unknown user_film.exe 0000000140236B11 Unknown
Unknown Unknown user_film.exe 000000013FFE32DB Unknown
Unknown Unknown user_film.exe 000000013FFEE6C1 Unknown
Unknown Unknown user_film.exe 000000013FE70FAE Unknown
Unknown Unknown user_film.exe 000000013FD51592 Unknown
Unknown Unknown user_film.exe 000000013FD4105D Unknown
Unknown Unknown user_film.exe 00000001424CE3DC Unknown
Unknown Unknown user_film.exe 0000000141D638B2 Unknown
Unknown Unknown kernel32.dll 0000000077475A4D Unknown
Unknown Unknown ntdll.dll 00000000775AB831 Unknown
Unknown Unknown

  1. ifort /c KDTree_mod.f90 ifort /c user_film.f run_marc -j name_input_file -obj KDtree_mod.obj user_film.obj
    read error: no such option: user_film.obj or input value: -b

    So seems that I am not able to pass both .obj files.

  2. ifort /c KDTree_mod.f90 ifort /c user_film.f KDTree_mod.obj ifort: warning #10146: no action performed for specified object file(s)

Marc in verbose: http://pastebin.com/6rd8v5Eh

Update 2 I am able to compile a dll file with these commands:

ifort /nologo /iface:stdcall /libs:dll /threads /c KDTree_mod.f90
link /NOLOGO /SUBSYSTEM:WINDOWS /manifest /dll /out:KDTree_mod.dll KDTree_mod.obj
mt /nologo “/outputresource:KDTree_mod.dll;#2″ /manifest KDTree_mod.dll.manifest
1
It is not enough to compile with the .mod file, you also have to link in the appropriate library (it will be an .obj. or a .dll). You must search the manual of your software providing the module about how to do that. - Vladimir F
Check if the line ifort /c KDTree_mod.f90 created also something else than the .mod files, perhaps an .obj, .o or .out or a similar file. - Vladimir F
Yes it creates .mod and .obj files. - yellowhat
Describe what exactly do you do before you get the error message. You must link the .obj files in. Which exact command do you lunch? How do you compile and link your subroutine with the program? - Vladimir F
MSC Marc needs to compile film somehow and incorporate the code into its execution path. We do not know how it does it, and you would need to figure out, how it does it and how it could be modified, to include linking of external objects. - haraldkl

1 Answers

0
votes

The most useful information I found on the internet is in this german CAD forum, where it says, that there is a run_marc with the following:

FCOMP=ifort
...
FORTRAN="$FCOMP -c -assume byterecl -safe_cray_ptr $PROFILE -save -zero -mp -WB -w90 -O1 $I8FFLAGS -I$MARC_SOURCE/common \
-I$MARC_SOURCE/bcssolver/common -I$MARC_SOURCE/mumpssolver/include $I8DEFINES -DLinux -DLINUX -DLinux_intel $FDEFINES $DDM $SOLVERFLAGS"

You would need to add a -obj KDTree_mod.obj or the like to this command line. From the descriptions there it sounds it would also be possible to link against libraries, so it might be another option to create a library and use that via a path that is more in line with the general usage of that tool.

Regarding your first update: I wouldn't have expected the -obj option to work for that at all. What I meant, was that you need to modify the run_marc script itself. According to the link above it appears to be a script with a variable containing the run script in it. It might be that this is only the case on Unix systems, and on Windows it is solved differently. Did you try to look into the run_marc script? I have no clue, what your first command in your update, which you say compiles, actually does what is this name_obj now all of a sudden?

In your second command, I would have expected something like:

run_marc -j name_input_file -u user_film -obj KDtree_mod.obj

Though, as outlined above, I don't think the obj gets passed on.

Regarding your second update, and your comment below:

Besides the linking you also need to have the module file available in the include path. Usually the include path of the compiler includes the current working directory, so if you can put the module file into the directory where the compiler is executed, this ought to work. Or you put it in one of the directories stated via the -I options in the compiling FORTRAN command above. Or, you modify the command and add your own include path to it.

How does this command from your pastebin look like with the set userdll option filled:

ifort  /fpp /c /DWIN32_intel  -D_IMPLICITNONE /nologo
      -DMKL -DOPENMP -DOMP_COMPAT -D_MSCMARC -DWIN64
      /I"C:\MSC.Software\Marc\2014.0.0\marc2014\common"
      /I"C:\MSC.Software\Marc\2014.0.0\marc2014\bcsgpusolver\common" 
      /I"C:\MSC.Software\Marc\2014.0.0\marc2014\mumpssolver\include" 
      /I"C:\MSC.Software\Marc\2014.0.0\marc2014\intelmpi\win64\include"
      /O2 /Qip /Qvec- /Qsafe-cray-ptr /switch:fe_old_modvar
      /W0  /Qopenmp /Qopenmp-threadprivate:compat  -DCASI -DPARDISO -DMUMPS
      -DBCSGPU -DCUDA /MD -DDDM
      /object:"C:\Users\Yellowhat\Desktop\prova\user_film.obj"
      "C:\Users\Yellowhat\Desktop\prova\user_film.f"

It looks like C:\MSC.Software\Marc\2014.0.0\marc2014\common would be a good location to put the KDTree *.mod files into.