Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC 2017 + Intel Compiler v19.0: Fails to compile in pre-compiled header mode unless "Enable Interprocedural Optimisation" is switched on #1295

Closed
sharpe5 opened this issue Aug 31, 2019 · 2 comments

Comments

@sharpe5
Copy link

sharpe5 commented Aug 31, 2019

IOW

If using MSVC 2017 + Intel Compiler v19.0, the linker error below can be eliminated by switching on: Interprocedural Optimization: Multi-File (/Qipo).

This is nothing to do with the {fmt} library, it appears to be a bug in the Intel Compiler.

Details

When compiling {fmt} with MSVC 2017 + Intel Compiler v19.0, the following compile error may occur if the {fmt} libraries are included in the file pch.h (i.e. the pre-compiled header file):

  • This error will never occur if switching to the MSVC compiler.
  • This error will not occur if the {fmt} header files are not included in pch.h (i.e. they are included in main.cpp).
  • This error typically occurs in Debug mode, but not in Release mode as this mode has a default of Interprocedural Optimization: Multi-File (/Qipo).

Linker error:

2>pch.obj : : error LNK2005: "union std::_Align_type<double,16> `class std::_Generic_error_category & __cdecl std::_Immortalize<class std::_Generic_error_category>(void)'::`2'::_Storage" (?_Storage@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A) already defined in Main.obj
2>pch.obj : : error LNK2005: __cp_array_end_?_Storage@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A already defined in Main.obj
2>pch.obj : : error LNK2005: "union std::_Align_type<double,16> `class std::_Iostream_error_category & __cdecl std::_Immortalize<class std::_Iostream_error_category>(void)'::`2'::_Storage" (?_Storage@?1???$_Immortalize@V_Iostream_error_category@std@@@std@@YAAEAV_Iostream_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A) already defined in Main.obj
2>pch.obj : : error LNK2005: __cp_array_end_?_Storage@?1???$_Immortalize@V_Iostream_error_category@std@@@std@@YAAEAV_Iostream_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A already defined in Main.obj
2>pch.obj : : error LNK2005: "union std::_Align_type<double,16> `class std::_System_error_category & __cdecl std::_Immortalize<class std::_System_error_category>(void)'::`2'::_Storage" (?_Storage@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A) already defined in Main.obj
2>pch.obj : : error LNK2005: __cp_array_end_?_Storage@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A already defined in Main.obj
2>Test.obj : : error LNK2005: "union std::_Align_type<double,16> `class std::_Generic_error_category & __cdecl std::_Immortalize<class std::_Generic_error_category>(void)'::`2'::_Storage" (?_Storage@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A) already defined in Main.obj
2>Test.obj : : error LNK2005: __cp_array_end_?_Storage@?1???$_Immortalize@V_Generic_error_category@std@@@std@@YAAEAV_Generic_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A already defined in Main.obj
2>Test.obj : : error LNK2005: "union std::_Align_type<double,16> `class std::_Iostream_error_category & __cdecl std::_Immortalize<class std::_Iostream_error_category>(void)'::`2'::_Storage" (?_Storage@?1???$_Immortalize@V_Iostream_error_category@std@@@std@@YAAEAV_Iostream_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A) already defined in Main.obj
2>Test.obj : : error LNK2005: __cp_array_end_?_Storage@?1???$_Immortalize@V_Iostream_error_category@std@@@std@@YAAEAV_Iostream_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A already defined in Main.obj
2>Test.obj : : error LNK2005: "union std::_Align_type<double,16> `class std::_System_error_category & __cdecl std::_Immortalize<class std::_System_error_category>(void)'::`2'::_Storage" (?_Storage@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A) already defined in Main.obj
2>Test.obj : : error LNK2005: __cp_array_end_?_Storage@?1???$_Immortalize@V_System_error_category@std@@@std@@YAAEAV_System_error_category@1@XZ@4T?$_Align_type@N$0BA@@1@A already defined in Main.obj
2>File.exe : : error LNK1169: one or more multiply defined symbols found

Cause of Issue

The line that triggers the linker error is this:

#include <iterator> // Included in `format.h`.

For the record, the project was rebuilt from scratch between switching compilers, so this is not an issue where old incompatible header files were left over from a previous build under a different compiler.

@sharpe5
Copy link
Author

sharpe5 commented Aug 31, 2019

As discussed, these linker errors are unrelated to the {fmt} library and appear to be a bug in the Intel Compiler v19.0.

As discussed, the error can be eliminated by using Interprocedural Optimization: Multi-File (/Qipo), or by not using precompiled headers.

I have raised this issue with the authors of Intel Compiler v19.0.

@sharpe5 sharpe5 closed this as completed Aug 31, 2019
@sharpe5 sharpe5 changed the title MSVC + Intel Compiler v19.0: Fails to compile in pre-compiled header mode unless "Enable Interprocedural Optimisation" is switched on MSVC 2017 + Intel Compiler v19.0: Fails to compile in pre-compiled header mode unless "Enable Interprocedural Optimisation" is switched on Aug 31, 2019
@sharpe5
Copy link
Author

sharpe5 commented Sep 11, 2019

If there are persistent Intel compiler errors that mention a lack of symbol "wmemcmp" during the linking phase, there is another, really heavy-handed solution: create a separate project, place the {fmt} library inside it, and compile it with MSVC. Then add this library to the main project which is compiled with Intel Compiler v19.0. The linkers for MSVC and Intel are 100% compatible, so everything should work well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant