Forums

Sample makefile for C++ compilation

Started by sri June 15, 2009
Hi,
I am using LPC2000 i got a make file from embedded artist which works for C programs. i would like to use C++ for my application. I changed gcc to g++ in the makefile but it seems not to work can some one share a makefile i am using winarm compiler

Regards
Raman

An Engineer's Guide to the LPC2100 Series

You have to link in the c++ libs as well.
Also if using newlib or other external C code, you need to 'wrap' the calls/include statements to avoid c++ name mangling.

C++ is bad you know? Read the C++ FAQ.
http://www.parashift.com/c++-faq-lite/

C++ code will be larger, due to more overhead. Not a prob on a 512Kb device, maybe more so on a 32kb device.

You have to post errors and code to get more help.
--- In l..., "sri" wrote:
>
> Hi,
> I am using LPC2000 i got a make file from embedded artist which works for C programs. i would like to use C++ for my application. I changed gcc to g++ in the makefile but it seems not to work can some one share a makefile i am using winarm compiler
>
> Regards
> Raman
>

What "more overhead"?

Jan
----- Original Message -----
From: "JoeR"
To:
Sent: Tuesday, June 16, 2009 3:04 PM
Subject: [lpc2000] Re: Sample makefile for C++ compilation
You have to link in the c++ libs as well.
Also if using newlib or other external C code, you need to 'wrap' the
calls/include statements to avoid c++ name mangling.

C++ is bad you know? Read the C++ FAQ.
http://www.parashift.com/c++-faq-lite/

C++ code will be larger, due to more overhead. Not a prob on a 512Kb device,
maybe more so on a 32kb device.

You have to post errors and code to get more help.
--- In l..., "sri" wrote:
>
> Hi,
> I am using LPC2000 i got a make file from embedded artist which works for
> C programs. i would like to use C++ for my application. I changed gcc to
> g++ in the makefile but it seems not to work can some one share a makefile
> i am using winarm compiler
>
> Regards
> Raman
>

--- In l..., "Jan Vanek" wrote:
>
> What "more overhead"?

All that OO goodness has to come at a price, no? (Sometimes I sure miss that clean easily-understood hierarchy of inheritted classes/structures. Every time I find myself writing something more than about 10 files large, the obsessive compulsive in me wants to switch back to C++ or C# or some other warm and fuzzy OO language.)

Kevin.

Read the C++ FAQ.
Better, buy the book, theres even more in there.

Just because YOU do not define a Destructor, does NOT mean there isn't one. Copy constructs are another.
A lot of stuff is done for you by the compiler, thats overhead.
--- In l..., "Jan Vanek" wrote:
>
> What "more overhead"?
>
> Jan
> ----- Original Message -----
> From: "JoeR"
> To:
> Sent: Tuesday, June 16, 2009 3:04 PM
> Subject: [lpc2000] Re: Sample makefile for C++ compilation
> You have to link in the c++ libs as well.
> Also if using newlib or other external C code, you need to 'wrap' the
> calls/include statements to avoid c++ name mangling.
>
> C++ is bad you know? Read the C++ FAQ.
> http://www.parashift.com/c++-faq-lite/
>
> C++ code will be larger, due to more overhead. Not a prob on a 512Kb device,
> maybe more so on a 32kb device.
>
> You have to post errors and code to get more help.
> --- In l..., "sri" wrote:
> >
> > Hi,
> > I am using LPC2000 i got a make file from embedded artist which works for
> > C programs. i would like to use C++ for my application. I changed gcc to
> > g++ in the makefile but it seems not to work can some one share a makefile
> > i am using winarm compiler
> >
> > Regards
> > Raman
>

You have much more expressive language and the price is its complicity and
more gotchas. But the price is certainly not paid in the size or in the
performance of the generated code.

I think it is obvious that I'm convinced there is no "more overhead". On the
other hand I don't want to start yet another C/C++ flame war. My objection
was against blind assertions like "C++ is bad" and "code will be larger, due
to more overhead".

Regards,
Jan
----- Original Message -----
From: "Kevin Townsend"
To:
Sent: Tuesday, June 16, 2009 4:33 PM
Subject: [lpc2000] Re: Sample makefile for C++ compilation
--- In l..., "Jan Vanek" wrote:
>
> What "more overhead"?

All that OO goodness has to come at a price, no? (Sometimes I sure miss
that clean easily-understood hierarchy of inheritted classes/structures.
Every time I find myself writing something more than about 10 files large,
the obsessive compulsive in me wants to switch back to C++ or C# or some
other warm and fuzzy OO language.)

Kevin.

> I think it is obvious that I'm convinced there is no "more overhead". On the
> other hand I don't want to start yet another C/C++ flame war. My objection
> was against blind assertions like "C++ is bad" and "code will be larger, due
> to more overhead".

While I think there has to be some overhead (even the 'creator' of C++ seems to have said as much), I couldn't agree more that C++ is the right choice in certain instances.

I think you need to pick the right tool (language) for the right job. Once I get past a certain number of files (or code complexity), it just makes more sense to me to be organising my project in a way that is not only easier for others to understand and maintain, but for ME to understand and maintain when I come back to it 6 months later. Or even while I'm developing it, just to stay sane and keep it all straight in my head.

I love the concise simplicity of C. I also love to warm and fuzzy goodness of object-oriented code, though. It's really just a matter of which is right and when, but it's definately not B&W/Good vs. Evil/etc.

That said ... I think I'm hijacking this thread, and there's no point beating dead horses anyway. :-)

