View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0011240CMakeCMakepublic2010-09-15 17:342016-01-04 11:51
Assigned To 
PlatformOSOS Version
Product VersionCMake-2-8 
Target VersionCMake 3.4Fixed in VersionCMake 3.4 
Summary0011240: VS 2010 Win64 does not correctly set /MACHINE:x64 in the solution project files
DescriptionAll my projects in the solution are missing a value for "Target Machine" under the Librarian general settings. Microsoft defaults to x86 when this happens and the link fails.
TagsNo tags attached.
Attached Filespng file icon Property.png [^] (54,003 bytes) 2010-09-15 17:34

zip file icon [^] (184,521 bytes) 2010-09-30 10:22

- Relationships Relation Graph ] Dependency Graph ]

-  Notes
Bill Hoffman (manager)
2010-09-15 17:42

I just tested this on my machine and although it is not specified as you claim, it did not cause any errors, and seemed to link just fine. Can you give a case where this fails?
Scott (reporter)
2010-09-15 18:16

This is the error I get, are you sure you are compiling 64 bit code?

3>LINK : warning LNK4068: /MACHINE not specified; defaulting to X86
3>NwUtils.dir\RelWithDebInfo\AppSettings.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
Bill Hoffman (manager)
2010-09-15 18:29

Yes, I just tested. I built Cmake with the Visual Studio 10 64 generator. The platform is x64 in the IDE. I have tried with both static and shared libraries and it works fine without that flag...
Scott (reporter)
2010-09-16 08:52

Hmm, I wish I knew how to fix it thru CMake. Right now, my only recourse is to manually change every project's "Target Machine" to /MACHINE:x64. Since this is a rather large solution with 25 projects, it's tedious to have to do it every time CMake regenerates.
Bill Hoffman (manager)
2010-09-16 10:26

If you could create a small project that shows the problem, I would be happy to fix this for you. I don't want to make changes for something I can not reproduce. What if you create a static library target via the GUI does it set this flag?
Scott (reporter)
2010-09-30 10:27

Okay, I've attached the smallest project I found that reproduces the problem.

Steps to recreate:

Extract to a directory.

Run CMake to create a build directory at the same level as src.
Use Visual Studio 10 WIN64 generator

Hit configure twice, should get output like this:

Could NOT find CxxTest (missing: CXXTEST_INCLUDE_DIR)
CMAKE_MODULE_LINKER_FLAGS is /STACK:10000000 /machine:x64
CMAKE_EXE_LINKER_FLAGS is /STACK:10000000 /machine:x64
CMAKE_SHARED_LINKER_FLAGS is /STACK:10000000 /machine:x64
Could NOT find objcopy
Setting precompiled to $(ProjectDir)/$(IntDir)/stdafx.pch
Configuring done

Generate and open solution.
Switch to RelWithDebInfo
Build Solution.

You should get the following output showing the error with NwUtils project:

1>------ Build started: Project: ZERO_CHECK, Configuration: RelWithDebInfo x64 ------
1> Checking Build System
1> CMake does not need to re-run because C:/Dev/cmake-error-2010-win64/build/CMakeFiles/generate.stamp is up-to-date.
1> CMake does not need to re-run because C:/Dev/cmake-error-2010-win64/build/NwUtils/CMakeFiles/generate.stamp is up-to-date.
1> CMake does not need to re-run because C:/Dev/cmake-error-2010-win64/build/zlib/CMakeFiles/generate.stamp is up-to-date.
2>------ Build started: Project: zlib, Configuration: RelWithDebInfo x64 ------
2> Building Custom Rule C:/Dev/cmake-error-2010-win64/src/zlib/CMakeLists.txt
2> CMake does not need to re-run because C:\Dev\cmake-error-2010-win64\build\zlib\CMakeFiles\generate.stamp is up-to-date.
2> adler32.c
2> compress.c
2> crc32.c
2> deflate.c
2> gzio.c
2> infback.c
2> inffast.c
2> inflate.c
2> inftrees.c
2> trees.c
2> uncompr.c
2> zutil.c
2> Generating Code...
2> zlib.vcxproj -> C:\Dev\cmake-error-2010-win64\build\lib\RelWithDebInfo\zlib.lib
3>------ Build started: Project: NwUtils, Configuration: RelWithDebInfo x64 ------
3> Building Custom Rule C:/Dev/cmake-error-2010-win64/src/NwUtils/CMakeLists.txt
3> CMake does not need to re-run because C:\Dev\cmake-error-2010-win64\build\NwUtils\CMakeFiles\generate.stamp is up-to-date.
3> stdafx.cpp
3> Base64.cpp
3>LINK : warning LNK4068: /MACHINE not specified; defaulting to X86
3>NwUtils.dir\RelWithDebInfo\Base64.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
4>------ Skipped Build: Project: ALL_BUILD, Configuration: RelWithDebInfo x64 ------
4>Project not selected to build for this solution configuration
========== Build: 2 succeeded, 1 failed, 0 up-to-date, 1 skipped ==========
Scott (reporter)
2010-09-30 10:34

