Jared
Jared

Reputation: 6025

Error C1047: Object file created with an older compiler than other objects

I have a project that I'm building in C++ in Release mode in Visual Studio 2008 SP1 on Windows 7 and when I build it I keep getting:

fatal error C1047: The object or library file '.\Release\foobar.obj' was created with an older compiler than other objects; rebuild old objects and libraries.

The error occurs while linking.

I've tried deleting the specific object file and rebuilding but that doesn't fix it. I've also tried blowing away the whole release build folder and rebuilding but that also didn't fix it. Any ideas?

Upvotes: 38

Views: 64683

Answers (11)

David
David

Reputation: 11

I try everything here... and my mistach become of a bad reference and duplicate GUID (between 2010 and 2015 project... the hell of copy/past project)

During project migration from VS2008 to 2010 and 2015. We keep all project version XXX.vxproj (for VS2010) and XXX_2015.vxproj (for VS2015).

And in one of them in 2015 solution we got a reference to 2010 project !

So check REFERENCE... and never duplicate GUID.

Upvotes: 1

Pierre
Pierre

Reputation: 4416

I was able to fix this problem in VS 2015 with the following steps.

[1] (Not sure this was necessary) Turn off /GL in all components

C/C++ > Optimization > Whole program Optimization > No

In the .VCXPROJ files it's:

<WholeProgramOptimization>false</WholeProgramOptimization>

Turn off /LTCG

Librarian > General > Link Time Code Generation

<LinkTimeCodeGeneration>false</LinkTimeCodeGeneration>  

[2] More important step, make sure all components are drawing from the same directories. My main EXE was using:

Release Include
$(WindowsSdkDir)include\um;$(WindowsSdkDir)include\shared;$(UniversalCRT_IncludePath);$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include
Release Library
$(VC_LibraryPath_x86);$(WindowsSdk_71A_LibraryPath_x86);

The .lib was using different directories (wrong):

Release Include
$(VC_IncludePath);$(WindowsSDK_IncludePath);
Release Library
$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86

I changed the .lib directories to be the same as the .exe, and the compilation error disappeared.

Upvotes: 15

Anand
Anand

Reputation: 509

With reference to MSDN, this error The object or library file 'file' was created with an older compiler than other objects; rebuild old objects and libraries is caused when object files or libraries built with /LTCG are linked together, but where those object files or libraries are built with different versions of the Visual C++ toolset.
This can happen if you begin using a new version of the compiler but do not do a clean rebuild of existing object files or libraries.
To resolve, rebuild all object files or libraries.

Upvotes: 0

cheburashka
cheburashka

Reputation: 31

It could also be that the offending library was built with a different "Platform Toolset" setting (in Project Properties->General).

Upvotes: 3

Gank
Gank

Reputation: 4677

Two ways:

1.Update to Sp1 to build the lib

2.Please check your build to make sure that Whole Program Optimization is disabled. For a static lib project, go to the property page and change “Configuration Properties->C/C++->Optimization->Whole Program Optimization” to “No”.

Upvotes: 8

Oliver Zendel
Oliver Zendel

Reputation: 2911

I had this problem but my solution differs:

For me the culprit was that an included external library was compiled with

/GL (=Enable link-time code generation under
      C/C++/ Optimization / Whole Program Optimization) 

using an older visual studio (2005). I rebuild said library in 2005 without /GL and the linker error disappeared in 2008. As MSDN states it has to do with the /LTCG setting, this is set automatically by the /GL flag: http://msdn.microsoft.com/en-us/library/ms173554%28v=vs.80%29.aspx

Upvotes: 20

mark
mark

Reputation: 5469

Anyone finding this thread looking for answers... I ran into this as well, but it wasn't a SP1 problem or a rebuild problem or a PCH problem... it ended up being a library that was built with a more recent version of VS trying to link into a project on the older VS. While that sounds obvious, the odd part was VS2008 was reporting that an object that it compiled was the cause of the problem which sent me on a wild goose chase...

Upvotes: 5

Eric
Eric

Reputation: 11

I had the same problem too, and my visual Studio About box reported I had SP1 installed. Apparently that was not entirely true. Investigation on my specific occurance to this problem reveiled the resource compiler seemed to be the culprid. It happened to be an older version, that caused the mentioned error message. My installed hotfixes (Windows update) did not solve that problem. Maybe I missed a crucial one.....

Hopefully we once experience the day developers will actually communicate back the real problem in their generated error messages. :-) 'an older version of a compiler....' come on guys, you can do better than that ;-)

Anyways, here is the downloadlink to the latest SP1 for VS2008 i've used to solve this problem.

http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&displaylang=en

Happy coding.

Upvotes: 1

learnvst
learnvst

Reputation: 16193

I had the same problem, but a straight up reinstall did not fix it. I was using the version I found here

https://www.dreamspark.com/Products/Product.aspx?ProductId=9

However, after trawling forums I found that installing VS2008 SP1 Express eliminates this problem. . . .

http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=f3fbb04e-92c2-4701-b4ba-92e26e408569

You have to be careful which place you download VS2008 from as different versions of the same Express product are available for download.

Upvotes: 0

Tobiesque
Tobiesque

Reputation: 762

I would suggest reinstalling VS 2008 SP1. Have you installed a different VS (e.g. VS Express) in the meantime? This is known to cause interference with an existing VS installation.

You could try checking the compiler and linker versions by running cl.exe and link.exe from the Visual Studio command prompt.

Upvotes: 12

shoosh
shoosh

Reputation: 79021

Check if you have a .pch (precompiled header) file somewhere in the project directory and erase it. then rebuild the project.
The best way to get a clean build is using Build->Clean or Build->Rebuild All

Edit: Another thing you can try that is pretty much fail safe is to recreate the project file in a new directory from only the source files.
If that works then you can incrementally compare the old project with the new one to see what does wrong.

Upvotes: -1

Related Questions