什么是编译为本机 Windows 代码的优秀轻量级编程语言?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/933129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's a good lightweight programming language that compiles to native windows code?
提问by Damovisa
I'm a .Net developer but I have a situation where I can't guarantee that the .Net Framework will be installed on the target machine.
我是 .Net 开发人员,但我无法保证 .Net Framework 会安装在目标机器上。
I've seen a few questions (hereand here) that suggest using NGen to compile to native code. Both point out that you still need the framework though.
我已经看到一些问题(这里和这里)建议使用 NGen 编译为本机代码。两者都指出您仍然需要该框架。
I want to write a fairly lightweight app (basic GUI, no database, nothing complicated) but for various reasons, I don't want to have to install any frameworks or bytecode interpreters.
我想编写一个相当轻量级的应用程序(基本的 GUI,没有数据库,没有什么复杂的),但出于各种原因,我不想安装任何框架或字节码解释器。
This questionsuggests Python and py2exe. I'm not familiar with Python, but if it's the best tool for the job, I can probably learn enough to write this app (I'd prefer not to though). I've also thought about writing it in DHTML and javascript - I can rely on the machine having a relatively new browser.
这个问题建议使用 Python 和 py2exe。我不熟悉 Python,但如果它是这项工作的最佳工具,我可能可以学到足够的知识来编写这个应用程序(不过我宁愿不这样做)。我还考虑过用 DHTML 和 javascript 编写它 - 我可以依靠具有相对较新浏览器的机器。
I'm familiar with the C family of languages and I've dabbled in Java, PHP, and Ruby.
我熟悉 C 语言家族,并且涉猎过 Java、PHP 和 Ruby。
Can anyone suggest a language that I can easily compile to native Win32 code?
任何人都可以建议一种我可以轻松编译为本机 Win32 代码的语言吗?
Edit: Clarification
编辑:澄清
There have been a few answers suggesting that if I'm familiar with the C family of languages, why not just use C? I should probably clarify. I use C# every day and I was brought up on C+ and C++ (but haven't used either for quite a few years).
有几个答案表明,如果我熟悉 C 语言家族,为什么不直接使用 C?我应该澄清一下。我每天都使用 C#,并且从小就学习 C+ 和 C++(但已经有好几年没有使用了)。
It does look like C/C++ might be the way to go, but I'll have to refresh my memory on them :)
看起来 C/C++ 可能是要走的路,但我必须刷新我对它们的记忆:)
回答by Jean Azzopardi
if it's lightweight and nothing complicated, and you are familiar with the C family of languages.. then why not C and the Win32 Api? It's harder than writing .net or java programs, sure but it's definitely going to compile to native windows code, and doesn't need bytecode or an interpreter.
如果它是轻量级的,没有什么复杂的,并且您熟悉 C 语言家族..那为什么不使用 C 和 Win32 Api?这比编写 .net 或 java 程序更难,当然,但它肯定会编译为本机 Windows 代码,并且不需要字节码或解释器。
Also, you might be able to use Mono to statically link a C# application with the Mono runtime. http://www.mono-project.com/Guide:Running_Mono_Applications
此外,您可以使用 Mono 将 C# 应用程序与 Mono 运行时静态链接。http://www.mono-project.com/Guide:Running_Mono_Applications
I see you need to brush up on C..here's another idea, then : Delphi.
我看到你需要复习 C ..这是另一个想法,然后是:Delphi。
There are some more answers in this thread
在这个线程中有更多的答案
回答by Johan Kotlinski
I would try C++ with Qt... I think it is a very important framework to learn, considering it just turned LGPL.
我会用 Qt 尝试 C++...我认为这是一个非常重要的学习框架,考虑到它刚刚变成了 LGPL。
回答by RBerteig
If you are willing to consider a bytecode interpreter that can be entirely contained within your installation (which the python solution you mention would be doing), then you might consider using Luaand something like srluato bundle your script along with the interpreter into a single .EXE. To get a quick GUI going with Lua, IUPis a good choice, but there are bindings for other GUI frameworks out there too.
如果你愿意考虑一个可以完全包含在你的安装中的字节码解释器(你提到的 python 解决方案会这样做),那么你可以考虑使用Lua和类似srlua 的东西将你的脚本与解释器捆绑成一个。可执行程序。为了让 Lua 快速运行 GUI,IUP是一个不错的选择,但也有其他 GUI 框架的绑定。
If the issue is more one of a clean installation without a lot of system dependencies rather than attempting to get a single EXE with no DLLs, then consider using Lua without the bother of srlua to package it. It doesn't need to be installed in any magical way, and can live in a single folder along with your script and any required modules in either DLL or script form.
如果问题更多是一个没有很多系统依赖项的干净安装,而不是试图获得一个没有 DLL 的单个 EXE,那么考虑使用 Lua,而无需 srlua 来打包它。它不需要以任何神奇的方式安装,并且可以与您的脚本和任何必需的 DLL 或脚本形式的模块一起存在于单个文件夹中。
It is easy to bind C callable functions to the Lua core because the authors designed it from the beginning to be embedded in a larger application. It only requires a few lines of boilerplate to create a Lua-callable module written in C that is distributed in a DLL, for example.
将 C 可调用函数绑定到 Lua 内核很容易,因为作者从一开始就将其设计为嵌入到更大的应用程序中。例如,它只需要几行样板就可以创建一个用 C 编写的 Lua 可调用模块,该模块分布在 DLL 中。
An easy way to get started with Lua along with a full kit of useful modules is the Lua for Windowsproject which maintains a "batteries included" installation kit for Lua.
开始使用 Lua 以及完整的有用模块套件的一种简单方法是Lua for Windows项目,该项目维护一个“包含电池”的 Lua 安装套件。
回答by User
Pascal/Delphi maybe?
也许是帕斯卡/德尔福?
Actually, if you want compatibility there is nothing better than a Win32 app without using MFC. Not sure if STL is not sitting in some extra DLL installed by VS.
实际上,如果您想要兼容性,没有什么比不使用 MFC 的 Win32 应用程序更好的了。不确定 STL 是否不在 VS 安装的一些额外 DLL 中。
On the other hand, I remember seeing messages like VC++ redistributables missing on installation, not sure if it referred to MFC or even core libraries. Better not use MFC at all.
另一方面,我记得在安装时看到像 VC++ 可再发行组件这样的消息丢失,不确定它是指 MFC 还是核心库。最好不要使用 MFC。
You could use WTL for GUI, it will compile to your executable.
您可以将 WTL 用于 GUI,它会编译为您的可执行文件。
回答by Drew Dormann
The Windows API itself is in C.
Windows API 本身是用 C 语言编写的。
If C is not lightweight enough, you could consider C++/MFC which is good for making simple GUI programs with minimal coding on your part.
如果 C 不够轻量级,您可以考虑使用 C++/MFC,它非常适合用最少的代码制作简单的 GUI 程序。
回答by Don Dickinson
for me its powerbasic (www.powerbasic.com). it compiles native exe's (real ones, not byte code with the compile embedded). the syntax is like old pds or quick basic (but much further advanced). it allows in-line assembler, object oriented classes (optional, you can also just do procedural code). if you have a background in c, then stick with it. if you like basicy languages, then pb is a no-brainer. its like c with strings. other than that, if you like pascal, delphi's compiler can produce native exes.
对我来说它的 powerbasic (www.powerbasic.com)。它编译本机 exe(真实的,而不是嵌入了编译的字节码)。语法就像旧的 pds 或快速基本(但更高级)。它允许内嵌汇编程序、面向对象的类(可选,您也可以只执行过程代码)。如果你有 c 语言背景,那就坚持下去。如果你喜欢基本的语言,那么 pb 是显而易见的。它就像带有字符串的 c。除此之外,如果您喜欢 pascal,delphi 的编译器可以生成本机 exe。
-don
-大学教师
回答by BCS
Along the lines of C/C++ you might take a look at the D programming language. It's got most of the advantage of D including native binaries by default but is a lot closer to C# or Java in the features department. Unfortunately, in the tools and, to a lesser extent, libs domain it's sadly lacking (although that is changing fairly quickly).
沿着 C/C++ 的路线,您可能会看看D 编程语言。它具有 D 的大部分优势,默认情况下包括本机二进制文件,但在功能方面更接近 C# 或 Java。不幸的是,在工具中,以及在较小程度上,libs 域中它是可悲的缺乏(尽管变化相当快)。
回答by DarkSquid
Without knowing what specific genre of application you're going to be writing, it's a little hard to say definitively...but MFC (if you know it) or plain C/C++ and the Win32 API would be a reasonable choice, based on the info you've given.
在不知道您将要编写什么特定类型的应用程序的情况下,很难确切地说......但是 MFC(如果您知道的话)或普通的 C/C++ 和 Win32 API 将是一个合理的选择,基于你提供的信息。
Certainly, MFC is a bit dated..but zillions of apps shipped with it and, its warts aside, it does "work" for many purposes. If you can get ahold of a copy of Visual C++ 6.x there are plenty of wizards/etc which will help you get an app out quickly. That said, I definitely wouldn't suggest learning MFC just for this purpose.
当然,MFC 有点过时了……但是它附带了无数的应用程序,而且除了它的缺点之外,它确实可以用于许多目的。如果您可以获得 Visual C++ 6.x 的副本,那么有很多向导/等可以帮助您快速推出应用程序。也就是说,我绝对不会建议仅仅为了这个目的而学习 MFC。
回答by Alistair Evans
NGen is designed to optimise .NET code by compiling to native code. You still require the .NET framework. Also, NGen runs in the installer on the client machine - you can't distribute native code.
NGen 旨在通过编译为本机代码来优化 .NET 代码。您仍然需要 .NET 框架。此外,NGen 在客户端计算机上的安装程序中运行 - 您不能分发本机代码。
Create the .NET installer project, which will check for the framework, and install it automatically.
创建 .NET 安装程序项目,它将检查框架并自动安装它。
回答by JP Alioto
Either C++ or VB6 will work for you. Take a look at VB6. It's pretty easy to learn and is very easy to do GUIs with.
C++ 或 VB6 都适合你。看看VB6。它非常容易学习并且非常容易使用 GUI。