non-IDE C development environment - c

How do I set up a non-IDE-based C development environment on Linux?

gcc + make + vi and you will live happily ever after!

A pretty good development environment is most likely already there--no setup necessary. This is because most Linux installations are GNU/Linux. GNU provides all the pieces you need for C software development.
Use the 'which' command to make sure these programs are in your execution path
which gcc
which make
Gcc is your compiler. Make lets you define the compiling and linking steps. (It can call gcc for you.)
You are likely to have several editors installed such as vi, nano, and GNU emacs. To see if you have emacs (for instance), type
which emacs
If the which command returns a valid path (i.e. it doesn't say which: no emacs in ...) then that means you can run the program just by typing its name:
emacs
for example.

Okay my environment:
Geany or gedit, make, GCC. If I have to code on the command line I'd probably go with vi or nano over emacs, I just can't cope with emacs anymore.

Okay, someone's gotta say it: Emacs, gcc, and make.
If - as a commenter suggested - you're looking for instructions on setting this up, there's probably no set up needed, as most Linux distributions I've used come with these programs already installed.

If you're not a masochist:
gcc + cmake + nano ;)
Make sure to edit your .nanorc file (you can copy an example from /etc/nanorc generally)

Emacs + Cedet is the best

I use gtkemacs, gcc, make but more often scons these days.
This question is dangerously close to inciting religious wars. Let me get it started: All configurations other than mine are inferior.

I would recommend gcc + vim/vi + (make).
Vim/vi is almost impossible to "just pick up and use" because it will be completely foreign and you will struggle to even move the cursor or insert text, but fortunately, Vim comes with an extremely helpful tutor you can start by invoking the command vimtutor in the shell. It will get you up and running in no time!
While Vim's interface is really bizarre and esoteric at first, once you get used to it (shouldn't take very long once you finish vimtutor), you will see your productivity when editing code increase dramatically!

Related

Compile and execute C program in Python using Windows

I need to iteratively edit, recompile and run a C program called sum_subgiants.c through Python (using Spyder on Windows). I am using a python code that has previously worked on my colleague's Mac. I am a novice with python and have no experience with C.
There is a makefile and all relevant files stored in the same folder as sum_subgiants.c. I have tried
subprocess.run('make sum_subgiants', shell=True)
to compile and then
subprocess.call('sum_subgiants', stdin=input_file, stdout=output_fh, shell=True)
These commands do not appear to do anything. Any help in terms I can understand would be much appreciated.
I notice that there is no make command on Windows, which explains the error. Is there an alternative command that would work on Windows?
Should I expect subprocess.call to run easily after I have sorted out the make?
Since you are on Windows, everything is difficult.
You need to install a C compiler on the Windows machine.
You need to install make on the Windows machine.
Depending on what is done in the makefile, you might need to install other tools as well.
You could consider installing MSYS2 and MinGW, which provide a Unix-like environment for Windows.
But I would question the whole procedure: Why is it necessary to dynamically build a C program at run time? This is going to be so complicated that looking for an alternative solution might be preferable.

Run C programs from sublime 2.02

I want to compile and run C/C++ programs with sublimetext 2 itself.I dont want to use terminal to do so. What do I need to do for this??I am compeletely new to this so a lot of answers to similar questions did not help me as most of them were for windows.
sublime text 2 build system for C programming language should show you how to setup your build environment. Note: you need gcc etc. installed
Edit: you should although run your programm in a Terminal because SublimeText2 is an Editor and can not recieve user input for your programm. so you better just build it with ST2 and run it in Terminal or you just forget about ST2 and make your own Bash script that manages compiling and runs the programm.
I would use sublime text as an editor (which is what IDEs are). Then you'll need to have a Makefile for your program. And build it by typing make in a terminal (or by configuring your editor to run that command). BTW, you can type m a k e enter once in your day (and later use up in the same terminal, to reapeat the latest command).
Learning how to write simple Makefile-s is a reusable skill (see here for "why?"). See this and that and many other examples. Don't attach yourself to one particular editor (even if you may like one more than others; my preference goes to emacs).
You'll learn a big lot by studying (and improving) the source code of some free software. Look at sourceforge, github, etc.. to find some free software interesting to you, then download its source code, build it, and study it.
The tips and advices I gave here are still valid today, with a recent Ubuntu (e.g. 14.x)
BTW, your question looks like you might be confused; Sublime Text is an editor (perhaps glorified as an IDE). It does not compile anything. The C or C++ compiler on Ubuntu is GCC (using gcc command for compiling C code, and g++ command for compiling C++ code) or perhaps Clang/LLVM (using clang command for C code, and clang++ command for C++ code). That compiler is often started by make, and IDEs on Linux are often running make -or directly the compiler- command for you. You'll better be able to run these commands yourself.

How do I setup a C environment on Windows (and maybe Linux compatible, too)

