[Tfug] CentOS vs Ubuntu

John Gruenenfelder johng at as.arizona.edu
Tue Aug 10 18:02:01 MST 2010


On Mon, Aug 09, 2010 at 05:30:13PM -0700, John Hubbard wrote:
>At home I use Ubuntu or some flavor there of.  At work we use CentOS.
>I was looking at getting the software that I am writing at work run
>on my Ubuntu machine (it would make telecommuting easier).  All of
>the java code just complied and ran, but I have been having problems
>getting the C++ to compile and Google hasn't been giving me a whole
>lot.  For the record Ubuntu (10.04) is using g++ 4.4.3 and CentOS
>(5.?) is using 4.1.2.
>
>Unless I add a "#include <stdint.h>" Ubuntu's compiler complains
>about not knowing what an "int64_t" is.  Any guess why CentOS doesn't
>need the include and Ubuntu does?
>
>The Ubuntu compiler complains that "free" (as in the opposite of
>malloc) wasn't declared in this scope. I thought the c++ was
>backwards compatible with C and that free should be recognized.
>
>So here are my questions.  Any guesses what I need to include to get
>"free"?  Other than the obvious "the compilers are different", why am
>I seeing these compiler errors?  Is Ubuntu's g++ more restrictive and
>eventually CentOS's will give the same warnings, or is there some
>other difference?

Hi John,

That's pretty much it exactly: the newer versions of gcc/g++ are more strict
with regards to the standards than older versions and are much less likely to
let things slip by.

For the record, in C/C++, you need the proper include files for just about
everything except builtin types and your own functions.  free, malloc, printf,
etc. are all going to require the proper include files.

Also, since you are using C++, there are some minor name changes to include
files.  Both will work for now, I think, but maybe not in the future.  For
example, you need stdint.h to get types such as int64_t.  In C++, you would
instead include:

#include <cstdint>

And free() is part of the standard library just as malloc is.  In C that would
be stdlib.h and in C++ you want:

#include <cstdlib>

Notice that for many of these headers, the C++ variant (which ends up being
the same file eventually), requires you add a "c" to the beginning and drop
the ".h" from the end.

I think that should get you most of the way towards getting your C++ code
working on a newer compiler version.


-- 
--John Gruenenfelder    Systems Manager, MKS Imaging Technology, LLC.
Try Weasel Reader for PalmOS (soon for Android) --  http://weaselreader.org
"This is the most fun I've had without being drenched in the blood
of my enemies!"
        --Sam of Sam & Max




More information about the tfug mailing list