How to build mixed C and C++ project in CodeWarror

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to build mixed C and C++ project in CodeWarror

1,397 Views
dsclarsky
Contributor I

Hi.

I have an ongoing GCC LINUX project with dozens of source files all written in C.

The project builds with CodeWarrior for our QorIQ processor board.

I would like to introduce some isolated C++ code to the project, but minimize the changes required to the existing source code.

I know how to write mixed C and C++ code, using extern "C", etc, so that's not a problem.

My problem is getting CodeWarrior to compile the project correctly.

To simplify, I created a brand new C++ project, which gave me main.cpp.

CodeWarrior chooses g++ to build main.cpp.

I then added one C source file, called funcs.c.

I was hoping that CodeWarrior would choose gcc for this new file, but it chose g++ instead.

I tried adding the C Compiler via the tool chain editor (ignoring the "tool conflict" error), but this didn't help.

Does anyone know how I can coerce CodeWarrior to use the C compiler for files with .c extension and continue to use the C++ compiler for files with .cpp extension?

tia,

DaveS.

0 Kudos
4 Replies

1,234 Views
yipingwang
NXP TechSupport
NXP TechSupport

Hello David Sclarsky,

Which version CodeWarrior do you use? Which processor do you use?

Thanks,

Yiping

0 Kudos

1,234 Views
dsclarsky
Contributor I

Hi Yiping, thanks for the reply!

We're using "CodeWarrior for Power Architecture Version 10.5.2", building for the NXP QorIQ T2080 processor.

I tried 'check for updates' but that didn't find anything.

Any advice would be greatly appreciated!

Thanks,
DaveS.

0 Kudos

1,234 Views
yipingwang
NXP TechSupport
NXP TechSupport

Hello DaveS,

In CodeWarrior IDE, only one Compiler command can be specified from Project->Properties->C/C++ Build->Settings->PowerPC* C Compiler for each project.

You could create a C compiler project to build your C program as a library and import this lib in the C++ compiler project.

Thanks,

Yiping 

0 Kudos

1,234 Views
dsclarsky
Contributor I

wow, that seems like a serious limitation for a build tool.  By definition, C++ was designed to inter-operate well with C.

I am working on a project with many developers, most have never used C++.

I finally convinced them to let me introduce some C++ into the project by telling them we could keep all existing code (except we might have to reorganize main()) and just add new .cpp files where appropriate.

I've been using C++ for about 30 years and have always been able to mix C and C++ easily in the same tool.

It's going to be difficult to ask them to put all of their existing code into a library just so I can add a module or two where I really need to use STL containers.

Is there really no other option?

0 Kudos