I have some linking problems. Let me explain the dependency arrangement and hopefully we can figure this out.
static fortran library: foo.lib
static c library: bar.lib which depends on foo.lib
executable c program: baz.exe which depends on foo.lib and bar.lib
foo.lib has a subroutine:
SUBROUTINE AABB (RA,RB,AA,AB,A,B)
bar.lib has a a.c which wants to call AABB:
so in a.c I have:
extern aabb_();
…
void somefunc()
…
aabb_(&ra, &rb, &aa, &ab, &a, &b);
…
baz.exe wants to call somefunc()
but linking complains:
error LNK2019: unresolved external symbol aabb referenced in function _somefunc File: bar.lib(a.obj)
Please help! Thanks
And I have tried the following but it fails with:
Error 81 error LNK2005: __heap_alloc already defined in libcmt.lib(malloc.obj)
Error 82 error LNK2005: __recalloc already defined in libcmt.lib(recalloc.obj)
Error 83 error LNK2005: __msize already defined in libcmt.lib(msize.obj)
Error 84 error LNK2005: __crt_debugger_hook already defined in libcmt.lib(dbghook.obj)
Error 85 error LNK2005: __isctype_l already defined in libcmt.lib(isctype.obj)
Error 86 error LNK2005: __isctype already defined in libcmt.lib(isctype.obj)
Error 109 error LNK2019: unresolved external symbol __imp__strncpy referenced in function _xxxx
Error 110 error LNK2019: unresolved external symbol __imp__fwrite referenced in function _YYYYYY
Error 111 error LNK2019: unresolved external symbol __imp__fprintf referenced in function _zzzzz
Error 112 error LNK2019: unresolved external symbol __imp___localtime64 referenced in function _localtime
Error 113 error LNK2019: unresolved external symbol __imp___time64 referenced in function _time
Error 114 error LNK2019: unresolved external symbol __imp___stat64i32 referenced in function _stat
Error 115 error LNK2019: unresolved external symbol _foofoo_ referenced in function _aaaaa
Error 116 error LNK2019: unresolved external symbol _barbar_ referenced in function _bbbbbb
Error 117 error LNK2019: unresolved external symbol _parameters_ referenced in function _ccccccc
Error 118 error LNK2019: unresolved external symbol __imp__totor referenced in function _ssssssss
Error 119 error LNK1120: 10 unresolved externals
Add the PGI library directory, “C:\Program Files\PGI\win32\11.3\lib” to: “Linker | General | Additional Libraries Directories” (Adjust the PATH as necessary)
Then add the PGI Runtime libraries to “Linker | Input | Additional Dependencies”
Here’s the full list:
Code:
libpgmp.lib;pg.lib;libpgf90.lib;libpgf90_rpm1.lib;libpgf902.lib;libpgf90rtl.lib;libpgftnrtl.lib;libpgc.lib;libnspgc.lib;libcmt.lib;
Finally add “-nodefaultlib:msvcrtd” to “Linker | Command Line | Additional Options”. Note, change “msvcrtd” to “msvcrt” when changing from Debug to a Release build.
So I decided to combine the fortran and c objects into one library using ar from the pgi tools.
I removed libcmt.lib since that seems to have a lot of conflicts event with -nodefaultlib:msvcrtd.
With the new library and removal of libcmt.lib I now get some unresolved symbols such as:
___mth_i_dsinx
___mth_i_dcosx
___mth_i_dsincosx
___mth_i_dasinx
___mth_i_idnintx
libpgf90.lib(initpar.obj) : error LNK2019: unresolved external symbol __environ referenced in function _pgf90_compiled
libpgc.lib(pgstdinit.obj) : error LNK2001: unresolved external symbol __environ
Selecting the correct library type helps thanks to reading the documentation. Now I only can’t find the external symbol which is referenced from the static c library to the static fortran library.
I even broke this problem down to the very basics. One function in a fortran library, one function in a c library that calls the fortran function. one c executable that references both libraries. And I still get unresolved external symbol libclibrary.lib(someobject.obj)
Hi initialzero,
For the first problem, this looks like a calling conversion issue (See Chapter 12 “Win32 Calling Conventions” of the PGI User’s Guide). Try compiling the Fortran code with “-Miface=unix”.
Several of the Microsoft header files need to be compiled differently depending upon if you will be linking dynamically or statically. It seems to me that you’re compiling dynamically but linking statically. The “imp” symbols are import library symbols, i.e. the interface to a DLL call. The “__environ” symbol occurs when you build dynamically but link with static C runtime library (libcmt.lib), since this symbol is only available in the dynamic C runtime library (mscvrt.dll)
Hope this helps,
Mat