I would also like to add there's another bug wrt VS 2010. It does not reload the solution correctly. It works correctly with VS 2008.

With VS 2010, you get the following error:

Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

and the solution fails to reload without a lot of manual "Reload" messages on every project under the solution. I typically just close the solution and reopen, just to be sure it correctly gets the changes.

You can easily see this problem by editing my project src/CMakeLists.txt and changing line 103 to something like this:


Then doing a Rebuild All from within VS 2010.
Scott (reporter)
2010-11-01 17:48

Any progress on this issue?
Bill Hoffman (manager)
2010-11-01 21:35

I found the source of the problem: [^]

So, in VS 2010, the resource file seems to want to come first when creating a library:

1>------ Build started: Project: NwUtils, Configuration: Debug x64 ------
1> Microsoft (R) Library Manager Version 10.00.30319.01
1> Copyright (C) Microsoft Corporation. All rights reserved.
1> "/OUT:C:\Users\hoffman\Desktop\test\cmake-error-2010-win64\src\b\lib\Debug\NwUtils.lib" NwUtils.dir\Debug\NwUtils.res
1> NwUtils.dir\Debug\Base64.obj
1> NwUtils.dir\Debug\stdafx.obj
1>LINK : warning LNK4068: /MACHINE not specified; defaulting to X86
1>NwUtils.dir\Debug\Base64.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========

In VS 9, it comes last (and works):
1>Copyright (C) Microsoft Corporation. All rights reserved.

So, the problem only shows up with static libraries that have resource files in them. And with the older VS versions the resource file came last.
Scott (reporter)
2010-11-02 08:34

Is this something that can be solved in CMakeLists.txt? It looks like I'm already putting resource files last:

Bill Hoffman (manager)
2010-11-02 09:44

No, it does not... I was not able to get VS 2010 to pick any different order.

There is a target property you could use.

