Carl Colijn
Carl Colijn

Reputation: 1617

Visual C++ 2017 link error due to -Ot flag?

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"
/DLL
/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...?

Upvotes: 2

Views: 3597

Answers (1)

Nathan Blackerby
Nathan Blackerby

Reputation: 31

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

Upvotes: 2

Related Questions