Reply
Thread Tools
Posts: 61 | Thanked: 77 times | Joined on Dec 2009 @ Lancaster
#1
Hello,

I am porting a simple camera application from a Maemo C project to QT C++ project. I always thought one can mix .c and .cpp files in the project and share the variables through out the project.

I added the .c files to my .pro file and tired to compile it. I got tones of errors. Am I missing something? Is this possible at all? Is this good practice?

Thank you for your advice.
Klen
 
hopbeat's Avatar
Posts: 516 | Thanked: 643 times | Joined on Oct 2009 @ Denmark/Poland
#2
If your .c files compile all right manually, you can check the Makefile qmake generated for you and make sure that it is not trying to use g++ on your .c files.
__________________
Hi! I'm a Maemo Greeter!
Witaj na talk.maemo.org!

Useful links for newcomers:
Użyteczne linki:
Nowi użyktownicy mówią cześć | New members say hello , Tu zaczynają nowi użytkownicy | New users start here, Podforum społeczności | Community subforum, Wiki dla początkujących | Beginners' wiki page, Maemo5 101, Często zadawane pytania | Frequently Asked Questions (FAQ), Google

Jeżeli mogę w czymś pomóc, pytaj!
If I can help with anything else, just ask!

Bored? Follow me
 

The Following User Says Thank You to hopbeat For This Useful Post:
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#3
It depends on what is inside your .c file :-)
Most C-code is valid C++-code, so it is possible but not always.
And the standard c-includefiles like stdio.h, stdlib.h, math.h have c++ counterparts
called cstdio, cstdlib, cmath ...

nicolai
 

The Following User Says Thank You to nicolai For This Useful Post:
Posts: 415 | Thanked: 732 times | Joined on Jan 2009 @ Finland
#4
You might need to

Code:
extern "C" {
#include <some-c-lib.h>
}
 

The Following User Says Thank You to timoph For This Useful Post:
Posts: 61 | Thanked: 77 times | Joined on Dec 2009 @ Lancaster
#5
I decided to wrap the code into C++ classes and managed to compile it yesterday evening. I might try to do it with .c files just to see how it works out.

Thanks for your help.
Klen
 
Posts: 353 | Thanked: 263 times | Joined on Dec 2009 @ Finland
#6
I think you can add extern "C" {} around the .c files' content and with #ifdefs use them in both C and C++ projects. Like this:

Code:
#ifdef CPLUSPLUS
// I don't remember if 
// it was CPLUSPLUS or something else
extern "C" {
#endif

// content of .c file here

#ifdef CPLUSPLUS
}
#endif
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 14:54.