So, this works:
set_target_properties(NwUtils PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")

You will want to put that in some if checking maybe for

This should of course be fixed in CMake, but that should get you going until the fix is done.
Scott (reporter)
2010-11-02 10:46

Okay, thanks for looking into this and the workaround. Is the VS 2010 solution reload issue getting fixed as well?
Vladislav Vaintroub (reporter)
2011-01-31 19:03

I see this as well. For me, this happens only with a single static library which is unique in that it has huge (I estimate 0000200:0000200-300) source files.
The whole project is about 100 targets, many of those static libraries. I can provide more info on how to reproduce it, if this is of any interest to anyone.
Vladislav Vaintroub (reporter)
2011-01-31 19:08

interesting markup here in mantis . I meant to say "200 to 300 source files" in the last comment
staticinline (reporter)
2011-05-24 13:26

I also got this error when building a 64-bit static library with an .rc file. The 'set_target_properties(NwUtils PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")' workaround is working for me though.
rvdn (reporter)
2011-10-06 10:22

I also have this issue, but the workaround mentioned here doesn't work for us. Can we get a fix in CMAKE?
Chris Scharver (reporter)
2011-11-07 15:17

I'm also seeing this with a static library containing a resource file. Setting the STATIC_LIBRARY_FLAGS lets me work around this for the time being.
edice (reporter)
2012-06-08 00:14


Can we please get this fixed properly? Its adding additional work to manually adjust the build settings in MSVC, or adding hacks like this to 3rd party libraries: [^]

edice (reporter)
2012-06-08 00:29

An example of a library that has trouble with cmake 2.8.8 + msvc2010 + x64:
zlib 1.2.7 (can be downloaded from
Andreas Mohr (reporter)
2012-12-03 06:03
edited on: 2013-04-25 12:46

Dito, hit the same issue with a SuperBuild when processing zlib.
This really needs to be pre-set correctly, soon - adding manual workarounds to a multitude of public projects is not the way to go.

I assume it's something that needs to be implicitly pre-configured by platform setup, i.e. [cmake_Modules]/Platform/Windows-cl.cmake

[edit] Nope, Bill Hoffmann above already said that it's likely to be a resource file build order problem.
I'll try to review it to see whether our resource file configuration actually is ok or whether something more obvious is problematic.

[edit] I don't think that this issue is as simple as "resource file not included as first file". In my case (zlib tested as standalone build) rearranging things (e.g. also by moving .rc into its own ResourceCompile-specific ItemGroup element) did NOT help.
[edit 2] Well, it easily might be - after all .vcxproj-side file list order arrangements can be completely unrelated to the actual order of input files as used by the tool's internal setup. And it's quite thinkable that that internal order possibly cannot be influenced on the .vcxproj side (i.e., CMake).
[edit 3] The lib.exe invocation is wrapped into a tracker.exe call, and if things got changed to a tracker.exe introduction post-9 (remember that msbuild is >= 2010 only!) then this is perhaps what changed the order of input files.

Detailed log level:

1> (TaskId:14)

tracker.exe /r switch is "Root primary input file(s) being tracked".

OTOH it looks like there is one tracker.exe (for lib.exe) invocation per input file, and these invocations do start with the .res file (and this is the only lib.exe invocation in my log!), and since that fails (since this is the first file, which does not internally carry an architecture setting due to being a resource file, some architecture guesswork/defaults happen, and that FAILS) no further .obj files are being processed, so that contributes towards confirming the "VS build now changed to wrong file order" theory.
[end edit 3]

Some of my findings:
- a static library project usually does not have a link step in its build
- it does include a link step once a .rc file is contained in the list of source files
- since it usually does not have a link step, VS does not need to figure out the machine type from the .obj files generated
- but once we do have a link step (.rc file contained in project), building fails since the machine type required for linking .rc file parts is not specifically specified
- this can all be analyzed by reviewing VS project settings tabs of zlib solution (zlib vs. zlibstatic projects), and especially their "Command Line" tabs which do/don't contain /machine:... in the Linker tab
- so that means that for static libraries (or, perhaps more precisely, static libs containing .rc files) we likely need to have CMake specify /machine:... explicitly
- or does that mean that we should be specifying /machine:... for library targets in general?

Andreas Mohr (reporter)
2012-12-03 07:56
edited on: 2012-12-03 08:05

Some other links where people have trouble on Non-CMake side:
"MSVC resource compiler problem" [^]
which mentions that adding .rc to a bjam config has same problem. [^]

In the Apple case, they're using AdditionalOptions /MACHINE:...

And then there's [^]
, which solves this problem in a more generic way (rather than specifying an ugly manual AdditionalOptions /MACHINE:...):
They simply set
(this setting shows up within the static library project's "Librarian" tab)

Modifying CMake's zlib static project to use
does make it work, and removing the TargetMachine line then makes it fail again.

So it seems we need to have TargetMachine indication added to generator - but the question remains in which cases that should be:
- only for static libs containing .rc files
- or for all static libs
- or for all libs, whether static *or* dynamic

[edit] it appears CMake trunk both VS7 and VS10 generators currently don't actively specify any TargetMachine setting (they do contain some - likely unused - TargetMachine tables, though).

Andreas Mohr (reporter)
2013-04-25 11:42
edited on: 2013-04-25 12:00

== Random thoughts == [^]
seems to be exactly our issue, too.

A detailed VS build log for analysis can be gained via
MSVS2010 Tools -> Options -> Projects and Solutions -> Build and Run -> MSBuild project build output verbosity
However, that doesn't actually yield overwhelmingly helpful details (it just shows e.g. lib.exe - the Librarian - processing the .res file).

== Further analysis ==

We've got a problem where VS tools seem to have weak handling of resources within static libraries (see "VC++ resources in a static library" [^] ). OTOH, *both* in a Win32 and an x64 build (via STATIC_LIBRARY_FLAGS /machine:x64 workaround, see above), the zlibstaticd.lib *does* receive the .res file content (InternalName etc. UTF-16 string data can be seen in binary).

So, it seems:

- VS has a long-standing librarian handling issue (LNK1112, see URL above) for storing .rc:s in static libs on non-Win32 $(Platform) setting (not too surprising given VS's general lack of polishing in many areas, e.g. zero-size .map files, grave .tlog cache inconsistency, project reload, astonishing non-performance)

- this results in a "problem" since zlib assigns .rc file to both shared (where this is nicely supported) *and* static (where this fails horribly) library. OTOH one could say that a *user* *should* be allowed to assign whichever input file types he wants to a target (with improper inputs being silently ignored). So perhaps CMake is missing an internal step which filters out .rc files for STATIC libraries? But this would be unsuitably hard-coded handling, I'd think...

- the issue of VS generators not generating specific TargetMachine elements for this x64 setting (which I mentioned in prior note) is irrelevant: an open-coded /machine:x64 is the usual handling as done by CMake's Platform modules. Also, the x64 setting *does* need to be specified much more generally (this configuration should simply be supplied open-coded from outside [Platform module content] since it's *not* specific to Visual Studio generator - nmake generator etc. most likely require availability of this setting as well since they're using the same build toolchain i.e. same issues)

- since VS does include .res data successfully once target machine is *manually, specifically* configured properly, this leaves us with the problem that the librarian (the <Lib> element within VS's tool configuration area) currently truly cannot be configured for x64:
while Platform/Windows-MSVC.cmake does set CMAKE_EXE_LINKER_FLAGS_INIT to /machine:${_MACHINE_ARCH_FLAG} and replicates it into CMAKE_SHARED_LINKER_FLAGS_INIT and CMAKE_MODULE_LINKER_FLAGS_INIT, which does get evaluated by cmVisualStudio10TargetGenerator.cxx ComputeLinkOptions(), *in addition to the CMAKE_<linkType>__LINKER_FLAGS variable* and the LINK_FLAGS *target property* and ultimately ends up in VS AdditionalOptions element of <Link> via linkOptions.OutputAdditionalOptions(), WriteLibOptions() first does its own dirty parsing (should be separated outside this method!), then considers the STATIC_LIBRARY_FLAGS **target property** only, which is a problem since then a /machine:x64 setting currently cannot be pre-configured from the outside (i.e., Platform modules), long before any targets come into play.

So, some current (master HEAD) CMake issues that I see:
- WriteLibOptions() (as opposed to WriteLinkOptions()) does dirty data gathering rather than *generation-only* handling of an *existing* dataset (--> cleanup required)
- we do want a default platform setup of AdditionalOptions /machine:${_MACHINE_ARCH_FLAG} for <Lib> (librarian) tool
- since we do want /machine:${_MACHINE_ARCH_FLAG} listed, we do need a specification and handling of a *librarian-specific* foo_INIT Platform variable. AFAICS, neither specification nor implementation nor use of this Platform variable currently exist.
  since MSVS has both separate <Link> and <Lib> tool elements, this clearly is NOT a linker-related variable. So, which name would such a Platform variable carry? Are there any existing variables for such purpose?
Don't tell me it would be CMAKE_LIBRARIAN_FLAGS_INIT...
Nope, Modules/Generic-SDCC-C.cmake mentions:
find_program(SDCCLIB_EXECUTABLE sdcclib)

("The sdcc librarian", CMAKE_AR)

On a system here, CMakeCache.txt has:

So that would strongly hint at CMAKE_AR_FLAGS_INIT being the correct variable name. However,

$ grep CMAKE_AR *
gas.cmake: "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
Generic-SDCC-C.cmake:# find sdcclib as CMAKE_AR
Generic-SDCC-C.cmake:set(CMAKE_AR "${SDCCLIB_EXECUTABLE}" CACHE FILEPATH "The sdcc librarian" FORCE)
Generic-SDCC-C.cmake: "<CMAKE_AR> -a <TARGET> <LINK_FLAGS> <OBJECTS> ")
Linux-como.cmake: "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
Windows-GNU.cmake: "<CMAKE_AR> cr <OBJECT_DIR>/objects.a <OBJECTS>"

nowhere lists a CMAKE_AR_FLAGS*, and it shows CMAKE_${lang}_ARCHIVE_CREATE as making use of the <CMAKE_AR> generator expression (genex).
And a CMAKE_AR variable (or others) do *not* exist in my Windows-side x64 zlib CMakeCache.txt.

So, does VS <Lib> == lib.exe == CMAKE_AR --> CMAKE_CXX_ARCHIVE_CREATE?
There are some reasons to doubt that...

More verbosely, Windows-GNU.cmake contains:

    # Create archiving rules to support large object file lists for static libraries.

Note that it's MSYS/MINGW-specific, but note that it does say "support large object file lists for static libraries".

However I'm currently having some doubts on whether the specific lib.exe command line as done by VS even is under CMake's control...
So maybe in the VS case we are NOT able to effectively specify a full MAKE_${lang}_ARCHIVE_CREATE librarian command line. IOW, we likely cannot and shouldn't specify that, but rather do Platform-have a and do generator-support a (currently not existing/used) CMAKE_AR_FLAGS_INIT Platform variable.
But I'm afraid I have to defer to the Platform setup wizards here on which way to best go... (the chosen solution ought to fit in cleanly with future plans on the LANGUAGE support / genex front).

Sorry for the rather long and possibly confusing note. But I'm happy to use the Edit button if requested (it's there for a reason :).

So, which way to go to finally get this annoying MSVC toolchain-originating issue solved? Thanks!

Side note: this was again a case where I managed to lose the entire form content during submission due to
invalid session token or whatever... [^]
had an awfully successful outcome. :)
And make damn sure to install Lazarus browser plugin *NOW* to avoid this in future...
(in many cases this manual recovery would NOT have worked!!)

== THE END ==

Sergei Nikulov (reporter)
2013-07-09 10:20

I've discovered this issue is reproducible on curl project

cmake .. -G"Visual Studio 10 Win64" -DCURL_STATICLIB=ON

After I deleted .rc file from CMakeLists.txt or apply workaround using set_target_properties() for libcurl it builds just fine.

Here the mailing [^]
xinyingho (reporter)
2013-11-23 07:05
edited on: 2013-11-23 07:06

I got the same error while compiling zlib after updating CMake.
I tested several versions and I can faithfully report that this bug is a regression that appeared between 2.8.9 and 2.8.10 RC1.

xinyingho (reporter)
2013-11-23 18:26

I saw another comment above mine where it's stated that the bug can be triggered with 2.8.8. This is not my case. So here's more information on how I reproduced the bug.

I use Win7 64-bit, VS 2010 SP1 and zlib 1.2.8.
To compile zlib, I have a .bat with the content below:

del ".\CMakeCache.txt"
call "%ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /Release /x64 /win7
call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat"
nmake clean

With CMake 2.8.8 and 2.8.9, this script is done successfully. But starting with 2.8.10 RC1, the compilation fails at the linking stage saying this:

fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
Roman80 (reporter)
2015-04-29 20:02

This affects also CMake 3.2.1
Brad King (manager)
2015-06-29 10:23

This should fix it:

 VS: Add /machine: flag to Librarian tool;a=commitdiff;h=806609c7 [^]

Note that a fresh build tree will be needed so that the value of CMAKE_STATIC_LINKER_FLAGS can be initialized in a new CMakeCache.txt.
Robert Maynard (manager)
2016-01-04 11:51

Closing resolved issues that have not been updated in more than 4 months.

- Issue History
Date Modified Username Field Change
2010-09-15 17:34 Scott New Issue
2010-09-15 17:34 Scott File Added: Property.png
2010-09-15 17:42 Bill Hoffman Note Added: 0022238
2010-09-15 18:16 Scott Note Added: 0022242
2010-09-15 18:29 Bill Hoffman Note Added: 0022243
2010-09-15 18:30 Bill Hoffman Status new => assigned
2010-09-15 18:30 Bill Hoffman Assigned To => Bill Hoffman
2010-09-16 08:52 Scott Note Added: 0022256
2010-09-16 10:26 Bill Hoffman Note Added: 0022259
2010-09-30 10:22 Scott File Added:
2010-09-30 10:27 Scott Note Added: 0022391
2010-09-30 10:34 Scott Note Added: 0022392
2010-11-01 17:48 Scott Note Added: 0022765
2010-11-01 21:35 Bill Hoffman Note Added: 0022768
2010-11-02 08:34 Scott Note Added: 0022771
2010-11-02 09:44 Bill Hoffman Note Added: 0022772
2010-11-02 10:46 Scott Note Added: 0022774
2011-01-31 19:03 Vladislav Vaintroub Note Added: 0025194
2011-01-31 19:08 Vladislav Vaintroub Note Added: 0025195
2011-05-24 13:26 staticinline Note Added: 0026576
2011-10-06 10:22 rvdn Note Added: 0027540
2011-11-07 15:17 Chris Scharver Note Added: 0027736
2012-06-08 00:14 edice Note Added: 0029642
2012-06-08 00:29 edice Note Added: 0029643
2012-12-03 06:03 Andreas Mohr Note Added: 0031798
2012-12-03 06:39 Andreas Mohr Note Edited: 0031798 View Revisions
2012-12-03 07:28 Andreas Mohr Note Edited: 0031798 View Revisions
2012-12-03 07:56 Andreas Mohr Note Added: 0031815
2012-12-03 08:05 Andreas Mohr Note Edited: 0031815 View Revisions
2013-04-25 11:42 Andreas Mohr Note Added: 0032944
2013-04-25 12:00 Andreas Mohr Note Edited: 0032944 View Revisions
2013-04-25 12:13 Andreas Mohr Note Edited: 0031798 View Revisions
2013-04-25 12:46 Andreas Mohr Note Edited: 0031798 View Revisions
2013-07-09 10:20 Sergei Nikulov Note Added: 0033520
2013-11-23 07:05 xinyingho Note Added: 0034524
2013-11-23 07:06 xinyingho Note Edited: 0034524 View Revisions
2013-11-23 18:26 xinyingho Note Added: 0034532
2015-04-29 20:02 Roman80 Note Added: 0038653
2015-06-29 10:23 Brad King Note Added: 0038995
2015-06-29 10:23 Brad King Assigned To Bill Hoffman =>
2015-06-29 10:23 Brad King Status assigned => resolved
2015-06-29 10:23 Brad King Resolution open => fixed
2015-06-29 10:23 Brad King Fixed in Version => CMake 3.4
2015-06-29 10:23 Brad King Target Version => CMake 3.4
2016-01-04 11:51 Robert Maynard Note Added: 0040086
2016-01-04 11:51 Robert Maynard Status resolved => closed

Copyright © 2000 - 2017 MantisBT Team
Powered by Mantis Bugtracker