Skip to content

Export API routines for MSVC compiler#168

Closed
TyBalduf wants to merge 0 commit intodftd4:mainfrom
TyBalduf:main
Closed

Export API routines for MSVC compiler#168
TyBalduf wants to merge 0 commit intodftd4:mainfrom
TyBalduf:main

Conversation

@TyBalduf
Copy link
Copy Markdown
Collaborator

  • Exports must be explictly declared for the MSVC compiler.
    This commit adds DLLEXPORT attributes to the subroutines needed for
    the api and app to compile

Signed-off-by: Ty [email protected]

Copy link
Copy Markdown
Member

@awvwgk awvwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can understand why we need to export the procedures in the C API. However, why do we have to do the same for the Fortran API? Especially, for type bound procedures the created struct will provide a procedure pointer.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 18, 2022

Codecov Report

Merging #168 (63cf994) into main (3e4ea97) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #168   +/-   ##
=======================================
  Coverage   60.12%   60.12%           
=======================================
  Files          44       44           
  Lines        3130     3130           
  Branches     1019     1019           
=======================================
  Hits         1882     1882           
  Misses        667      667           
  Partials      581      581           
Impacted Files Coverage Δ
src/dftd4/api.f90 40.67% <ø> (ø)
src/dftd4/damping/rational.f90 69.04% <ø> (ø)
src/dftd4/disp.f90 64.10% <ø> (ø)
src/dftd4/model.f90 79.52% <ø> (ø)
src/dftd4/output.f90 51.39% <ø> (ø)
src/dftd4/param.f90 38.22% <ø> (ø)
src/dftd4/utils.f90 50.00% <ø> (ø)
src/dftd4/version.f90 90.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e4ea97...63cf994. Read the comment docs.

@TyBalduf TyBalduf marked this pull request as draft July 18, 2022 21:35
@TyBalduf
Copy link
Copy Markdown
Collaborator Author

@awvwgk I'm not entirely sure why the app subroutines would need the DLL attributes. This was the error I was getting on the last step of the build after I added DLLEXPORTs to just the api subroutines:

[157/157] Linking target app/dftd4.exe
FAILED: app/dftd4.exe app/dftd4.pdb
"xilink.exe"  /MACHINE:x64 /OUT:app/dftd4.exe app/dftd4.exe.p/main.f90.obj app/dftd4.exe.p/cli.f90.obj app/dftd4.exe.p/driver.f90.obj "/nologo" "/DEBUG" "/PDB:app\dftd4.pdb" "dftd4.lib" "subprojects\mctc-lib\libmctc-lib.a" "subprojects\json-fortran-8.2.5\libjsonfortran.a" "subprojects\multicharge\libmulticharge.a" "mkl_rt.lib" "mkl_rt.lib" "mkl_rt.lib" "/SUBSYSTEM:CONSOLE"
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_UTILS_mp_WRAP_TO_CENTRAL_CELL referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_PARAM_mp_GET_RATIONAL_DAMPING referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_ASCII_DAMPING_PARAM referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_MODEL_mp_NEW_D4_MODEL referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_DISP_mp_GET_DISPERSION referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_ASCII_RESULTS referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_ASCII_PAIRWISE referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_TAGGED_RESULT referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_TURBOMOLE_GRADIENT referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_JSON_RESULTS referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_TURBOMOLE_GRADLATT referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_DISP_mp_GET_PAIRWISE_DISPERSION referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_ASCII_ATOMIC_RADII referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_ASCII_ATOMIC_REFERENCES referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_DISP_mp_GET_PROPERTIES referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2019: unresolved external symbol DFTD4_OUTPUT_mp_ASCII_SYSTEM_PROPERTIES referenced in function DFTD4_DRIVER_mp_RUN_MAIN
driver.f90.obj : error LNK2001: unresolved external symbol DFTD4_DAMPING_RATIONAL_mp_GET_DISPERSION2
driver.f90.obj : error LNK2001: unresolved external symbol DFTD4_DAMPING_RATIONAL_mp_GET_DISPERSION3
driver.f90.obj : error LNK2001: unresolved external symbol DFTD4_DAMPING_RATIONAL_mp_GET_PAIRWISE_DISPERSION2
driver.f90.obj : error LNK2001: unresolved external symbol DFTD4_DAMPING_RATIONAL_mp_GET_PAIRWISE_DISPERSION3
driver.f90.obj : error LNK2001: unresolved external symbol DFTD4_MODEL_mp_WEIGHT_REFERENCES
driver.f90.obj : error LNK2001: unresolved external symbol DFTD4_MODEL_mp_GET_ATOMIC_C6
driver.f90.obj : error LNK2001: unresolved external symbol DFTD4_MODEL_mp_GET_POLARIZIBILITIES
app\dftd4.exe : fatal error LNK1120: 23 unresolved externals