Kevin

> Just because YOU do not define a Destructor, does NOT mean there isn't
> one. Copy constructs are another.
> A lot of stuff is done for you by the compiler, thats overhead.

The destructor is generated and used (called or inlined) if it is necessary,
e.g. when a member variable is of a class which contains non-empty
destructor.

The stuff done for you by the compiler is not an overhead. It just saves
typing which you have to do in C manually.

And in this particular case, you have to define your own "destructor" in a
form of a close() function and which is worse you have to call it (and not
forget) each time you need to dispose your variable, whereas in C++ this is
all done automatically when the variable goes out of scope, without typing,
and without the possibility to forget it.

Regards,
Jan
--- In l..., "Jan Vanek" wrote:
>
> What "more overhead"?
>
> Jan
> ----- Original Message -----
> From: "JoeR"
> To:
> Sent: Tuesday, June 16, 2009 3:04 PM
> Subject: [lpc2000] Re: Sample makefile for C++ compilation
> You have to link in the c++ libs as well.
> Also if using newlib or other external C code, you need to 'wrap' the
> calls/include statements to avoid c++ name mangling.
>
> C++ is bad you know? Read the C++ FAQ.
> http://www.parashift.com/c++-faq-lite/
>
> C++ code will be larger, due to more overhead. Not a prob on a 512Kb
> device,
> maybe more so on a 32kb device.
>
> You have to post errors and code to get more help.
> --- In l..., "sri" wrote:
> >
> > Hi,
> > I am using LPC2000 i got a make file from embedded artist which works
> > for
> > C programs. i would like to use C++ for my application. I changed gcc to
> > g++ in the makefile but it seems not to work can some one share a
> > makefile
> > i am using winarm compiler
> >
> > Regards
> > Raman
>

To exclude part of the c++ libraries overhead (that's a lot), if you can
live
without the C++ library set, and catch/throw functionality you can
remove the -lstdc++ at linking time and add this to your code (GCC
4.4.0...):
int __gxx_personality_sj0 = 0xdeadbeef;
void * operator new (unsigned long sz)
{
void *p;

if (sz == 0) sz = 1;
p = (void *) malloc (sz);
// if (!p) crash!
return p;
}
void operator delete (void *p)
{
free(p);
}
If you can live without new/delete, using static or heap objects, just
remove the
new/delete definitions, and all the malloc/free from stdlib is gone :-)

I also love C++ warm when code complexity rises too much :-)

2009/6/16 Kevin Townsend

> > I think it is obvious that I'm convinced there is no "more overhead". On
> the
> > other hand I don't want to start yet another C/C++ flame war. My
> objection
> > was against blind assertions like "C++ is bad" and "code will be larger,
> due
> > to more overhead".
>
> While I think there has to be some overhead (even the 'creator' of C++
> seems to have said as much), I couldn't agree more that C++ is the right
> choice in certain instances.
>
> I think you need to pick the right tool (language) for the right job. Once
> I get past a certain number of files (or code complexity), it just makes
> more sense to me to be organising my project in a way that is not only
> easier for others to understand and maintain, but for ME to understand and
> maintain when I come back to it 6 months later. Or even while I'm developing
> it, just to stay sane and keep it all straight in my head.
>
> I love the concise simplicity of C. I also love to warm and fuzzy goodness
> of object-oriented code, though. It's really just a matter of which is right
> and when, but it's definately not B&W/Good vs. Evil/etc.
>
> That said ... I think I'm hijacking this thread, and there's no point
> beating dead horses anyway. :-)
>
> Kevin
>
>
>

--
Miguel Angel Ajo Pelayo
http://www.nbee.es
+34 91 120 1798
+34 636 52 25 69
skype: ajoajoajo


I have code written in C++ for 8k parts.
C++ is just somewhat harder to know what you are doing, since there's a lot
left for compiler work.
It may be used to help readability, code reuse, time-to-market and many
other aspects. Indeed, I still haven't found a case where it has improved
performance (size or speed), but it may also be possible.

Regards
Ricardo

On Tue, 16 Jun 2009 13:04:36 -0000, "JoeR" wrote:
> You have to link in the c++ libs as well.
> Also if using newlib or other external C code, you need to 'wrap' the
> calls/include statements to avoid c++ name mangling.
>
> C++ is bad you know? Read the C++ FAQ.
> http://www.parashift.com/c++-faq-lite/
>
> C++ code will be larger, due to more overhead. Not a prob on a 512Kb
> device, maybe more so on a 32kb device.
>
> You have to post errors and code to get more help.
> --- In l..., "sri" wrote:
>>
>> Hi,
>> I am using LPC2000 i got a make file from embedded artist which works
for
>> C programs. i would like to use C++ for my application. I changed gcc to
>> g++ in the makefile but it seems not to work can some one share a
>> makefile i am using winarm compiler
>>
>> Regards
>> Raman
>>
>