开发者

How to build executable from c written source files?

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开发者_如何学Python into some executable file on Windows 7 (64bits) ? I think i need to download compilers for C or some sdks right?


Yes.

You need to:

  • download and install a C/C++ compiler (I recommend TDragon's distribution of MinGW ),
  • add the compiler to your PATH (the installer can do it for you most of the cases); verify it's done by opening cmd.exe and typing gcc -v and mingw32-make -v, both should give you half a screenful of version information if your path is set correctly,
  • via cmd.exe, navigate to the folder in which the Makefile resides and call mingw32-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 of mingw32-make from now on).

About the CreateProcess bug, it has to do with the system PATH variable being too long. You'd need to do something like this:

  • open cmd
  • execute set PATH=c:/mingw32/bin;c:/msys/1.0/bin (change the paths here to reflect your own installation if it's different)
  • then as before: navigate to your project's directory, run 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.


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 ??


I think i need to download compilers for C or some sdks right?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