cuda fortran dll link error

I created simple cuda fortran code in two forms, first as console application and second as dynamic link library. First case was alright (compiling, building and running without problems), but in second case an link error occurred:

pgf90 -Bdynamic -c cudainfodll.cuf
pgf90 -Mmakedll cudainfodll.obj -o cudainfo.dll
Creating library cudainfo.lib and object cudainfo.exp
cudainfodll.obj : error LNK2001: unresolved external symbol CUDAFOR
cudainfo.dll : fatal error LNK1120: 1 unresolved externals

I am using PGI Community Edition 17.4. Comparing both source codes I can send. Can anyone help me?

Thanks

Hi intelligentsoftware,

This error is occurring since you’re missing the flag “-Mcuda” on the link line. You don’t need “-Mcuda” on the compile line since it’s implied by the “.cuf” file suffix. However when the file is “.obj” the compiler doesn’t know you’re linking in a CUDA Fortran program so you need to add the flag to tell it to add the CUDA libraries.

Note that when using CUDA Fortran or OpenACC in a dynamic library you must also compile and link with the flag “-Mcuda=nordc”. Re-locatable device code (RDC) requires a device linker which is not available for dynamically linked libraries. Without RDC, you will not be able to access module data from external modules or call device routines contained in external modules or files.

Hope this helps,
Mat

Hi Mat,

thank you very much, now is all OK.

Milos