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

Libary Integration with Simpack

Marvin_R_
Beginner
2,031 Views

hey,

 

i hope someone can help me with my problem regarding a Simpack User Routine. I wanted to create a User Routine (writen in Fortran) wich starts a Matlab Program. However i created a normal Fortran exe and icluded the Matlab Libary .lib Files an everything worked fine. After i created the Simpack User Routine i've got an error regarding the link of those libary Files.

Simpack allows to include external .lib libarys through the User Interface.

This is the error i got.

"engopen" etc.. are the matlab functions.

"Linking CXX shared library user.dll
   Creating library user.lib and object user.exp
uforce20.f.obj : error LNK2019: unresolved external symbol engopen referenced in function uforce20
uforce20.f.obj : error LNK2019: unresolved external symbol engevalstring referenced in function uforce20
uforce20.f.obj : error LNK2019: unresolved external symbol mxcreatedoublematrix730 referenced in function uforce20
uforce20.f.obj : error LNK2019: unresolved external symbol mxgetpr referenced in function uforce20
uforce20.f.obj : error LNK2019: unresolved external symbol mxcopyreal8toptr730 referenced in function uforce20
uforce20.f.obj : error LNK2019: unresolved external symbol engputvariable referenced in function uforce20
uforce20.f.obj : error LNK2019: unresolved external symbol enggetvariable referenced in function uforce20
uforce20.f.obj : error LNK2019: unresolved external symbol mxcopyptrtoreal8730 referenced in function uforce20
user.dll : fatal error LNK1120: 8 unresolved externals
LINK Pass 1 failed. with 1120"

it seems that Simpack cannot include the libary files i specified.

Can anyone help me?

0 Kudos
7 Replies
Steven_L_Intel1
Employee
2,031 Views

There is a lot you have not shown us. Is this 32-bit or 64-bit? Does matlab provide a .lib to link against? Did you do something like /names:lowercase to force the names to lower case, or are you using ALIAS or BIND(C) on their declarations?

0 Kudos
Marvin_R_
Beginner
2,031 Views

thank you for reply steve,

 

I am using the 64 bit version (incl. Simpack, Matlab, Windows, Compiler). Matlab provides 64bit .libs. It also provides pointers in a C++ header to use in a fortran program. I didn't use /names:lowercase, alias or bind(c). Compiling an .exe File works perfectly fine, but linking the .lib Files in a Simpack User Routine doesn't.

 

Marvin

0 Kudos
Lorri_M_Intel
Employee
2,031 Views

Could you please give the full link commands for creating the .exe and for creating the .lib?

It would be interesting to compare the differences.

If there are huge numbers of object files, you can just list a few representative files, such as:

                         link /exe:myexe.exe uforce20.f.obj user.obj <many other objs> foo.lib bar.lib

where the names of the libraries are spelled out, please.

                --Lorri

0 Kudos
mecej4
Honored Contributor III
2,031 Views

There are many missing pieces of information that you have yet to divulge before an attempt to solve the problem can be begun:

  • The versions of IVF, Matlab and Simpack used
  • The contents of the "user routine" (written in Fortran?), or at least the lines that call Matlab routines
  • The commands used to compile and link the user routine into a DLL.

The default name convention for Intel Fortran external symbols on Windows is all uppercase, no underscores added as prefix or suffix. The "unresolved external" lines that you reported, however, show lowercase names. In the libraries provided with Matlab R2014a/64-bit, the DLL libeng.dll contains function entries ENGOPEN and engOpen, but no engopen, as your linker errors in #1 display.

I suspect that either you or your build system (cmake?) did something to cause deviations from the default naming convention. That is why, without being given the information that I listed, we cannot proceed.

0 Kudos
Alexander_G_1
Beginner
2,031 Views

Hi everyone,

I have a problem that is quite similar to the one from Marvin. I also want to include Fortran .lib files to Simpack via a User Routine. The compile step works without indicating any problems. The linker step however throws errors just like those from Marvin. Here is the Message log:

