How to compile a C program?

烈酒焚心 提交于 2019-12-22 07:55:12

问题


I haven't done C in a long time. I'd like to compile this program, but I have no idea how to proceed. It seems like the makefile refers to GCC a lot and I've never used GCC.

I just want an executable that will run on windows.


回答1:


You may need to install either cygwin or mingw, which are UNIX-like environments for Windows.

  • http://www.mingw.org/
  • http://www.cygwin.com/

When downloading/installing either cygwin or mingw, you will have the option of downloading and installing some optional features; you will need the following:

  • gcc (try version 2.x first, not 3.x)
  • binutils
  • GNU make (or gmake)



回答2:


If it requires gcc and you want it to run on Windows, you could download Cygwin.

That's basically an emulator for GNU/Linux type stuff for Windows. It works with an emulation DLL.

http://www.cygwin.com/




回答3:


In order to compile this program you need a C compiler. It does not have to be gcc, although you are already given a makefile set up to use gcc. The simplest thing for you to do would be the following:

  1. Install cygwin
  2. Open the cygwin command prompt
  3. go into the directory where you have your makefile
  4. type 'make'
  5. That should compile your program

If you are not comfortable with using command line tools then you can download the free version of MS Visual Studio and import the source files into a new Visual Studio project. This way you would not need to install cygwin and use gcc, but you would need to know how to create projects and run programs in Visual Studio.




回答4:


You almost certainly don't need all of cygwin to compile using gcc. There are plenty of standalone gcc clones for Windows, like gcw.




回答5:


If it's reasonably portable C code (I haven't looked at it), then you may be able to just ignore the included Makefile and feed the source into whatever compiler you do want to use. What happens when you try that?




回答6:


Dev-C++ provides a simple but nice IDE which uses the Mingw gcc compiler and provides Makefile support. Here are the steps I used to build the above code using Dev-C++ (i.e. this is a "how-to")

After downloading the source zip from NIST, I

  • downloaded and installed the Dev-C++ 5 beta 9 release
  • created a new empty project
  • added all the .c files from sts-2.0\src

Then under Project Options

  • added -lm in the Linker column under Parameters
  • added sts-2.0\include to the Include Directories in Directories
  • set the Executable and Object directories to the obj directory under the Build Options

and then hit OK to close the dialog. Go to Execute > Compile and let it whirl. A minute later, you can find the executable in the sts-2.0\obj directory.




回答7:


First, there is little chance that a program with only makefiles will build with visual studio, if only because visual studio is not a good C compiler from a standard POV (the math functions in particular are very poorly supported on MS compilers). It may be possible, but it won't be easy, specially if you are not familiar with C. You should really stick to the makefiles instead of trying to import the code in your own IDE - this kind of scienfitic code is clearly meant to be compiled from the command line. It is a test suite, so trying things randomly is NOT a good idea.

You should use mingw + msys to install it: mingw will give you the compilers (gcc, etc...) and msys the shell for the make file to run correctly. Contrary to one other poster, I would advise you against using gcc 2 - I don't see any point in that. I routinely use gcc 3 (and even 4) on windows to build scientific code, it works well when the code is unix-like (which is the standard platform for this kind of code).



来源:https://stackoverflow.com/questions/571076/how-to-compile-a-c-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!