Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29262 Обсуждение

CALL A FUNCTION IN A PROVIDED DLL

Guaglardi__Paul
Начинающий
1 783Просмотр.

I have not posted in a while and am not sure that I am in the correct location to pose this question.

Regardless, I have been provided a DLL from which I want to invoke a function that is within the DLL.

I know the function name and the argument list.

I have declared the function.

No mater what I do, set DLL as a resource or go to TOOLS COMPILERS and add the directory to the list of places to look, I am constantly getting UNRESOLVED LINK.

Any help?

How can I get access to this DLL and the functions within this DLL?

0 баллов
12 Ответы
Steve_Lionel
Почетный участник III
1 783Просмотр.

If all you have is a DLL, you can't link to it. Linking requires a .LIB - for DLLs an "export .LIB" is created when the DLL is linked.

Since you don't have that, you have to dynamically load the DLL, get the address of the procedure and then call it. This is illustrated in the compiler_f\DLL\DynamicLoad sample that is part of the Intel Parallel Studio XE for Windows Sample Bundle (make sure you get the one for Windows.)

Guaglardi__Paul
Начинающий
1 783Просмотр.

Turns out that I do have the .LIB.

So, should I just put the .LIB in the same directory as the DLL?

Guaglardi__Paul
Начинающий
1 783Просмотр.

I did put the appropriate .LIB in the folder and then through the TOOLS COMPILERS put the path into the X64 tab for Libraries and it still did not work.  I am confused here why it cannot see the DLL nor the embedded function.

Steve_Lionel
Почетный участник III
1 783Просмотр.

Just putting the .LIB in the folder doesn't do anything. You have to tell the linker to look in the .LIB. The easiest way to do that is to add the .LIB to your project as if it were a source file. An alternative is to give the name of the .LIB in the project property Linker > Input > Additional Dependencies. 

I would not recommend modifying the Tools ... Compilers tab unless this is a location you want to use for all projects. Linker > General > Additional Library Directories is a place you can add project-specific paths.

The DLL itself needs to be in a place Windows will look for it. In the same folder as the EXE will work.

GVautier
Новый участник III
1 783Просмотр.

Hello

The static library .lib associated with a dynamic library .dll contains for each function the necessary code to call to each of them.

It must be linked with the application and the .dll file is not required at this step.

At runtime, the .dll file must be in a location where the application can find it, in the same directory as the .exe is a common place. See Windows documentation to get information of search mechanism for .dll.

If you don't have the .lib file, call to .dll functions can be done using the loadlibray and getprocaddress functions. refer to the documentation of these functions.

 

Guaglardi__Paul
Начинающий
1 783Просмотр.

Steve, thanks as always.  I did end up adding as a dependency and the error has changed.  Now, instead of saying it cannot find the function name, it is throwing that it cannot open an input file C:\PROGRAM.obj

 

Any clues?

Lorri_M_Intel
Сотрудник
1 783Просмотр.

Perhaps, you needed to put the full filename of your external library in quotes due to embedded spaces?

This looks  suspiciously like the linker was passed this:

             link  foo.obj c:\program files (x86)\SomeDirectory\SomeOther\mylib.lib

and parsed the command line as having these files:

            foo.obj
           c:\program.obj
            files.obj
           (X86)\SomeDirectory\SomeOther\mylib.lib

 

 

Guaglardi__Paul
Начинающий
1 783Просмотр.

I have enclosed an image of how I have implemented the entry.

 

C:\PROGRAM FILES\GPS\IP2LIB64.LIB

 

This was entered under LINKER and then under INPUT.

Steve_Lionel
Почетный участник III
1 783Просмотр.

Enclose the path in ""

Guaglardi__Paul
Начинающий
1 783Просмотр.

thanks for the different input.

i have looked at the tips at the bottom of the properties as i move through the lists.

finally, or maybe not, i have the following error: unresolved...cannot open 'JHJHJH.lib'

 

any ideas?

mecej4
Почетный участник III
1 783Просмотр.

It is not possible to tell you what to do if you report only the error messages without also reporting what steps you took earlier that may have caused those messages to be given.

For instance, the file name 'JHJHJH.lib' is not a random name. You must have typed it in into some Visual Studio setting, perhaps by mistake.

Steve_Lionel
Почетный участник III
1 783Просмотр.

Attach a ZIP file with your .vfproj file and the buildlog.htm, from the Debug or Release folder after a failed build. This will let us see what you are doing.

Ответить