none
LNK2001 and LNK2019 unresolved external symbol -- Link errors in a C / Fortran Solution

    Question

  • My Solution Explorer is comprised of three projects in the solution.  The main project is a Visual C++ Console application that includes a single .c source main module and one supporting .h header file.  The other two projects are respectively:  a) a Visual C++ class library composed of many .c source and .h header files; and b) an Intel Visual Fortran Library composed of many .f source and .inc include files.  The C calls the Fortran routines, and some of the Fortran calls the c routines.

    All of the Fortran successfully compiles, and the project successfully builds a '.lib'.   The path to the .lib is included as an "Additional Include Directory" in the C/C++ General Project Properties pages of the C-Lib project

    The Project Build Order is as follows:  F-Lib, C-Lib, Main (where Main Depends on the C-Lib and C-Lib depends on F-Lib).

    I'm encountering LNK2001 and LNK2019 unresolved external symbols related to Pointers to the Fortran commons (includes) in the C-lib project.

    A snippet from a C routine flagged with a LNK2001 error:

    void

    clean_run_option_()

    {

         cleanRunOption(&run_option_common_);

    }

    'run_option_common.inc' is one of the includes in the FLib project, that I would think should get resolved by the inclusion of the path to the .lib (Fortran) in the properties pages of the C-Lib project.  Obviously something is not set right to resolve the external symbol by the Linker.

    Appreciate any questions, comments, guidance toward resolution.

    Tuesday, June 19, 2012 11:41 PM

All replies

  • Hi Ramassey,

    Error LNK2001 has three possible causes. You can refer to http://msdn.microsoft.com/en-us/library/f6xx1b1z(v=vs.100).aspx.

    If you can't find the cause, please show your error messages and command lines.

    Best regards,

    Ego

    Wednesday, June 20, 2012 8:59 AM
    Moderator
  • Hello Ego,

    Thank you for the reply.  I investigated the presence of the /Zi option in the clib project C/C++ Command Line Property Page.  There is a single /Zi option present; however, it is immediately following the path the clib header files (and not, for example, the path to the fortran ('flib') project include files; i.e., the include files the names of which are behind the the LNK2001 unresolved external symbols at link time).

    Nonetheless I attempted to set the 'Yes (/ZI)' option in the 'Omit Default Library Name of the C/C++ Advanced Property page.  Upon cleaning and building the solution, this resulted in 557 LNK2001 and LNK2019 unresolved external symbols instead of 144 before.  The additional unresolved symbols were MS Visual Studio identified symbols, not any relationship to the proper source code in the project solution.

    I also added the following paths to the 'Additional Library Directories' of the Linker, General pages of both the main and clib projects, which made no difference in the number of LNK2001 and LNK2019 errors (144):

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\msvcrt.lib

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\msvcmrt.lib

    I then reviewed other possible causes in the msdn reference link you provided and, following my instincts, I don't believe any of those are directly applicable to the LNK errors associated with my Solution which, again, consists of a main C Visual C++ Console Application (call it 'main'), a Visual C++ Class Library project (call it 'clib'), and an Intel Visual Fortran Library (call it 'flib').  The issue is in linking the solution, which results in unresolved external references associated with the main and clib .c source files referencing the entry and include files of the Fortran flib.

    Following are the Option settings in the C/C++ Command Line page of the clib project:

    /I"C:\VM\share\SPEPH_svn\tools_ws\fortran\asw_er11_1_3000_msvs\spectr_clib\Header Files" /I"C:\VM\share\SPEPH_svn\tools_ws\fortran\asw_er11_1_3000_msvs\spectr_flib\Include Files" /Zi /nologo /W3 /WX- /Od /D "WIN32" /D "_DEBUG" /D "_CRT_SECURE_NO_WARNINGS" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"x64\Debug\spectr_clib_msvs.pch" /Fa"x64\Debug\" /Fo"x64\Debug\" /Fd"x64\Debug\vc100.pdb" /Gd /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll" /errorReport:queue

    Following are the Option settings in the C/C++ Command Line page of the main project:

    /I"C:\VM\share\SPEPH_svn\tools_ws\fortran\asw_er11_1_3000_msvs\spectr_cmain\Header Files" /Zi /nologo /W3 /WX- /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_WARNINGS" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"x64\Debug\spectr_cmain_msvs.pch" /Fa"x64\Debug\" /Fo"x64\Debug\" /Fd"x64\Debug\vc100.pdb" /Gd /errorReport:queue

    Appreciate your continued support in resolving these LNK errors.

    Wednesday, June 20, 2012 6:34 PM
  • Hi Ramassey,

    I think you did not link the .cpp files in your project.You should provide a compilation unit that defines the symbols that were declared in the header, and make the environment compile and link it together.

    Did you forget to link the library from your current project?

    Regards,

    Disley

    Monday, June 25, 2012 9:17 AM