Add a C++ module to an ASF project?

Go To Last Post
17 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have built an ASF project using CDC USB, for educational purposes.

I want to add some code. I'd like to write it with C++. I added a couple of .cpp files to the project but Studio won't try to compile them.

The file's properties Build Action is set to None. I can set the Build Action to Compile, but that does no good. It still won't compile them. When I close and reopen the project the Build Action is again set to None.

I am using Studio 6.1.2440.
.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This has been discussed before so you should be able to find the previous thread.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I searched but I can't find my symptom or cure. Most of the hits I got had to do with libraries and linkages. I did get a hint though. I suspect the makefile doesn't know what to do with .cpp files.

Interesting. I build C++ projects with Studio all the time. C++ is all I use.

I'm wondering if I should try building the project from scratch. This ASF project has many files scattered around many folders. It seems like a big job.

But I still don't understand what is going on. I believe Studio remakes the makefile whenever I do a build. So either I'm wrong about the makefile not handling .cpp files or there is something about the project that somehow ignores the .cpp files.

I looked at the makefile. It seems to mention each source file by name. My .cpp files are not there.

I'm confused and ticked off.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I looked at the properties of this C project and the properties of a CPP project. That tells the story. The C project toolchain has a C compiler (avr-gcc). The CPP project has that and also a CPP compiler (avr-g++).

So I'm wondering if I could add a second project to this ASF solution that would be a CPP project. Maybe the linker would link up the two projects, or maybe not.
.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See:

https://www.avrfreaks.net/index.p...

I'd consider upgrading your 2440 to 2730 if what Dean said there was true.

Also read from here onwards:

https://www.avrfreaks.net/index.p...

In particular:

Dean wrote:
The current workaround for this is to add "-x c++" to the compiler flags (open the C++ file, then open the Properties window) to force the C++ compiler to be invoked. It's only a workaround at the moment but we'll look into better support in the future for C++ in ASF projects.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
See:

https://www.avrfreaks.net/index.p...

I'd consider upgrading your 2440 to 2730 if what Dean said there was true.

I will download the upgrade on Friday when I have access to a high speed internet connection.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Also read from here onwards:

https://www.avrfreaks.net/index.p...

In particular:

Dean wrote:
The current workaround for this is to add "-x c++" to the compiler flags (open the C++ file, then open the Properties window) to force the C++ compiler to be invoked. It's only a workaround at the moment but we'll look into better support in the future for C++ in ASF projects.
I guess the attached is what Dean is talking about. Unfortunately it doesn't work. The .cpp file is still not compiled.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried changing the extension of the .cpp file to .c. Now I can compile it but it seems to be compiling with the C compiler. The included header file produces an error:

unknown type name 'class'

EDIT: My mistake. When I changed the extension, I lost the compiler flags. I put the flags back and I may be making some progress.

Last Edited: Wed. Sep 4, 2013 - 11:46 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Indeed. That is not the solution. If you look at the generated Makefile you will see it contains a .c to .o rule that invokes the C compiler that is not what you want. There needs to be a rule there for .cpp to .o that either invokes avr-g++ direct or that invokes avr-gcc with then "-x c++" option.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff, I edited my previous post while you were posting. I'm now compiling as C++, I think. I have some other incidental errors to take care of. Also I get some warnings that some command line options like '-Wstrict-prototypes' is valid for C but not C++. That doesn't seem to be serious though.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Maybe the linker would link up the two projects, or maybe not.

Not. Or at least not by default or automagically.

If one of the projects is a "binary library" project and th eother project is an executable and that later project has the result of the first in the list of libs to link in - then it would.

But not just because you place the two projects in the same solution.

Quote:
this ASF solution

The solution is not "an ASF solution". It is just a solution. A solution is just a container for one or more projects. Those projcts might be quite diverse, so the solution can not be said to be of any specific type.

A projet might be "an ASF project".

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yep. I was thinking of making one of the projects a library. I've never done that with Atmel Studio. In fact I've never made any libraries of my AVR code.

Anyway, I think I've accomplished my mission. I got it to build correctly. I haven't tested it yet. I want to make some tweaks to my C++ module.

As I indicated in previous posts, I changed the properties of my C++ module so the Build Action is Compile, and the Custom Compilation Setting is -x c++. Then I changed the file extension to .c. Actually you need to do it in the opposite order. Changing the file extension clears out the Properties changes.

Also, I think I found the magical mystical button to push that saves the properties changes for all time. Click on File >> Save All.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there any way to remove compiler options for selected files?

Every time I compile one of the C++ files, with the extension of .c of course, I get three warnings.

Warning	1	command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++ [enabled by default]	cc1plus.exe	0	0	usb_DEVICE_EXAMPLE1
Warning	2	command line option '-Wmissing-prototypes' is valid for C/ObjC but not for C++ [enabled by default]	cc1plus.exe	0	0	usb_DEVICE_EXAMPLE1
Warning	3	command line option '-std=gnu99' is valid for C/ObjC but not for C++ [enabled by default]	cc1plus.exe	0	0	usb_DEVICE_EXAMPLE1

I can live with it, but it is a bit messy.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, why not turn the warning off then?

Add

-Wno-strict-prototypes

to the compiler options for those files.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not much help, but thanks anyway.

Warning	2	command line option '-Wno-strict-prototypes' is valid for C/ObjC but not for C++ [enabled by default]	cc1plus.exe	0	0	usb_DEVICE_EXAMPLE1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh, OK. I see...

Sorry for being too quick on the trigger.

So it seems that Studio pushed the switch onto the compilation command. I can't see much you can do about that.

Yup, I'd hate that warning too. A build with warnings is not a clean build IMO.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually this ASF project has 3 warnings right out of the box. I don't see them though unless I do a clean build.

Warning	7	'sck_pin' may be used uninitialized in this function [-Wmaybe-uninitialized]	F:\Archiveable\AVR_butterfly\Xmega\Atmel_studio_6\usb_DEVICE_EXAMPLE1\usb_DEVICE_EXAMPLE1\src\ASF\common\services\ioport\xmega\ioport.h	138	20	usb_DEVICE_EXAMPLE1
Warning	8	'sck_pin' was declared here	F:\Archiveable\AVR_butterfly\Xmega\Atmel_studio_6\usb_DEVICE_EXAMPLE1\usb_DEVICE_EXAMPLE1\src\ASF\xmega\drivers\usart\usart.c	98	15	usb_DEVICE_EXAMPLE1
Warning	9	'type' may be used uninitialized in this function [-Wmaybe-uninitialized]	F:\Archiveable\AVR_butterfly\Xmega\Atmel_studio_6\usb_DEVICE_EXAMPLE1\usb_DEVICE_EXAMPLE1\src\ASF\xmega\drivers\usb\usb_device.c	992	2	usb_DEVICE_EXAMPLE1