Short version of question: How do I get started with C programming? Note that I am not asking for a tutorial on learning C language (I can learn that easy enough). I need to setup the environment (I hope I'm asking this question clearly). Here's what I mean:
For my math thesis, I need to write a program in C on Gentoo Linux, using a library called CVODE/SUNDIALS. There is nobody (it seems) in my department who can help me set this up - my professor has left the computer work 100% to me because I have some programming background and he's a math geek. But my experience is with scripting languages (think VBA) and not full, powerful programming languages where you have to link the compiler and libraries, etc. like C.
There is no development environment on the Linux cluster - or at least not that's friendly, and has a debugger - that I've found. So, what I need to figure out how to setup a C programming environment with CVODE library on my PC (Win 7 x64, at little to no cost.
I have found plenty of tutorials on programming in C. I looked up Eclipse, which I have a little bit of experience with, as a development environment, but it's instructions say you need to install a compiler, too.
What I would like is someone to tell me, in simple language that I can understand (which might be the most difficult part of this question) the big picture of what I need and what to do (and maybe even links to where I can find what I need) to set up a C environment with CVODE. If the information is Windows/Gentoo Linux cross platform, even better.
Thank you.
P.S. I did search the site and saw lots of "How do I setup" quesitons, but no C one. Because I know someone will yell at me for that. Also, I don't want to have a convo about whether to use C#, C++, Java, etc. That just complicates the issue - and I need to get this done.
Edit: I have learned a little more since this question and now realize that I left out a key part of the question. The CVODE library and Linux cluster at school use MPI - parallel programming - which is not available on your average, run-of-the-mill PC. So all development must be done directly on the cluster.
Linux: Simple way is to install gcc or g++.
You can write your code in your plain text editor (nano, vim, gedit, kwrite, etc)
Save your file in .c or .cpp extention and type in terminal
gcc filename.c
or
g++ filename.cpp
You said that you want to write c code on Gentoo Linux, as i understand you're not familiar with Linux? The best choice in this case is to:
Install virtualbox in your windows machine (https://www.virtualbox.org/), it's a free software that let you emulate in your desktop another systems like Linux...
Install Gentoo linux on virtualbox, there are a lot of tutorials on the net, for example this video: http://www.youtube.com/watch?v=DUf_1wAPeyA
When you install Gentoo Linux on virtualbox you have all you need to develop C (gcc compiler, gdb debugger...)
Now you can download your library, and decompress it
In general all (Good) Linux libraries come with a 'README' file that contain all instructions for installing the library.
I think you need to do this:
./configure --prefix=/DIRECTORY_YOU_WANT_TO_INSTALL_THE_LIBRARY
make
make install
You can now play with C and you new library, like this:
suppose you create a new file test_lib_ CVODE.c you can compile it like this:
gcc -Wall test_lib_ CVODE.c -o test_lib_ CVODE -lcvode
I assume that the installed library is named libcvode.so
If you have any questions, you can always get help here.
Regards.
I think you should use Code::Block in Linux, it is very similar to Window's Code::Block and it is very easy to debug and other things.
These were all useful answers. I tried pursuing each of them at least a little bit. However, the only reasonable solution seems to be to use emacs on a terminal window. This is because I'm using MPI - yes, I know I didn't mention that in the OP - which can only be done on a cluster.
I am new to this environment and was not aware of the MPI or the affect it would have on my attempt to develop.
I believe I can do better than this if I can figure out X/Windows using Cygwin. But I am a long way from that.
Thanks all for your effort and sorry I can't really award a best answer (I guess).

what software should i use when i want to study c

i want to write code use notepad and compile the c code use cmd on windows (like java),
what software should i use ,
gcc for windows
cygwin
Turbo C
gvim
thanks
An excellent option for Windows is the Visual C++ Express Edition (which is free). This is a full IDE, compiler, and debugger and is a great way to get started.
GCC is also a good option if for some reason you wish to avoid an IDE. I wouldn't recommend this for a beginner, though.
Please don't use Turbo C, it's very old and you will have problems with it.
Cygwin is a popular linux environment for Windows.
Gvim is an editor and (in my opinion) has a very high learning curve. You could use Notepad++ or Code::Blocks to develop your code in.
mingw is also a good option to start with.
IMO you should avoid IDEs: a beginner needs to actually see and feel the whole process of compiling by invoking the compiler from a terminal, not by simply pressing some keys and bang! Also most of the IDEs have code completion facilities which is not good for beginners (especially for C). So I would go with vim (or gvim) and cygwin.
PS: Give Linux a try, you might actually like it; then vim and gcc.
Use cygwin. It's just about the only way to get a C environment on Windows that's both modern (i.e. not 16-bit, DOS-based) and conformant to the standards, and with it you get a fairly-complete POSIX environment, which allows you to actually do interesting things with C.
The classics would be Cygwin and MSYS/MinGW.
Cygwin provides a Linux API compatibility layer and includes a package manager which provides access to many well-known Linux applications (ie batteries included).
MSYS/MinGW only provides a minimal userland to get the GNU build system working.
Both come with their own shell environment, but can be used from Windows' command line as well.
Binaries created with Cygwin-gcc won't work without cygwin1.dll, but you get all the benefits of a mostly-POSIX environment. You can also use Cygwin's MinGW package for cross-compilation and thus create stand-alone binaries.
Other solutions are possible: Currently, I'm using the MinGW compiler together with the Cygwin userland from the Windows command line...
I think cygwin itself named as gcc for windows.
also gvim is not a compiler , It is a very nice and powerful tool for code editing.Also you can try emacs and kwrite
Some suggestions from my side:
In windows, you need to install a third party software to try all programming stuffs(c,c++ etc) ,Most of the times it is having GUI implementations and you didn't get any exact idea behind the code execution flow.also the command prompt of windows not at all efficient as linux shell.
But if you install a good linux distro (ubuntu/fedora/cent os/debian/pardus/suse/arch linux),all default compilers,debuggers and editors are installed within the OS and you can try the basic and all advanced programs by just opening the terminal(shell).Also the shell is a more powerful tool and you can enjoy all kind of automation comamnds(I mean scripting).
Also: for your added information, most of the embedded programmers in the industry prefer command line execution unlike GUI implementation because it is too fast than GUI.

How can I improve my C coding process on OS X?

I'm currently learning C from some Harvard screencasts. They're great. I'm currently, because I'm used to it, using this process for running my code:
Type it it TextMate
Save it
gcc filname
run "./a.out"
goto 1
Is there a major process, program, or best practice I'm missing here? I've tried apple-R in TextMate, but to compile something bare-bones like...
#include <stdio.h>
int
main(int argc, char * argv[])
{
int x = 342;
int y = 92;
int z = x + y;
printf("these values added are: %d\n", z);
return 0;
}
...takes 4 seconds which is clearly no good. Is there a great environment/compiler shortcut, or anything else I could be doing to make the actual testing more streamlined?
Thanks!
I use text mate and gcc in the terminal. I find Xcode too bulky for small commandline programs in C. It's great if you want to do cocoa GUI applications, need a quick Apple API reference or want a graphic frontend to gdb etc. 4 seconds sounds excessive for the program you have above, but it's probably due to Textmate cmd-R shortcut. I have never used that for anything else than scripts. But I agree that you should install Xcode, it's on your Mac OS install disk.
I disagree if you want to code ANSI C then this is what I'd suggest. Get familiar with a more powerful text editor, be it vim, emacs or whatever. I prefer vim.
See here:
http://macvim.org/OSX/index.php
Now, you should try to setup GNU Make for Mac OS X.
Doing this you will learn the methods most C programmers have used for ages. I think you'll get a lot more out of this than using Xcode straight out. With Xcode you want to make sure you are doing C and not Objective-C.
Now, with an editor like vim, you can do everything from a single terminal and waste fewer cycles switching around in your workflow.
So your workflow becomes:
$vim foo.c
(save)
$make
$./a.out
If you want to do any serious C programming that has any relevance to the UNIX envirnoment (and I suspect that Harvard course does), you will need to learn make at some point.
Install Apple's development tools, and use the XCode IDE. It may or may not increase your compile time, but it will greatly decrease much of the pain of hand coding and compiling on the command line.
To create a simple command-line C program (like the one you're describing above) do this:
File->New Project
Choose Command Line Tool as the project type.
The template includes a "hello world" program with a main.c file.
Edit the main.c file to include the code you're working on.
Run the project by choosing the Build and Run button.
**be sure to open the Console to view the output of your program. (Run->Console)
Good luck!
As mentioned before, XCode is the Mac way of doing it.
Just to give you an alternative solution, you can also use vi/vim from within a terminal. You open the file for the first time by typing vi filename.c. Then you type :w to save the file, :!gcc filename.c to compile it and :!./a.out to run it. The exclamation point does the trick of calling a shell command, so the last two commands can be replaced by one :!gcc filename.c; ./a.out . You also have a command history ("arrow up", "arrow down") from within vi, after pressing the colon.
Getting used to vi is a different story...
Try to build with gcc -Wall -Werror and try to understand and fix your warnings. That is always good practice.
I wouldn't recommended switching to XCode unless you need to use the debugger. GDB integration with XCode is pretty nice, and non-existent with Textmate.
To improve your Textmate workflow for smallish projects, learn to use make and install the Makefile bundle for Textmate. You can find it on GitHub.
This will give you a new Build ("Command-B") option in Textmate that will run make, parse the output, and let you easily correct compile time errors.
I think you should continue what you're doing. 4 seconds isn't that much time to wait, especially once your programs grow more extensive. Just using a basic text editor and gcc will let you master the basics of C. Once you're ready to start making GUI apps, then I would suggest to start using XCode to take advantage of the tools to make those kind of applications. I think an IDE is overkill at this point.
There should use Emacs or Vim with a Makefile. They can do anything.
For example, in Emacs, compiling is as simple as M-x Compile (But of course you could bind any key to it). Emacs is also cross-platform (Unlike XCode and TextMate).
Emacs also provides various other features useful for debugging (Built-in gdb support, ability to parse compile output, etc)
Using an IDE-Specific build tool is the exact wrong way to do things (Especially if that IDE happens to be platform specific, like XCode and TextMate)

Resources