** INFO: Cleaning build directory D:\s4_Sandbox\user_routines\build\win64\release

** INFO: Cleaning successfully done

** INFO: Backing up current CMakeLists file and swapping it with the file from the installation!

** INFO: User CMakeLists.txt successfully renamed to D:/s4_Sandbox/user_routines/src/CMakeLists.txt_160118-155503

** INFO: setting user directory to 'D:\s4_Sandbox\user_routines'

** INFO: setting default cmake generator to 'NMake Makefiles'

Copyright (C) 1985-2015 Intel Corporation. All rights reserved.

Intel(R) Compiler 16.0 (package 110)

 

-- The C compiler identification is MSVC 18.0.21005.1

-- The CXX compiler identification is MSVC 18.0.21005.1

-- The Fortran compiler identification is Intel

-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/cl.exe

-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/cl.exe -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/cl.exe

-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/cl.exe -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Check for working Fortran compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016/windows/bin/intel64/ifort.exe

-- Check for working Fortran compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016/windows/bin/intel64/ifort.exe -- works

-- Detecting Fortran compiler ABI info

-- Detecting Fortran compiler ABI info - done

-- Checking whether C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016/windows/bin/intel64/ifort.exe supports Fortran 90

-- Checking whether C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016/windows/bin/intel64/ifort.exe supports Fortran 90 -- yes

USER_CONFIG:NMake Makefiles

SIMPACK_OS:win64

CMAKE_Fortran_COMPILER_ID:Intel

-- Configuring done

-- Generating done

-- Build files have been written to: D:/s4_Sandbox/user_routines/build/win64/release

Scanning dependencies of target user

[100%] Building Fortran object CMakeFiles/user.dir/mbselem/uforce20.f.obj

Linking CXX shared library user.dll

Bibliothek "user.lib" und Objekt "user.exp" werden erstellt.

uforce20.f.obj : error LNK2019: Verweis auf nicht aufgel�stes externes Symbol "m_init_mp_s4_init" in Funktion "uforce20_type".

uforce20.f.obj : error LNK2019: Verweis auf nicht aufgel�stes externes Symbol "m_s4_mp_s4function" in Funktion "uforce20_type".

user.dll : fatal error LNK1120: 2 nicht aufgel�ste Externe

LINK Pass 1 failed. with 1120

NMAKE : fatal error U1077: ""C:\Program Files\SIMPACK-9.8.1\extern\win32\cmake-3.0\bin\cmake.exe"": R�ckgabe-Code "0xffffffff"

Stop.

NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\nmake.exe"": R�ckgabe-Code "0x2"

Stop.

NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\nmake.exe"": R�ckgabe-Code "0x2"

Stop.

 

 

 

Both libraries (M_Init and M_S4) have been built with cmake and ifort in 64Bit version (Cmake Generator: Visual Studio 12 Win64)

). I also did not use anything like /names:lowercase but the error message shows the function calls only in lower case letters, too. The contents of the user routine are quite basic:

 

use M_S4,                   only:S4function
use M_interface,           only:T_interface
use M_Init,                   only:S4_INIT

...

type(T_interface) :: allin   ! structure containing all input of the simulation
type(T_interface) :: allout ! structure containing all output of the simulation

...

call S4_INIT(allout,allin)
call S4function(allout,allin)

 

 

The Simpack Version is SIMPACK-9.8.1 and i use Intel Parallel Studio XE 2016 Composer Edition for Fortran. I hope that i was able to provide enough information regarding the involved components.

 

Any help would be very appreciated

 

0 Kudos
mecej4
Honored Contributor III
2,031 Views

You have shown a lot of error messages and chatter from the failed build process, but I do not have the background information to understand most of them. At least tell us where the procedures S4function and S4_init are defined (in an .obj file, a .lib file or a DLL?), and the full text of the link command. Things get obscured when you use a build system such as Cmake and you don't force it to reveal commands before attempting to execute them. If Cmake allows you to specify "verbose" or something similar, please try that. 

