The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    C Compiler for Ubuntu?

    Discussion in 'Linux Compatibility and Software' started by Mark, Jul 14, 2007.

  1. Mark

    Mark Desktop Debugger

    Reputations:
    1,288
    Messages:
    4,172
    Likes Received:
    0
    Trophy Points:
    105
    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! :)
     
  2. Jalf

    Jalf Comrade Santa

    Reputations:
    2,883
    Messages:
    3,468
    Likes Received:
    0
    Trophy Points:
    105
    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)
     
  3. Mark

    Mark Desktop Debugger

    Reputations:
    1,288
    Messages:
    4,172
    Likes Received:
    0
    Trophy Points:
    105
    Jalf could you elaborate on how to do that. I am essentially a noob when it comes to linux. :eek: Thanks!
     
  4. lemur

    lemur Emperor of Lemurs

    Reputations:
    524
    Messages:
    1,024
    Likes Received:
    0
    Trophy Points:
    55
    Are you sure you mean studio.h and not stdio.h?

    You should familiarize yourself with the commands "locate" and "man".
     
  5. jbizzler

    jbizzler Notebook Consultant

    Reputations:
    31
    Messages:
    274
    Likes Received:
    0
    Trophy Points:
    30
    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.
     
  6. Mark

    Mark Desktop Debugger

    Reputations:
    1,288
    Messages:
    4,172
    Likes Received:
    0
    Trophy Points:
    105
    Yes, I did mean stdio.h and that is what I have in my code. (Updated my post)

    I will also familiarize myself with the locate and man commands. Thanks.
     
  7. timberwolf

    timberwolf Notebook Consultant

    Reputations:
    131
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    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
     
  8. Gladiator

    Gladiator Notebook Consultant

    Reputations:
    38
    Messages:
    126
    Likes Received:
    0
    Trophy Points:
    30
  9. lemur

    lemur Emperor of Lemurs

    Reputations:
    524
    Messages:
    1,024
    Likes Received:
    0
    Trophy Points:
    55
    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:

    He's not trying to build a deb, he's trying to compile. Out of curiosity I've created a file with just the two includes and nothing else. I was able to compile without a problem.

    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?
     
  10. Mark

    Mark Desktop Debugger

    Reputations:
    1,288
    Messages:
    4,172
    Likes Received:
    0
    Trophy Points:
    105
    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!
     
  11. chimpanzee

    chimpanzee Notebook Virtuoso

    Reputations:
    683
    Messages:
    2,561
    Likes Received:
    0
    Trophy Points:
    55
    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).
     
  12. Mark

    Mark Desktop Debugger

    Reputations:
    1,288
    Messages:
    4,172
    Likes Received:
    0
    Trophy Points:
    105
    Thank you for the info. It is pretty nifty how easy it is to get new software on Linux (not too mention it is free!).
     
  13. Jalf

    Jalf Comrade Santa

    Reputations:
    2,883
    Messages:
    3,468
    Likes Received:
    0
    Trophy Points:
    105
    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.

    As long as it is in the package tree, yes. ;)
     
  14. Mark

    Mark Desktop Debugger

    Reputations:
    1,288
    Messages:
    4,172
    Likes Received:
    0
    Trophy Points:
    105
    I guess I am insane then! :p

    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?
     
  15. lemur

    lemur Emperor of Lemurs

    Reputations:
    524
    Messages:
    1,024
    Likes Received:
    0
    Trophy Points:
    55
    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.
     
  16. Mark

    Mark Desktop Debugger

    Reputations:
    1,288
    Messages:
    4,172
    Likes Received:
    0
    Trophy Points:
    105
    Sounds like a plan. Do I need to install anything special for that? Also, and good starting points would be appreciated. Thanks.
     
  17. Pitabred

    Pitabred Linux geek con rat flail!

    Reputations:
    3,300
    Messages:
    7,115
    Likes Received:
    3
    Trophy Points:
    206
    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.

    Because Java doesn't work in embedded applications? Because it has it's own set of stupid programming practices? (Guess what kids, everything is Java is an object, except when it's not, with things like int, char, etc. You have to treat those specially. And operator overloading isn't allowed because it might make code easier to read.) C is a high-level language that you can still treat a lot like assembly, and when working "close to the metal" like you do with robotics and other embedded applications, it's well worth the size and complexity reduction. Java isn't a magic language, nor is C or C++. Use them where they fit.
     
  18. Jalf

    Jalf Comrade Santa

    Reputations:
    2,883
    Messages:
    3,468
    Likes Received:
    0
    Trophy Points:
    105
    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"... ;)

    What I'd do is start with a language that's easy to learn, and make sure you get used to programming in general. The language you use doesn't really matter, what's important is that you learn to break down problems and express solutions in code.

    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.

    A book. :D
    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:
    I have to disagree here.
    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.
     
  19. Mark

    Mark Desktop Debugger

    Reputations:
    1,288
    Messages:
    4,172
    Likes Received:
    0
    Trophy Points:
    105
    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!
     
  20. lemur

    lemur Emperor of Lemurs

    Reputations:
    524
    Messages:
    1,024
    Likes Received:
    0
    Trophy Points:
    55
    Pitabred, I think you're reading too much in what I wrote.

    Java works on my Treo and also on cell phones much less powerful than a Treo but I guess that's not embedded enough for you. See also this page.

    I never said Java is perfect but for all its faults, I find C++ more deficient.

    Regarding Integer vs int, please Google "java autoboxing" and learn. Operator overloading is specifically one of the features of C++ which I think makes for bad language design.

    I totally agree with this. No one is trying to get Mark not to learn C. The question was between C++ and Java.

    Nobody ever said Java is a magic language.
     
  21. chimpanzee

    chimpanzee Notebook Virtuoso

    Reputations:
    683
    Messages:
    2,561
    Likes Received:
    0
    Trophy Points:
    55
    I use Lua for resources constrained environment, such as my WRT54G(openwrt) router.

    Otherwise, I would use python.
     
  22. Jalf

    Jalf Comrade Santa

    Reputations:
    2,883
    Messages:
    3,468
    Likes Received:
    0
    Trophy Points:
    105
    That seems a pretty sensible approach... ;)
    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.
     
  23. Mark

    Mark Desktop Debugger

    Reputations:
    1,288
    Messages:
    4,172
    Likes Received:
    0
    Trophy Points:
    105
    Yes, I couldn't agree with you more. From my programming expereince, which is limited since I am a mechanical engineer, it seems that programming is all about how you approach and think about your programming problem. And that was the hardest thing for me to learn. After that, it is all syntax! :p