So my first pass was to try also adding DLLEXPORT to the other unresolved external symbols, which worked on my machine.

I suspect it could be due to my compiler setup being somewhat unusual (ifort and msvc cl).
Here is the output from my meson setup if it makes anything clearer.

The Meson build system
Version: 0.62.99
Source dir: C:\msys64\home\balduf\repos\dftd4
Build dir: C:\msys64\home\balduf\repos\dftd4\build
Build type: native build
Project name: dftd4
Project version: 3.4.0
Fortran compiler for the host machine: ifort (intel-cl 2021.5.0)
Fortran linker for the host machine: xilink.exe xilink 2021.5.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
C compiler for the host machine: cl (msvc 19.29.30141 "Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30141 for x64")
C linker for the host machine: link link 14.29.30141.0
Library mkl_rt found: YES
Found pkg-config: C:\msys64\mingw64\bin\pkg-config.EXE (1.8.0)
Did not find CMake 'cmake'
Found CMake: NO
Run-time dependency mctc-lib found: NO (tried pkgconfig and cmake)
Looking for a fallback subproject for the dependency mctc-lib

Executing subproject mctc-lib

mctc-lib| Project name: mctc-lib
mctc-lib| Project version: 0.3.0
mctc-lib| Fortran compiler for the host machine: ifort (intel-cl 2021.5.0)
mctc-lib| Fortran linker for the host machine: xilink.exe xilink 2021.5.0
mctc-lib| Run-time dependency json-fortran found: NO (tried pkgconfig and cmake)
mctc-lib| Looking for a fallback subproject for the dependency json-fortran
mctc-lib| Using subprojects\mctc-lib\subprojects\json-fortran-8.2.5.wrap

Executing subproject mctc-lib:json-fortran-8.2.5

json-fortran-8.2.5| Project name: jsonfortran
json-fortran-8.2.5| Project version: 8.2.5
json-fortran-8.2.5| Fortran compiler for the host machine: ifort (intel-cl 2021.5.0)
json-fortran-8.2.5| Fortran linker for the host machine: xilink.exe xilink 2021.5.0
json-fortran-8.2.5| Build targets in project: 1
json-fortran-8.2.5| Subproject json-fortran-8.2.5 finished.

mctc-lib| Dependency json-fortran from subproject subprojects/json-fortran-8.2.5 found: YES 8.2.5
mctc-lib| Build targets in project: 4
mctc-lib| Subproject mctc-lib finished.

Dependency mctc-lib from subproject subprojects/mctc-lib found: YES 0.3.0
Run-time dependency multicharge found: NO (tried pkgconfig and cmake)
Looking for a fallback subproject for the dependency multicharge

Executing subproject multicharge

multicharge| Project name: multicharge
multicharge| Project version: 0.2.0
multicharge| Fortran compiler for the host machine: ifort (intel-cl 2021.5.0)
multicharge| Fortran linker for the host machine: xilink.exe xilink 2021.5.0
multicharge| Library mkl_rt found: YES
multicharge| Dependency mctc-lib found: YES 0.3.0 (cached)
multicharge| Run-time dependency mstore found: NO (tried pkgconfig and cmake)
multicharge| Looking for a fallback subproject for the dependency mstore

Executing subproject multicharge:mstore

mstore| Project name: mstore
mstore| Project version: 0.2.0
mstore| Fortran compiler for the host machine: ifort (intel-cl 2021.5.0)
mstore| Fortran linker for the host machine: xilink.exe xilink 2021.5.0
mstore| Dependency mctc-lib found: YES 0.3.0 (cached)
mstore| Build targets in project: 9
mstore| Subproject mstore finished.

