Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Beginner Question about __imp_

tiek
Beginner
1,084 Views
Hello!
I have a little problem with a static lib here.
When I compile a console test program that uses it I get the following error:

Test.obj : error LNK2019: unresolved external symbol __imp_MethodName referenced in function _TESTMODULE_mp_EXECUTETEST

A dumpbin of my obj file gives me the expected:
03B 00000000 UNDEF notype External | __imp_MethodName

A dumpbin of my static lib shows:
00A 00000006 SECT1 notype () External | MethodName
03E 00000000 SECT4 notype Static | MethodName$FUNCTNAME

Where does the "__imp_" come from ? And how do Iget rid of it.

Thanks in advance and sorry for my poor english.
0 Kudos
4 Replies
mecej4
Honored Contributor III
1,084 Views
Look for compiler directives in your sources that declare MethodName as a DLLIMPORT. Remove or comment out the directive, if you want to link statically to the routine.
0 Kudos
tiek
Beginner
1,084 Views
Hello!
I searched my sources for DLLIMPORT and found nothing.
Wrong search term?



BTW: I also build the above Lib as a DLL and use it with my Testprogram. This works fine for me.
0 Kudos
tiek
Beginner
1,084 Views
Hello again!

I want to build my sources as a static lib AND as a DLL.

When I build my sources as LIB everything now is fine.
When I Build it as a DLL I get the following error message types:
error LNK2019: unresolved external symbol _MODULENAME_mp_METHODNAME

Now I change my source and add !DEC$ ATTRIBUTES DLLEXPORT :: MethodName

Now my DLL builds fine.
But my static lib gives me an error like:
error LNK2019: unresolved external symbol __imp_MethodName referenced in function ...

How do I get both to work?

0 Kudos
IanH
Honored Contributor III
1,084 Views
Create two separate projects, one that builds the static lib and the other builds the DLL. In both projects, add your source files (a source file can be in multiple projects).

In the source file you can conditionally compile the DLLEXPORT directive, so that when you are building the static lib the DLLEXPORT directive is not active. The _DLL symbol is defined when a DLL is being built.

SUBROUTINE MyFunction
!DEC$ IF DEFINED(_DLL)
!DEC$ ATTRIBUTES DLLEXPORT :: MyFunction
!DEC$ ENDIF

Alternatively, your DLL could be a thin forwarding wrapper around the functions in the static lib. The DLL then links to the static lib. Requires that you write the wrapper code though.
0 Kudos
Reply