I suspect that the static libraries or DLL-import-libraries that contain S4function and S4_init were not included in the link command, or that the names have been mangled into a form different from their names in the library or DLL.

0 Kudos
Alexander_G_1
Beginner
2,031 Views

Hi mecej4,

thanks for the quick reply. Both functions are defined in a .lib file. I added them in the gui panel of simpack in "External objects/libraries". The error message does indeed look like the program cannot find the library. The user interface gui of Simpack however provides a line called "External objects/libraries" in which the libs shall be written that are to be included by Simpack (at least this is what the simpack documentation says). Well, i have included the library there and hoped for the best.

I did set Verbose=1 in the Simpack Interface. This is the resulting log. Please dont get scared by the huge amount of included directories... the project is quite large.

 

** INFO: setting user directory to 'D:\s4_Sandbox\user_routines'

** INFO: setting default cmake generator to 'NMake Makefiles'

Copyright (C) 1985-2015 Intel Corporation. All rights reserved.

Intel(R) Compiler 16.0 (package 110)

 

USER_CONFIG:NMake Makefiles

 

SIMPACK_OS:win64

CMAKE_Fortran_COMPILER_ID:Intel

-- Configuring done

-- Generating done

-- Build files have been written to: D:/s4_Sandbox/user_routines/build/win64/release

"C:\Program Files\SIMPACK-9.8.1\extern\win32\cmake-3.0\bin\cmake.exe" -HD:\s4_Sandbox\user_routines\src -BD:\s4_Sandbox\user_routines\build\win64\release --check-build-system CMakeFiles\Makefile.cmake 0

"C:\Program Files\SIMPACK-9.8.1\extern\win32\cmake-3.0\bin\cmake.exe" -E cmake_progress_start D:\s4_Sandbox\user_routines\build\win64\release\CMakeFiles D:\s4_Sandbox\user_routines\build\win64\release\CMakeFiles\progress.marks

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\nmake.exe" -f CMakeFiles\Makefile2 /nologo -L all

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\nmake.exe" -f CMakeFiles\user.dir\build.make /nologo -L CMakeFiles\user.dir\depend

"C:\Program Files\SIMPACK-9.8.1\extern\win32\cmake-3.0\bin\cmake.exe" -E cmake_depends "NMake Makefiles" D:\s4_Sandbox\user_routines\src D:\s4_Sandbox\user_routines\src D:\s4_Sandbox\user_routines\build\win64\release D:\s4_Sandbox\user_routines\build\win64\release D:\s4_Sandbox\user_routines\build\win64\release\CMakeFiles\user.dir\DependInfo.cmake --color=

Dependee "D:\s4_Sandbox\user_routines\build\win64\release\CMakeFiles\user.dir\DependInfo.cmake" is newer than depender "D:/s4_Sandbox/user_routines/build/win64/release/CMakeFiles/user.dir/depend.internal".

Scanning dependencies of target user

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\nmake.exe" -f CMakeFiles\user.dir\build.make /nologo -L CMakeFiles\user.dir\requires

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\nmake.exe" -f CMakeFiles\user.dir\build.make /nologo -L CMakeFiles\user.dir\build

"C:\Program Files\SIMPACK-9.8.1\extern\win32\cmake-3.0\bin\cmake.exe" -E cmake_progress_report D:\s4_Sandbox\user_routines\build\win64\release\CMakeFiles 1

[100%] Building Fortran object CMakeFiles/user.dir/mbselem/uforce20.f.obj

C:\PROGRA~2\INTELS~1\COMPIL~1\windows\bin\intel64\ifort.exe @C:\Users\gatt_al\AppData\Local\Temp\nm12C6.tmp

Linking CXX shared library user.dll

"C:\Program Files\SIMPACK-9.8.1\extern\win32\cmake-3.0\bin\cmake.exe" -E vs_link_dll C:\PROGRA~2\MICROS~3.0\VC\bin\amd64\link.exe /nologo @CMakeFiles\user.dir\objects1.rsp @C:\Users\gatt_al\AppData\Local\Temp\nm143E.tmp

