Hey everyone, I learned some C about 3 years ago, but have mainly been programming in Matlab since. I want to dive back into C, especially now that I am running Ubuntu.
I started out by re-writing a little piece of code that computers BMI to see if it would compile correct (The code is actually from a class I took a while ago). Then I typed in:
gcc BodyMassIndex.c
For some reasons, it doesn't seem to be recognizing my two headers, which leads to lots of errors.
#include <stdio.h>
#include <math.h>
I saw somewhere online to try typing in:
sudo apt-get install build-essentials
When I do this, I get an error that says:
E: Couldn't find package build-essentials
Anyways, I was hoping someone could help, I just want to be able to compile my code. Thank in advance!![]()
-
Check if you have those header files hidden away somewhere on your system. (I'm guessing you do, and just need to set the path)
-
Thanks!
-
You should familiarize yourself with the commands "locate" and "man". -
HAHA lemur likes to locate men. Bad joke; sorry.
Yeah, when I first started programming, I typed studio instead of stdio a couple of times. stdio is short for standard in/out. I know I'm not helping you any, but I just want to help you get a little more understanding for th C world. I myself have never programmed in Linux.
But if it's on purpose, I just wasted my time. Good luck with Linux. I gave up before I got the hang of it. -
I will also familiarize myself with the locate and man commands. Thanks. -
Is this the first package that you've tried to install? If so did you remember to do an 'apt-get update' before issuing the 'apt-get install...'? Is your /etc/apt/sources.list correct?
I'm not a Ubuntu user myself, but I understand that there are easier GUI methods (for the beginner) for installing software than using the console (not that I want to discourage anyone from using the console as it's my preferred method), Maybe? https://help.ubuntu.com/community/InstallingSoftware -
sudo apt-get install build-essentials -
First of all, it's not build-essentials, it's build-essential without a final 's'.
Secondly, build-essentials is required to build deb packages, not for compilation. Here's the first line of the package description:
I would be good to see the exact errors gcc give when compiling because right now we're just guessing.
Do you have the package libc6-dev installed? -
Alright, thanks everyone I got it working. All I did was the following two lines in a terminal.
sudo apt-get install
sudo apt-get install build-essential
One of the issues was I had an "s" on the end of essential.
Thanks for the help everyone! -
this command is handy for building packages(even from other sources):
apt-get build-dep <package>
e.g.:
apt-get build-dep python24
This would pull in everything(sometimes more like doc creation but who care about disk space these days) that is needed to build the python24 package. So if say you want to upgrade python(from 24 to 25 which is not in the repo) you don't need to hunt down libraries etc. not in build-essential(which I believe is only basic compiler, make stuff). -
-
Slightly off topic, there is really no sane reason to program in C. (unless you're working on the Linux kernel or anything like that)
You might as well get used to C++ for applications programming.
-
I'd be up for C++. Really what I am going to do is start programming in whatever languages that will be helpful for me when I start my robotics masters this fall. I know one project that is being worked on at my University has lots of Java code.
As for coding in C++, do you have any good online references that you would recommend? -
If you think Java is going to be used, why not spend time mastering Java instead of C++? I'm not a fan of C++ myself. I consider it to be a pretty good example of bad language design.
-
-
With a robotics course, C is quite applicable. Java and C++ have much larger compiled code sizes, and C is almost certainly going to be the only high-level language supported on many of the embedded chips you'd use in robotics. And either way, you gotta learn to walk before you can run... C++ is mostly just a superset of C. Learn C, and the weird things C++ does will make much more sense. Java too.
-
First, I'm right behind Lemur. C++ is (as I've said before), a horrible language, and I wouldn't recommend it (especially not for beginners). It's just that it's better than C, at least, and I assumed you wanted to stay with a "C-like language"...
If you can do that, you'll be able to pick up whichever language they want you to use very quickly.
So my recommendation would be to start with either Python, C# or Java (in order of preference)
Python is a really nice, and beginner-friendly language, and in some ways it's a lot more flexible than the two others, so it'll give you a good basis to build on. C# and Java are both more focused on a specific programming paradigm (You will write object-oriented code, and you will do it our way), and I personally think it's best not to close any doors too soon. Starting out with a language that doesn't lock you in, and lets you use the approach that seems most natural will probably make it easier for you to adapt to new languages later on.
That said, C# is a very good language too, and Java is decent too.
Of course, C# might be a bit limited on Linux. I know there is a C# compiler, and Mono to replace .NET, but I don't know how easy it is to set up, and how many mysterious errors you'll run into along the way.
Python, on the other hand, is very well supported on Linux.
C++ is not easy to learn, and *extremely* hard to learn *well*. Which means most tutorials either 1) teach you bad practices, 2) give you code that doesn't, or shouldn't, work, or 3) suck.
If you want to learn C++, the best you can do is buy a good book about it (one that doesn't have "in 24 days", or "for Dummies" in the title, an isn't written by André LaMothe)
If you do choose to learn C++, I can recommend this book, which just so happens to be freely distributed as a PDF. It's also easy to read, and very beginner-friendly.
I do have a few issues with some of the content of the later chapters (teaches what I'd consider bad practices), but that's a minor criticism only. Overall, it's probably the best beginners C++ book I've seen.
Edit:
Yes, C is applicable for (some) robotics stuff, but not all.
But you'll definitely need C sooner or later, I'll give you that.
I wouldn't recommend learning C before C++ though. It just doesn't make sense that a beginner should be burdened with all the idiosyncrasies of C.
(How exactly, does the fact that you're forced to use a pointer to represent strings, make "the weird things in C+ make more sense"? The answer, it doesn't. It's one of C's own idiosyncrasies, and it certainly shouldn't be allowed to mess with the minds of beginners.
On the other hand, once you know C++, you've already learned about pointers and all the other stuff, so C suddenly becomes very easy to learn. (Hey, it's just C++ where I can't use the standard library or templates, and have to do things the hard way...)
But C++ allows you to start out with at least somewhat meaningful stuff.
(And yes, I've recently had to teach a beginning programmer how to work with C strings... That alone should be enough reason to keep away from the language until you know C++)
Java is used for robotics, and not all robotics is about embedded applications.
That said, Java certainly has its own set of stupid programming practices, which is why it was last on my list (but still before C)
About compiled executable size, C++ isn't necessarily bad. It depends a lot on the compiler, but you can get executable sizes close to that of equivalent C programs without too much trouble. (But again, I doubt people starting out on a robotics course are required to worry about code size at all. Focus on learning programming first, which is best done in a programmer-friendly langauge. Which excludes C, and to some extent, C++)
Edit2:
However, let's end this thread here. You got your C compiler working, so if we're going to discuss programming languages, let's do it in a more appropriate thread.
While I enjoy discussing programming, it's not really within the scope of this thread. -
Thanks for the long lengthy replies. I appreciate the time you have taken to right them. That said. I think what I will do is talk to some of the professors I plan to work with and see what they are using in terms of code. I know a lot of them use a few languages, so I will see which ones they recommend the most.
As far as programming goes, I have done a lot of programming in Matlab over my undergraduate career for robotics classes and research that I used to do. I have a pretty good sense about how to program, just need to extent my knowledge into different languages. Thanks for the help everyone! -
Pitabred, I think you're reading too much in what I wrote.
-
I use Lua for resources constrained environment, such as my WRT54G(openwrt) router.
Otherwise, I would use python. -
But in the end, it doesn't really make a difference which language(s) you decide to learn now. No matter which you choose, it'll help you out later on. -
C Compiler for Ubuntu?
Discussion in 'Linux Compatibility and Software' started by Mark, Jul 14, 2007.