Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.

Linking Error

kulachi
Beginner
1,154 Views

!Warning (Newbie here!)

I am using the trial version of Intel Visual Fortran on a 64bit system. Today, I read about mixing C and Fortran code, opened the sample project "c_calls_Fortran" and build it. Nothing went wrong, and the resulting executable file was working nicely (as expected!). I tried it for both versions i.e. DLL and Static LIB. Then I opened another copy of Visual Studio 2005, created a duplicate multi-project for just the Static LIB version, and simply did a copy-paste of the code from the sample project. However, when I tried to build it, (without any modifications to the code) it did not work :(

When I build the Fortran routine, it produces the following error:

1>------ Build started: Project: bingo, Configuration: Debug Win32 ------
1>Compiling with Intel Fortran Compiler 10.1.011 [IA-32]...
1>Source1.F90
1>Linking...
1>libifcoremt.lib(for_main.obj) : error LNK2019: unresolved external symbol _MAIN__ referenced in function _main
1>Debugingo.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build log written to "file://C:Program Files (x86)IntelCompilerFortran10.1.011samplesMixedLanguageingoingoDebugBuildLog.htm"
1>bingo - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I read about similar errors on this forum and tried many options, but the error would not leave. The strange thing is that the same code works when I open the original project. Save me from banging my head against the keyboard :-)

0 Kudos
8 Replies
kulachi
Beginner
1,154 Views
I managed to find out one mistake! I have to add the fortran project as a Static Library. I was just adding it as a console application. Now when I build, the fortran project goes ahead nicely. The C part is still adamant. Here is the new error log I am getting:

Note: I changed the file/project(s) names to keep track of my mistakes. If it causes any confusion, just treat this as a new Solution altogether.


1>------ Build started: Project: Lib1, Configuration: Debug Win32 ------
1>Compiling with Intel Fortran Compiler 10.1.011 [IA-32]...
1>Source2.F90
1>Creating library...
1>
1>Build log written to "file://C:Program Files (x86)IntelCompilerFortran10.1.011samplesMixedLanguageBINGOLib1DebugBuildLog.htm"
1>Lib1 - 0 error(s), 0 warning(s)
2>------ Build started: Project: HUHA, Configuration: Debug Win32 ------
2>Compiling...
2>Source3.cpp
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludestdio.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludecrtdefs.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludesal.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludevadefs.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludeswprintf.inl
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludestring.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludecrtdefs.h
2>c:program files (x86)intelcompilerfortran10.1.011samplesmixedlanguageingohuhasource3.cpp(66) : warning C4996: 'strcpy' was declared deprecated
2> c:program files (x86)microsoft visual studio 8vcincludestring.h(73) : see declaration of 'strcpy'
2> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
2>Linking...
2>Source3.obj : error LNK2019: unresolved external symbol _FSUB referenced in function _main
2>C:Program Files (x86)IntelCompilerFortran10.1.011samplesMixedLanguageBINGODebugHUHA.exe : fatal error LNK1120: 1 unresolved externals
2>Build log was saved at "file://c:Program Files (x86)IntelCompilerFortran10.1.011samplesMixedLanguageBINGOHUHADebugBuildLog.htm"
2>HUHA - 2 error(s), 1 warning(s)
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

You would notice that libifcoremt.lib(for_main.obj) : error LNK2019 is gone, and now we have to face error LNK2019: unresolved external symbol _FSUB referenced in function _main

I guess this would be something minor (as in some option to lit or fire) but I am missing it altogether. Help please.


0 Kudos
Steven_L_Intel1
Employee
1,154 Views
Three things required.

1. Right click on the C project, select Dependencies. Set the static library project as a dependent of the executable project
2. Install VS2005 SP1. Without that, MSVC will ignore non-MSVC projects as dependencies
3. Tools > Options > Projects > VC++ Directories > Library Files. Add the path to the Intel Fortran LIB folder to this list. Note that the path will change each time you install a new compiler version.
0 Kudos
kulachi
Beginner
1,154 Views
Many thanks Steve. This is what I did:

1. Downloaded and installed VS2005 SP1,
2. Started a fresh copy of the project (same example code)
3. Added Intel Fortran Lib and appropriate dependency of C project on Fortran Project.

This rather had a good impact. The previous error left, with a vengeance though! Now I am getting the following long list of errors. You would notice that probably I am quoting a reference to some library twice (note the red text and then the underlined text following it):

1>------ Build started: Project: Fproj, Configuration: Debug Win32 ------
1>Compiling with Intel Fortran Compiler 10.1.011 [IA-32]...
1>SUBF.F90
1>Creating library...
1>
1>Build log written to "file://C:Documents and SettingsAdministratorDesktopFORTCprojFprojDebugBuildLog.htm"
1>Fproj - 0 error(s), 0 warning(s)
2>------ Build started: Project: Cproj, Configuration: Debug Win32 ------
2>Compiling...
2>MainC.cpp
2>c:documents and settingsadministratordesktopfortcprojcprojmainc.cpp(66) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:program files (x86)microsoft visual studio 8vcincludestring.h(74) : see declaration of 'strcpy'
2>Linking...
2>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __CrtSetCheckCount already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(setlocal.obj) : error LNK2005: __configthreadlocale already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRTD.lib(cinitexe.obj)
2>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRTD.lib(cinitexe.obj)
2>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRTD.lib(cinitexe.obj)
2>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRTD.lib(cinitexe.obj)
2>LIBCMTD.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRTD.lib(MSVCR80D.dll)
2& gt;LIBCMTD.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in MSVCRTD.lib(crtexe.obj)
2>LIBCMTD.lib(printf.obj) : error LNK2005: _printf already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVCRTD.lib(MSVCR80D.dll)
2>LIBCMTD.lib(dbgrptw.obj) : error LNK2005: __CrtDbgReportW already defined in MSVCRTD.lib(MSVCR80D.dll)
2>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
2>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)

