如何将dll链接到fortran(visual studio)? [英] how can I link a dll to fortran (visual studio)?

查看:435
本文介绍了如何将dll链接到fortran(visual studio)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一些简单的代码我是使用来了解如何。



使用visual studio我从这个创建了一个DLL

 子程序打印

!DEC $ ATTRIBUTES DLLEXPORT ::打印
打印*,dll naimi创建

结束子程序打印

我将DLL的链接添加到项目>属性>链接器>常规>其他库目录



主程序:

 程序Console11 
隐式无

打印

结束程序Console11

错误:错误1错误LNK2019:函数_MAIN __中引用的未解析的外部符号_PRINTING。



与此相关的其他解决方案建议使用在生成时创建的.lib DLL,但在我的实际情况下,我只有没有他们的DLL .lib。



所以如何使用DLL ...?

解决方案

您似乎试图使用DLL作为链接器的输入文件。



(您似乎也在尝试指定一个连接器选项的文件,该文件需要一个目录。要指定链接器的其他输入文件,请将文件添加到该项目就像您将附加一个源文件,或使用链接器>输入>附加依赖项项目属性。您在帖子中提及的属性告诉链接器哪里(哪个目录)搜索这些附加依赖项。)



与unix约定不同,在Windows上构建可执行文件和其他DLL时,不要链接DLL。 DLL通常不包含链接器的必要信息 - 而是将信息包含在导入库中(这只是典型的.lib静态库的一个变体)或等效的。



如果您能够成功构建DLL,那么您可能会在与DLL相同的目录中找到该DLL的导入库。提供该导入库作为需要DLL的项目的附加依赖项。



当您使用Windows上的导入库链接EXE或其他DLL时,目标DLL将自动当您的可执行代码加载时由操作系统加载。这被称为加载时间动态链接。



如果您没有DLL的导入库,那么您的选择是:




  • 向构建导入库的DLL的人询问。


  • 使用run时间动态链接,而不是加载时间。这意味着您使用程序中的Windows API函数LoadLibrary,GetProcAddress和朋友明确地告诉操作系统加载特定的DLL并获取函数指针的地址。如果您使用的是英特尔Fortran,那么完整的示例将与编译器一起安装 - 请参见文件C:\Program Files(x86)\IntelSWTools\samples_2016\en\compiler_f\psxe\DLL .zip或类似的文件。


  • 从DLL中的最小信息生成一个导入库,以及您可能拥有的其他有关该DLL的信息。一种方法是为DLL编写一个模块定义文件(.def),然后使用LIB实用程序将该def文件转换为导入库。请参阅如何以.dll文件和头文件为例,来制作一个.lib文件。



I have some DLLs that I want to use in a FORTRAN Project in VISUAL STUDIO but I can't find how.

Here is a simple code I'm using to find out how.

Using visual studio I created a DLL from this

  subroutine printing

  !DEC$ ATTRIBUTES DLLEXPORT::printing
  print*,"dll naimi created"

  end subroutine printing

I added the link of the DLL to project>properties>Linker>General>Additional Library directories

Main program:

program Console11
implicit none

call printing

end program Console11

ERROR : Error 1 error LNK2019: unresolved external symbol _PRINTING referenced in function _MAIN__.

other solutions related to this suggest using the .lib created while generating the DLL, but in my real case I only have the DLLs without their .lib.

So how to use a DLL ... ?

解决方案

You appear to be trying to use a DLL as an input file to the linker.

(You also appear to be trying to specify a file for a linker option that takes a directory. To specify an additional input file for the linker, either add the file to the project just like you would attach a source file, or use the "Linker > Input > Additional dependencies" project property. The property you mention in your post then tells the linker where (which directories) to search for those additional dependencies.)

Unlike the unix convention, you do not link against DLLs when building executables and other DLLs on Windows. The DLL typically does not contain the necessary information for the linker - instead that information is contained in an import library (which is just a variation of a typical .lib static library) or equivalent.

If you were able to successfully build a DLL, then you will probably find the import library for that DLL in the same directory as the DLL. Supply that import library as an additional dependency for projects that require the DLL.

When you link an EXE or other DLL using an import library on Windows, the target DLL is automatically loaded by the operating system when your executable code is loaded. This is called load time dynamic linking.

If you do not have the import library for a DLL, then your choices are:

这篇关于如何将dll链接到fortran(visual studio)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