- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
The essence of the problem is shown below:
! In DLL 1 (Fortran) ! ==> File: my_mod.f90 module my_mod type my_type contains end type my_type contains subroutine my_sub() bind(c,name='MY_SUB') !DEC$ ATTRIBUTES DLLEXPORT :: MY_SUB end subroutine my_sub end module my_mod ! ==> End file ! File: another.for subroutine another_sub use my_sub type(my_type) :: t end subroutine another_sub ! ==> End file ! MY_SUB is also specified in the EXPORTS section of the .def file for the DLL ! =============================================================================
// In DLL 2 (C++) // File: dll2.cpp extern "C" { void MY_SUB(); }; void dll2_proc() { MY_SUB(); } // ==> End file
When I try to build DLL2 I get a link error that MY_SUB is missing unless I include the 'another.for' file in DLL1, so the behaviour is that the symbol MY_SUB is exported iff the module is used in DLL1; note that the subroutine another_sub has to be called in another part of DLL1 that gets used elsewhere. Adding the symbol to the .def file and DLLEXPORTS directive has no effect. I have tried this with VS2010 &IFV14, and VS2012 & IVF16 and the result is the same. Is this a known problem with a known solution?
コピーされたリンク
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
When you built the first DLL, an import library was built (probably with the same name as the DLL and with ".lib" as suffix). Use that library in the command used to build the second DLL. That import library contains information regarding where the actual machine code for the function is to be found (in the first DLL, not in the import library) and how to link to it.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
Thanks for that. I've tried it and it creates a different problem (multiple symbol definitions). I think this is probably a cosnequence ot the way we build our application.
The solution contains about 70 projects and comprises C++, C# and Fortran code. For the C# code there is a 1:1 correspondence with directories but the C++ and Fortran code are mixed together. Since it isn't possible to have C++ and Fortran in the same project file (is this a VS restriction?) we build a '.lib' file from the Fortran and include that in the DLL created from the C++. What is happening here is that the MY_SUB symbol is not used and so is never loaded from the '.lib' file.
I have found a solution: set Force Symbol References to MY_SUB in the Linker>Input section of the C++ project file and the Fortran project file (DLL1 in my example).
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
There are a number of linker options (such as /force:multiple) that are intended to resolve problems of the type that you described, and I have had several occasions to use those options. I do my builds with makefiles or batch files, but I am sure that you can also specify such linker options in the VS project/solution property tabs.
Of course, if you have two different routines with the same linker name, whether in static or dynamic libraries, you have to be careful and make sure that the appropriate one is used in each linking step, but you are probably on top of such issues given the size of your project.
