Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to get a Visual Studio 2017 project to link, but I'm stuck on the following linker error:

LINK : fatal error C1007: unrecognized flag '-Ot' in 'p2'

I've read questions on what the cause could be, but I couldn't come to a solution for my project.

The details are that, due to an external component we have no control over (component A), this Visual Studio 2017 project is forced to use the v14.13 version of the C++ toolchain, i.e. not the latest one (v14.14). However, the latest release of another external precompiled static lib we have no control over either (component B), is built with the v14.14 version (I checked via a dumpbin extract of the debug version of the lib). Switching my project over to the v14.14 toolchain indeed makes the link error go away on component B, but this unfortunately isn't a solution for me due to component A. Taking an earlier version of component B isn't desirable either, since we need the functionality in the latest release...

However, what strikes me, is that the /Ot ("optimize for speed") flag has been around since the middle ages... Why wouldn't v14.13 recognize it? Or is it just an (awkwardly manifested) matter of a mismatched obj file layout due to the version differences? And, probably related, what does the 'p2' stand for anyway?

Update

I've checked the linker output by using the /verbose flag, and all seems normal (3600 lines of Searching <lib> , Found <function> , Referenced in <obj> and Loaded <lib> ).

Right up until the end that is, where I get the following 6 lines:

1>    Searching C:\PathToExternalLib\TheirStatic.lib:
1>      Found UsedFunctionName
1>        Referenced in MyOwnStatic.lib(MyOwnCompileUnit.obj)
1>LINK : fatal error C1007: unrecognized flag '-Ot' in 'p2'
1>LINK : fatal error LNK1257: code generation failed
1>Done building project "MyProject.vcxproj" -- FAILED.

And that's that.

When visiting the command line setting of the link properties of the project, the only thing listed is (broken up in separate lines for convenience):

/OUT:"MyProject.dll"
/MANIFEST
/NXCOMPAT
/PDB:"MyProject.pdb"
/DYNAMICBASE "C:\PathToMyStatic.lib"
/IMPLIB:"MyProject.lib"
/MACHINE:X64
/PGD:"MyProject.pgd"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'"
/ManifestFile:"MyProject.prm.intermediate.manifest"
/ERRORREPORT:PROMPT
/NOLOGO
/LIBPATH:"C:\PathToExternalStaticLib"
/LIBPATH:"C:\PathToAnotherExternalStaticLib"
/TLBID:1 

So no trace of any -Ot flag there as well...?

Ot is (and always has been) a compiler option, not a linker one. Can you try setting /VERBOSE linker flag ('show progress' in the options), search the output for Ot and say where it comes from? – Ofek Shilon Nov 16, 2018 at 10:41 I've checked, but it didn't provide anything new I'm afraid... See the added Update section of my post on the new details. But while I'm still intrigued by this, we have decided to move on and use an older version of Visual Studio (not the 14.13 VS2017 toolchain, but the proper VS2015 toolchain); doing so makes this error moot (the VS2015 version of their static lib plays nice), as well as giving us some extra backward-compatibility benefits with other external components. So a big thanks for your effort so far, and I'll leave it up to you if you want to continue investigating :) – Carl Colijn Nov 19, 2018 at 9:36 Sure. For what it's worth, I see that for others a VS reinstall solved an identical issue: github.com/xmrig/xmrig/issues/630 – Ofek Shilon Nov 20, 2018 at 8:49

I had this problem. LINK : fatal error C1007: unrecognized flag '-Ot' in 'p2' while building a project with Visual Studio 2015. I had to rebuild any library or sub library the project linked to which were built with Visual Studio 2017. Once I rebuild the dependent libraries with Visual Studio 2015 the first project was able to link against them.

project

--------\ ---------lib1(unable to rebuild lib1 until its dependencies were also rebuilt with VS2015 --------------\lib_linked_by_lib1_which_was_build_with_VS2017_and_had_to_be_rebuilt --------------\another_lib_which_had_to_be_rebuilt_for_lib1_with_VS2015

--------\lib2

--------\lib3

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.