Visual Studio Incremental Link with embedded manifests

Create user.dll.resource.txt

RC Pass 1:

C:/Program Files (x86)/Windows Kits/8.1/bin/x64/rc.exe /fouser.dll.embed.manifest.res user.dll.resource.txt

LINK Pass 1:

C:\PROGRA~2\MICROS~3.0\VC\bin\amd64\link.exe /nologo @CMakeFiles\user.dir\objects1.rsp /out:user.dll /implib:user.lib /pdb:D:\s4_Sandbox\user_routines\build\win64\release\user.pdb /dll /version:0.0 /machine:x64 /nologo /stack:10000000 /incremental /nodefaultlib:libc.lib /nodefaultlib:libcd.lib /nodefaultlib:libcmt /nodefaultlib:libcmtd /nodefaultlib:libcimt /nodefaultlib:msvcrtd.lib /nodefaultlib:libifcoremdd.lib /nodefaultlib:libmmdd.lib /libpath:C:/Program Files/SIMPACK-9.8.1/run/bin/win64 D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/LIBRARIES/auswertung/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/LIBRARIES/genvis/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/LIBRARIES/mathlib/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/LIBRARIES/utils/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/AERODYNAMICS/Airfoils/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/AERODYNAMICS/DOWNWASH/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/AERODYNAMICS/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/AERODYNAMICS/WEA/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/CALCULATION/CONTROL/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/DYNAMICS/Release/*.lib D:/s4/Entwicklertrunk/SOURCE/DYNAMICS/s4cosim/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/DYNAMICS/s4cosim/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/INOUT/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/ROTORS/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/TYPES/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/USER_INPUT/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/LIBRARIES/genvis/libGENVIS.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/LIBRARIES/mathlib/mathlib.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/LIBRARIES/utils/libutils.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/AERODYNAMICS/Airfoils/libs4airfoils.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/AERODYNAMICS/DOWNWASH/libDOWNWASH.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/AERODYNAMICS/libAERODYNAMICS.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/AERODYNAMICS/WEA/libs4wea.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/CALCULATION/libCALCULATION.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/DYNAMICS/libDYNAMICS.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/DYNAMICS/s4cosim/libcosim.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/DYNAMICS/s4cosim/libcosim_C.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/INOUT/libINOUT.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/libBATCH.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/ROTORS/libROTORS.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/s4.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/TYPES/libTYPES.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/USER_INPUT/libUSER_INPUT.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/LIBRARIES/vdwall/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/LIBRARIES/vdwall/libvdwall.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/libs4globals.dir/Release/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/CALCULATION/Release/*.lib D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/CALCULATION/CONTROL/libCONTROL.dir/Release/*.obj ../../../extlib/*.lib ../../../extobj/*.obj D:/s4/Entwicklertrunk/BUILD/VisualStudio/BUILD/SOURCE/CALCULATION/Release/libCalculation.lib /INCREMENTAL:NO FortranInterface.lib libifcoremd.lib libmmd.lib msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:user.dll.intermediate.manifest user.dll.embed.manifest.res

Bibliothek "user.lib" und Objekt "user.exp" werden erstellt.

uforce20.f.obj : error LNK2019: Verweis auf nicht aufgel�stes externes Symbol "m_init_mp_s4_init" in Funktion "uforce20_type".

uforce20.f.obj : error LNK2019: Verweis auf nicht aufgel�stes externes Symbol "m_s4_mp_s4function" in Funktion "uforce20_type".

user.dll : fatal error LNK1120: 2 nicht aufgel�ste Externe

LINK Pass 1 failed. with 1120

NMAKE : fatal error U1077: ""C:\Program Files\SIMPACK-9.8.1\extern\win32\cmake-3.0\bin\cmake.exe"": R�ckgabe-Code "0xffffffff"

Stop.

NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\nmake.exe"": R�ckgabe-Code "0x2"

Stop.

NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\amd64\nmake.exe"": R�ckgabe-Code "0x2"

Stop.

 

 

Does this help you?

 

 

 

0 Kudos
Reply