简体   繁体   English

使用VS2008为64位Windows平台编译C ++静态库

[英]compiling C++ static library for 64 bit windows platform using VS2008

ith Visual Studio 2008, If the configuration type is a static library, I dont see a linker option in project properties. 在Visual Studio 2008中,如果配置类型是静态库,我在项目属性中看不到链接器选项。 I need to specify /MACHINE:x64 option for a static library. 我需要为静态库指定/ MACHINE:x64选项。 I tried to specify this in command line option in Librarian. 我试图在Librarian的命令行选项中指定它。 Only then I could build the static library. 只有这样我才能构建静态库。 If I dont specify /MACHINE compiling the static lib fails with LNK1112: module machine type 'X86' conflicts with target machine type 'x64' ( even if I set the platform to X64 for my solution). 如果我没有指定/ MACHINE编译静态库使用LNK1112失败:模块机器类型'X86'与目标机器类型'x64'冲突(即使我将平台设置为X64用于我的解决方案)。

With /MACHINE:X64 specified as command line through Project-Properties-Librarian, the static library was built but other project (of configuration type : DLL) in the same solution has a dependency on the static lib, when the DLL is built and tries to use one of the functions in the lib I again get the same error: 使用/ MACHINE:X64通过Project-Properties-Librarian指定为命令行,构建了静态库,但是同一解决方案中的其他项目(配置类型:DLL)依赖于静态库,当构建DLL并尝试使用lib中的一个函数我再次得到相同的错误:

fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64' 致命错误LNK1112:模块机器类型'X86'与目标机器类型'x64'冲突

Please suggest, how do I build a 64 bit static library 请建议,如何构建64位静态库

For what it's worth, I've come across this exact same issue. 对于它的价值,我遇到了同样的问题。

I have a project that compiles a static library, and creating an "x64" configuration did NOT get it actually targeting x64. 我有一个编译静态库的项目,并且创建“x64”配置并没有实际定位到x64。 I had to explicitly add "/MACHINE:X64" as an "additional option" under "Librarian -> Command Line" in the project's property pages, just as you did. 我必须在项目的属性页面中明确地将“/ MACHINE:X64”添加为“Librarian - > Command Line”下的“附加选项”,就像你一样。

I would expect visual studio to expose this setting as a first-class property in the property pages, as it does for dynamic libraries (under "Linker -> Advanced -> Target Machine"). 我希望visual studio将此设置公开为属性页中的第一类属性,就像动态库一样(在“链接器 - >高级 - >目标机器”下)。 Perhaps I'm missing something. 也许我错过了一些东西。

As mentioned by Timbo, you need to ensure that you have an x64 configuration that you're building. 正如Timbo所提到的,您需要确保拥有正在构建的x64配置。 However, there are a couple of other gotchas to be aware of: 但是,还有其他一些需要注意的问题:

  • Do a total clean of your build directory first in case you still have some 32 bit object files lying around that are causing confusion 首先要彻底清理你的构建目录,以防你仍然有一些32位目标文件,这会导致混乱
  • Check the intermediate and output directories for your project. 检查项目的中间和输出目录。 If the destination is Debug\\Mylib.lib then you're going to run into problems because the same name is being used for the 32 and 64 bit libraries. 如果目标是Debug\\Mylib.lib那么您将遇到问题,因为32位和64位库使用相同的名称。 I prefer to select all configurations and all platforms and then rename them all to something standard like ..\\build\\$(ProjectName)\\$(ConfigurationName).$(PlatformName) 我更喜欢选择所有配置和所有平台,然后将它们全部重命名为标准,如..\\build\\$(ProjectName)\\$(ConfigurationName).$(PlatformName)
  • Check in the configuration manager that when you are building the 64-bit configuration of the solution that it is configured to build the 64-bit configurations of the projects (this doesn't always happen by default) 检查配置管理器,在构建解决方案的64位配置时,将其配置为构建项目的64位配置(默认情况下并不总是这样)
  • The error: module machine type 'X86' conflicts with target machine type 'x64' means that the object file has been built as 32-bit but the link setting of the project is set with the flag /machine:x64 . 错误: module machine type 'X86' conflicts with target machine type 'x64'意味着目标文件已构建为32位,但项目的链接设置使用flag /machine:x64 So this suggests that the project configuration is 32-bit. 所以这表明项目配置是32位。
  • If in doubt about what you've created, pick one of the object files and type this at a command prompt: 如果对您创建的内容有疑问,请选择一个目标文件并在命令提示符下键入:

    dumpbin /headers myfile.obj | findstr machine

This will show you the architecture you've actually built for. 这将向您展示您实际构建的体系结构。

Did you try to add a new project configuration (x64) to the existing project? 您是否尝试将新项目配置(x64)添加到现有项目中?

You should usually not have to edit the project properties at all to build in 64bit. 您通常不必编辑项目属性以构建64位。 You just have to add the configurations and make sure the solution configuration is correct (64 bit solution configuration contains 64bit project configurations). 您只需添加配置并确保解决方案配置正确(64位解决方案配置包含64位项目配置)。

You can check this by opening Build->Configuration Manager . 您可以通过打开Build-> Configuration Manager来检查这一点。 My Visual Studio sometimes messes with these settings and makes the project uncompilable, so checking it again might help. 我的Visual Studio有时会混淆这些设置并使项目无法编译,因此再次检查可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM