如何从 C 编写的源文件构建可执行文件?
src 目录下有少量以 .c 和 .h 为扩展名的文件(cmdline.c cmdline.h core.c core.h 等),还有一个没有扩展名的文件“MakeFile”。是否有可能将这些源文件构建成 Windows 7(64 位)上的某个可执行文件?我想我需要下载 C 编译器或一些 SDK,对吗?
There is few files with .c anf .h extensions (cmdline.c cmdline.h core.c core.h and so on) in src directory, also there is one file "MakeFile" without extension. Is there any possibility to build these source files into some executable file on Windows 7 (64bits) ? I think i need to download compilers for C or some sdks right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。
你需要:
cmd.exe
导航到Makefile
所在的文件夹并调用mingw32-make
。从现在开始,一切都应该自动编译。如果没有,请发布错误。
更新:
首先,获取 MSys 包。安装它,您将拥有更新版本的
make
(从现在开始使用它而不是mingw32-make
)。关于
CreateProcess
bug,它与系统PATH
变量太长有关。您需要执行以下操作:cmd
set PATH=c:/mingw32/bin;c:/msys/1.0/bin
(在此处更改路径以反映您自己的安装(如果不同),make
。如果您没有丢失任何外部库,现在一切都应该很顺利。顺便说一句 - 记住不要将 MinGW 或 MSys 安装在带有空格的目录中。
Yes.
You need to:
cmd.exe
and typinggcc -v
andmingw32-make -v
, both should give you half a screenful of version information if your path is set correctly,cmd.exe
, navigate to the folder in which theMakefile
resides and callmingw32-make
.From now on everything should compile automatically. If it doesn't, post the errors.
Update:
First of all, it'd be useful for you to get the MSys package. Install it and you'll have a more recent version of
make
(use it instead ofmingw32-make
from now on).About the
CreateProcess
bug, it has to do with the systemPATH
variable being too long. You'd need to do something like this:cmd
set PATH=c:/mingw32/bin;c:/msys/1.0/bin
(change the paths here to reflect your own installation if it's different)make
. Everything should be smooth now if you're not missing any external libraries.BTW- remember not to install MinGW or MSys in directories with spaces.
我不是 Windows 开发人员..
但据我所知还是这样。 Visual Studio(我猜是2008)有能力读取Makefile。
请看一下它。如果需要,请将此 makefile 更改为其格式。
有许多与平台无关的开源产品。它们使用它们提供的 Makefile 在两个操作系统上进行编译。
或者使用“cygwin”
开发人员C++在Windows中工作,但它实际上是购买到Windows中的GCC代码,有人熟悉他们用来将linux(.sh)转换为可执行文件的过程吗?
I am not a Windows Developer..
But still as per my knowledge. Visual Studio (i.e 2008, I guess) has the ability to read the Makefile.
Please have a look at it..and if needed change this makefile to their format..
There are many opensource product which are platform independent..and they get compiled on both OS with the just Makefile they provided.
Or else use 'cygwin'
Developer C++ works in windows but it is actually GCC code bought into Windows, Is anyone familiar about the procedure they used to convert the linux ( .sh) to executables ??
当然是编译器,但是您可能需要哪些额外的库完全取决于代码本身。成功的构建还可能取决于原始代码和 makefile 的预期目标。 makefile 可能是 GNU makefile,但还有其他类似但不兼容的 make 实用程序,例如 Borland Make 和 MS NMake。如果是简单的构建,您可以完全避免 makefile 问题并使用 IDE(例如 Visual C++ 2010 Express)提供的项目管理。
如果您不知道这段代码是什么、它的作用是什么以及它需要构建什么,那么您就完全在冒险构建它。也许您应该发布原始来源的链接,以便您可以获得有关如何构建它的更具体的建议。
[编辑]
好的,现在看看您尝试构建的代码,这是一个非常简单的构建,因此如果您想避免使用 GNU make,那么您可以添加所有 *.c将 src 文件夹中的文件复制到 IDE 中的项目并构建它。
然而,有一个严重的问题,它使用 BSD 套接字 API 和 Linux 系统标头。您需要首先将代码移植到 Windows API,例如 WinSock(与 BSD 套接字非常相似),或者在 Cygwin 下构建它(有点像大锤)。可能还有其他Linux依赖项需要排序,我没有详细查看,但看起来相当简单。也就是说,如果您没有关于编译这些东西的第一条线索,那么也许这不是您可以完成的任务?
当然,编译代码可能只是问题的一半,如果它被设计为在 Linux 上运行,则可能存在运行时依赖性阻止它在 Windows 上运行。我又没有仔细看过。
另外看看代码,我建议谨慎一些,这可能不是最好质量的代码。这可能不公平,但一个明显的缺陷以及缺乏经验的迹象是头球中缺乏后卫。
A compiler certainly, but what additional libraries you may need will depend entirely on the code itself. A successful build may also depend on the intended target of the original code and makefile. The makefile may be a GNU makefile, but there are other similar but incompatible make utilities such as Borland Make and MS NMake. If it is a simple build, you may be able to avoid the makefile issue altogether and use the project management provided by an IDE such as Visual C++ 2010 Express.
If you do not know what this code is or what it does and what it needs to build, you are taking a risk building it at all. Maybe you should post a link to the original source so that you can get more specific advice on how to build it.
[EDIT]
Ok, now looking at the code you are attempting to build, it is a very simple build, so if you wanted to avoid using GNU make, then you could just add all the *.c files in the src folder to a project in your IDE and build it.
However there is one serious gotcha, it uses the BSD sockets API and Linux system headers. You will need to first port the code to Windows APIs such as WinSock (very similar to BSD Sockets), or build it under Cygwin (a sledgehammer for a nut somewhat). There may be other Linux dependencies that need sorting, I have not looked in detail, but it looks fairly simple. That said, if you did not have the first clue regarding compiling this stuff, then perhaps this is not a task you could do?
Of course compiling the code may only be half teh problem, if it was designed to run on Linux, there may be run-time dependencies that prevent it running on Windows. Again I have not looked in detail.
Also looking at the code, I would suggest some caution, this may not be the best quality code. That may be unfair, but one obvious flaw and an indication if inexperience is the lack of include guards in the headers.