为 Windows 64 编译 C 代码

发布于 2024-11-07 07:12:22 字数 1539 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

七禾 2024-11-14 07:12:22

由于这里的每个人都没有注意到您明确的 64 位声明,因此我将给出正确的答案:

  1. 如果 makefile 是 Nmake makefile,则可以安装 Visual Studio Express for Windows Desktop,从开始菜单打开命令提示符(选择针对 64-位 Windows),cd 到您的项目目录,然后运行 ​​nmake。您需要修改 makefile 以调用 cl 和链接。

  2. 如果 Makefile 是 MinGW makefile,则需要 mingw -w64 针对 Win64 的工具链(注意还提供了 32 位工具链)。我推荐 通过安装程序提供的官方版本或可从 MSYS2 安装的版本(请参阅第 3 点)。安装,打开 MinGW-w64 命令提示符,cd 到您的项目目录,然后运行 ​​mingw32-make

  3. 如果Makefile是Unix/MSYS makefile,我建议使用MSYS2。您可以使用上述工具链,或者执行 pacman -S mingw-w64-x86_64-gcc 从 MSYS2 shell 安装工具链。请务必将 /mingw64/bin 添加到 PATH 或从“MSYS2 MinGW-w64 64-bit”快捷方式启动以使用它。请注意,您只能使用 MSYS2 作为包管理工具:安装您想要的任何依赖项(有大量的 3rd 方库二进制文件可供使用),然后只需添加 /mingw64/bin目录到 PATH 并从任何地方调用编译器。

  4. 如果项目使用 Unix 功能(例如 fork() 或其他 Unix 系统调用),则可以使用 64 位 Cygwin,安装其编译器,并链接到 Cygwin dll。不建议这样做,因为这会带来性能(相对于将代码移植到 Win32 API 而言)和许可证损失(Cygwin DLL 是 GPL,这会强制您的程序以 GPL 兼容方式获得许可)。

以下是使用免费工具为 64 位 Windows 编译 C 源文件的四种方法。如果您是学生,您也可以使用以下方法:

  1. Dreamspark(如果您的大学/学院/学校与 Microsoft 就此达成协议)并使用它。几乎等同于第 1 点,除非您使用 MFC/ATL 和/或 VS 插件之类的东西,这些插件在 Express 版本中不起作用。

  2. 教育产品网站下载英​​特尔编译器。但从第 5 点开始需要 Visual Studio Professional。不过,您需要修改 Makefile 才能使用英特尔编译器。

  3. 此处下载 LLVM/Clang 编译器(Windows 快照版本)并将其与第 5 点。您需要修改 makefile 以调用 clang。

我知道这超出了您的要求,但我的高评价答案必须完整,对吧?

Since everyone here is oblivious to your clear 64-bit statement, I'll give a correct answer:

  1. If the makefile is an Nmake makefile, you can install the Visual Studio Express for Windows Desktop, open a command prompt from the start menu (choose the one targetting 64-bit Windows), cd to your project's directory, and run nmake. You'll need to modify the makefile to call cl and link.

  2. If the Makefile is a MinGW makefile, you will need mingw-w64's toolchains targetting Win64 (note also 32-bit toolchains are provided). I recommend the official builds provided through an installer or the ones installable from MSYS2 (see point 3). Install, open the MinGW-w64 command prompt, cd to your projects directory, and run mingw32-make.

  3. If the Makefile is a Unix/MSYS makefile, I suggest using MSYS2. You can use the above toolchain, or do pacman -S mingw-w64-x86_64-gcc to install a toolchain from the MSYS2 shell. Be sure to either add /mingw64/bin to PATH or launch from the "MSYS2 MinGW-w64 64-bit" shortcut to use it. Note you can use MSYS2 as a package management tool only: install any dependency you want (there are tons of 3rd party library binaries ready for use) and just add the <MSYS2 root>/mingw64/bin directory to PATH and call the compiler from anywhere.

  4. If the project uses Unix functionality (like fork() or other Unix system calls), you can use 64-bit Cygwin, install its compiler, and link with the Cygwin dll. This is not recommended as there is a performance (well, relative to porting the code to Win32 APIs) and license penalty (The Cygwin DLL is GPL, which forces your program to be licensed in a GPL-compatible way).

These are four ways of compiling a C source file for 64-bit Windows with free tools. If you are a student, you can probably use the following ways as well:

  1. Download Visual Studio Professional from Dreamspark (if your university/college/school has an agreement with Microsoft for this) and use that. Pretty much equivalent to point 1 except if you use stuff like MFC/ATL and/or VS plugins, which don't work in the express version.

  2. Download the Intel compiler from their Education offerings website. Requires Visual Studio Professional from point 5 though. You'll need to modify the Makefile to use the Intel compiler though.

  3. Download the LLVM/Clang compiler from here (the Windows snapshot builds) and use it in conjunction with point 5. You'll need to modify the makefile to call clang.

I know this is more than what you asked for, but my high-rated answers need to be complete, right?

大姐,你呐 2024-11-14 07:12:22

您可以使用 Visual C 并查看 nmake

请参阅:如何在 Visual Studio 中使用 makefile ?

You could use Visual C and look at nmake

see: How to use makefiles in Visual Studio?

情深如许 2024-11-14 07:12:22

您可以尝试 MinGW 来获得与 GCC 类似的 makefile。

You could try MinGW to have makefiles similar to GCC ones.

九公里浅绿 2024-11-14 07:12:22

Code::Blocks 带有内置的 Mingw 环境,它应该只处理 makefile美好的。

Code::Blocks comes with a built in Mingw environment, which should handle makefiles just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文