2>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
2>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library

2>C:Documents and SettingsAdministratorDesktopFORTCprojDebugCproj.exe : fatal error LNK1169: one or more multiply defined symbols found
2>Build log was saved at "file://c:Documents and SettingsAdministratorDesktopFORTCprojCprojDebugBuildLog.htm"
2>Cproj - 26 error(s), 3 warning(s)
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


What I tried next was to take away the reference to Intel Fortran Lib (your suggestion No. 3). Now there is only one error left:

1>------ Build started: Project: Fproj, Configuration: Debug Win32 ------
1>Compiling with Intel Fortran Compiler 10.1.011 [IA-32]...
1>SUBF.F90
1>Creating library...
1>
1>Build log written to "file://C:Documents and SettingsAdministratorDesktopFORTCprojFprojDebugBuildLog.htm"
1>Fproj - 0 error(s), 0 warning(s)
2>------ Build started: Project: Cproj, Configuration: Debug Win32 ------
2>Compiling...
2>MainC.cpp
2>c:documents and settingsadministratordesktopfortcprojcprojmainc.cpp(66) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:program files (x86)microsoft visual studio 8vcincludestring.h(74) : see declaration of 'strcpy'
2>Linking...
2>LINK : fatal error LNK1104: cannot open file 'ifconsol.lib'
2>Build log was saved at "file://c:Documents and SettingsAdministratorDesktopFORTCprojCprojDebugBuildLog.htm"
2>Cproj - 1 error(s), 1 warning(s)
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I am still working on it. What would you suggest next?

-Kulachi




0 Kudos
Steven_L_Intel1
Employee
1,154 Views
You have "Mixed C Library Syndrome". Make sure that the run-time library type selection is the same in your C and Fortran projects. You have Debug Multithread in one and Debug Multithread DLL in the other.
0 Kudos
kulachi
Beginner
1,154 Views
Well, looks like I have solved it without knowing exactly what I did! This is what I 'did' after my last post:

1. Opened two copies of the MSVC, opened my own project in one and the Intel example in the other.
2. Right clicked on the C project, in both MSVC copies, and compared the settings, line by line.
3. They were both the same except that the Intel example had a few more options in {Configuration Properties .. General .. C/C++ .. Command Line}.
4. So I copy-pasted all of these in my own project, in the same section, in the Edit Box labeled {Additional Options}.

Now when I compiled the solution, it worked. I changed my code a bit and recompiled, and it still worked. I am pasting the compilation dump below:


1>------ Build started: Project: Fproj, Configuration: Debug Win32 ------
1>Compiling with Intel Fortran Compiler 10.1.011 [IA-32]...
1>SUBF.F90
1>Creating library...
1>
1>Build log written to "file://C:Documents and SettingsAdministratorDesktopFORTCprojFprojDebugBuildLog.htm"
1>Fproj - 0 error(s), 0 warning(s)
2>------ Build started: Project: Cproj, Configuration: Debug Win32 ------
2>Compiling...
2>cl : Command line warning D9025 : overriding '/MDd' with '/MTd'
2>MainC.cpp
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludestdio.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludecrtdefs.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludesal.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludevadefs.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludeswprintf.inl
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludestring.h
2>Note: including file: C:Program Files (x86)Microsoft Visual Studio 8VCincludecrtdefs.h
2>c:documents and settingsadministratordesktopfortcprojcprojmainc.cpp(66) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
2> c:program files (x86)microsoft visual studio 8vcincludestring.h(74) : see declaration of 'strcpy'
2>Linking...
2>LINK : C:Documents and SettingsAdministratorDesktopFORTCprojDebugCproj.exe not found or not built by the last incremental link; performing full link
2>Embedding manifest...
2>Build log was saved at "file://c:Documents and SettingsAdministratorDesktopFORTCprojCprojDebugBuildLog.htm"
2>Cproj - 0 error(s), 2 warning(s)
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


But I still don't know the answer. Would you explain what I was supposed to do to make it work? The error seemed to generate from a double reference to some library. So what did I do that made the obnoxious error surrender?

I am pasting the Command Line Options (that I mentioned above) below, for easy comparison.

FROM: Intel Fortran Example
{Configuration Properties .. General .. C/C++ .. Command Line}:

/Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_VC80_UPGRADE=0 x0710" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /Fo"Debug" /Fd"Debugvc80.pdb" /W3 /nologo /c /Wp64 /ZI /TP /errorReport:prompt


FROM: My Duplicate Example (Copy-Paste of Intel Fortran example)

/Od /D "_MBCS" /Gm /EHsc /RTC1 /MDd /Fo"Debug" /Fd"Debugvc80.pdb" /W3 /nologo /c /ZI /TP /showIncludes /errorReport:prompt

Would you highlight any learnings for future reference.

Now I am heading to convert my gigantic MATLAB project into Fortran!

-Kulachi
0 Kudos
kulachi
Beginner
1,154 Views
Oh, I see! Let me check that out.
0 Kudos
kulachi
Beginner
1,154 Views
Many thanks Steve! Just one last question. I could not find an option in the Fortran project to change the Runtime Library. For the C project, I found it at {Configuration Properties .. General .. C/C++ .. Code Generation .. Runtime Library}. Here I changed it to Multi-threaded Debug (/Mtd). Would you point out where I can find it in Fortran project properties?

Once again, your help was much appreciated.

-Kulachi
0 Kudos
Steven_L_Intel1
Employee
1,154 Views
Fortran > Libraries > Use Runtime Library.
0 Kudos
Reply