multicharge| Dependency mstore from subproject subprojects/mstore found: YES 0.2.0
multicharge| Build targets in project: 10
multicharge| Subproject multicharge finished.

Dependency multicharge from subproject subprojects/multicharge found: YES 0.2.0
Program tester.py found: YES (C:\msys64\scr\Scripts\python.exe C:\msys64\home\balduf\repos\dftd4\app\tester.py)
Program config/install-mod.py found: YES (C:\msys64\scr\Scripts\python.exe C:\msys64\home\balduf\repos\dftd4\config/install-mod.py)
Program asciidoctor found: NO
Build targets in project: 13

dftd4 3.4.0

  Subprojects
    json-fortran-8.2.5: YES
    mctc-lib          : YES
    mstore            : YES
    multicharge       : YES

  User defined options
    fortran_args      : -fpp
    lapack            : mkl-rt
    openmp            : false

Found ninja-1.10.2 at C:\msys64\mingw64\bin\ninja.EXE

This is not a crucial fix in my view. My main goal was to see if making the compilation work for my setup was as simple as the fix made for getting xTB to compile. I'll leave this as a draft until I get a chance to try to fix it.

@TyBalduf
Copy link
Copy Markdown
Collaborator Author

The docs/build-and-deploy error seems to be unrelated.

I'll have to look more into what could be causing the intel-build failure, though that is during the CMake build of mctc, so I'm surprised my changes would affect it.

@awvwgk
Copy link
Copy Markdown
Member

awvwgk commented Jul 18, 2022

I can reproduce the error with Intel 2021.5 and MSVC 19.31 on my machine. Seems like the dllexports are needed all over the place, however they don't work anymore on Unix platforms and I'm not down for introducing preprocessor statements to guard a compiler directive in a comment. We can't fix one platform and than just break the build for another.

From the Intel side there seems to be no solution (https://community.intel.com/t5/Intel-Fortran-Compiler/dllexport-Exporting-all-module-data-automatically/td-p/1153856). However, the recommendation is to create a script which parses the symbols dumped by some mean and turn them into a def file. This has the huge drawback of the symbols in the def file being dependent on the respective Fortran compiler since the ABI and symbol names are different.

@awvwgk
Copy link
Copy Markdown
Member

awvwgk commented Jul 18, 2022

I'll have to look more into what could be causing the intel-build failure, though that is during the CMake build of mctc, so I'm surprised my changes would affect it.

the dllexport attribute is not supported on Unix platforms with Intel Fortran for non-bind(c) routines.

[256/288] Building Fortran object CMakeFiles/dftd4-lib.dir/src/dftd4/utils.f90.o
/home/runner/work/dftd4/dftd4/src/dftd4/utils.f90(29): remark #7841: DLL IMPORT/EXPORT is not supported on this platform.   [DLLEXPORT]
!DEC$ ATTRIBUTES DLLEXPORT :: wrap_to_central_cell
-----------------^

@TyBalduf
Copy link
Copy Markdown
Collaborator Author

TyBalduf commented Jul 18, 2022

I can reproduce the error with Intel 2021.5 and MSVC 19.31 on my machine. Seems like the dllexports are needed all over the place, however they don't work anymore on Unix platforms and I'm not down for introducing preprocessor statements to guard a compiler directive in a comment. We can't fix one platform and than just break the build for another.

Agreed, I definitely wouldn't want to fix one build just to break another or cause a big game of chasing down bugs introduced by fixes intended for another build. I'm using ifort/msvc in a mingw environment, which was why adding the attributes worked for me. If I can't find a fix that doesn't break other builds, I'm fine with just using a patched version locally. Or since this compiler combination hasn't worked on Unix machines, just supporting/allowing it for Windows (only under the condition that the fixes don't break any existing build).

the dllexport attribute is not supported on Unix platforms with Intel Fortran for non-bind(c) routines.

But I would assume based on it being a remark, rather than a warning or error, that these attributes are simply ignored. The Meson build displays the same messages and goes through just fine.

@awvwgk
Copy link
Copy Markdown
Member

awvwgk commented Jul 19, 2022

But I would assume based on it being a remark, rather than a warning or error, that these attributes are simply ignored. The Meson build displays the same messages and goes through just fine.

I see, it is a linking error due to CMake failing to properly detect BLAS and LAPACK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants