problem with C++ project and custom C librarie

bridged with qnx.development_tools
Post Reply
Armand Ciejak

problem with C++ project and custom C librarie

Post by Armand Ciejak » Tue Aug 30, 2005 8:41 am

I've got 2 projects using the same custom librarie (written in C).
One is a C project and the second is a C++ project.
Both projects are configured the same, but only the C project compiles
without errors.
In the C++ project I've got the following error:

Idefix.o: In function `GPI(void)':
Idefix.o(.text+0xe08): undefined reference to `mpc85xx_get_ccsr(void)'
Idefix.o(.text+0xe08): relocation truncated to fit: R_PPC_REL24

"mpc85xx_get_ccsr(void)" is obviously a function of the custom librarie.

Any idea how to solve this?

Environment:
- Momentics (Windows hosted)
- QNX 6.3.0 SP1
- gcc 2.95.3

Garry Turcotte

Re: problem with C++ project and custom C librarie

Post by Garry Turcotte » Tue Aug 30, 2005 1:52 pm

I'd guess it's looking for the C++ name mangled version.
Do you have an extern "C" prototype defined?

Armand Ciejak wrote:
I've got 2 projects using the same custom librarie (written in C).
One is a C project and the second is a C++ project.
Both projects are configured the same, but only the C project compiles
without errors.
In the C++ project I've got the following error:

Idefix.o: In function `GPI(void)':
Idefix.o(.text+0xe08): undefined reference to `mpc85xx_get_ccsr(void)'
Idefix.o(.text+0xe08): relocation truncated to fit: R_PPC_REL24

"mpc85xx_get_ccsr(void)" is obviously a function of the custom librarie.

Any idea how to solve this?

Environment:
- Momentics (Windows hosted)
- QNX 6.3.0 SP1
- gcc 2.95.3

Armand Ciejak

Re: problem with C++ project and custom C librarie

Post by Armand Ciejak » Tue Aug 30, 2005 2:52 pm

Garry Turcotte wrote:
I'd guess it's looking for the C++ name mangled version.
Do you have an extern "C" prototype defined?
Yes -> extern uint32_t mpc85xx_get_ccsr();
Armand Ciejak wrote:

I've got 2 projects using the same custom librarie (written in C).
One is a C project and the second is a C++ project.
Both projects are configured the same, but only the C project compiles
without errors.
In the C++ project I've got the following error:

Idefix.o: In function `GPI(void)':
Idefix.o(.text+0xe08): undefined reference to `mpc85xx_get_ccsr(void)'
Idefix.o(.text+0xe08): relocation truncated to fit: R_PPC_REL24

"mpc85xx_get_ccsr(void)" is obviously a function of the custom librarie.

Any idea how to solve this?

Environment:
- Momentics (Windows hosted)
- QNX 6.3.0 SP1
- gcc 2.95.3

Garry Turcotte

Re: problem with C++ project and custom C librarie

Post by Garry Turcotte » Tue Aug 30, 2005 3:17 pm

Armand Ciejak wrote:

Garry Turcotte wrote:

I'd guess it's looking for the C++ name mangled version.
Do you have an extern "C" prototype defined?


Yes -> extern uint32_t mpc85xx_get_ccsr();
No -> extern "C" uint32_t mpc85xx_get_ccsr();
without the "C", you'd be looking for something
like mpc85xx_get_ccsr__Fv

Armand Ciejak wrote:

I've got 2 projects using the same custom librarie (written in C).
One is a C project and the second is a C++ project.
Both projects are configured the same, but only the C project
compiles without errors.
In the C++ project I've got the following error:

Idefix.o: In function `GPI(void)':
Idefix.o(.text+0xe08): undefined reference to `mpc85xx_get_ccsr(void)'
Idefix.o(.text+0xe08): relocation truncated to fit: R_PPC_REL24

"mpc85xx_get_ccsr(void)" is obviously a function of the custom librarie.

Any idea how to solve this?

Environment:
- Momentics (Windows hosted)
- QNX 6.3.0 SP1
- gcc 2.95.3

Chris Herborth

Re: problem with C++ project and custom C librarie

Post by Chris Herborth » Tue Aug 30, 2005 5:50 pm

Armand Ciejak wrote:

Garry Turcotte wrote:

I'd guess it's looking for the C++ name mangled version.
Do you have an extern "C" prototype defined?


Yes -> extern uint32_t mpc85xx_get_ccsr();
Try:

extern "C" uint32_t mpc85xx_get_ccsr();

Presumably there would be a header (protected by extern "C" { ... })
defining that prototype somewhere...

--
Chris Herborth (cherborth@qnx.com)
Never send a monster to do the work of an evil scientist.
Monthly QNX newsletter - http://www.qnx.com/news/forms/newsletter.html

Armand Ciejak

Re: problem with C++ project and custom C librarie

Post by Armand Ciejak » Wed Aug 31, 2005 7:49 am

On Tue, 30 Aug 2005 19:50:31 +0200, Chris Herborth <cherborth@qnx.com>
wrote:
Armand Ciejak wrote:
Garry Turcotte wrote:

I'd guess it's looking for the C++ name mangled version.
Do you have an extern "C" prototype defined?
Yes -> extern uint32_t mpc85xx_get_ccsr();

Try:

extern "C" uint32_t mpc85xx_get_ccsr();

Presumably there would be a header (protected by extern "C" { ... })
defining that prototype somewhere...
Now in my C++ file:

extern "C" {
#include <mpc8540_gpio.h>
}

in mpc8540_gpio.h:

uint32_t mpc85xx_get_ccsr();

everything work fine except that I got no warning or error if I do that
(in the C++ file):

float tmp = mpc85xx_get_ccsr();

In other word I have to do data type checking myself :-(

JohnMcClurkin

Re: problem with C++ project and custom C librarie

Post by JohnMcClurkin » Wed Aug 31, 2005 11:30 am

The method I use to incorporate C libraries in C++ projects is
to begin the library header file with...
#ifdef __cplusplus
extern "C" {
#endif

Then, at the end of the header file are the lines
#ifdef __cplusplus
}
#endif

Armand Ciejak wrote:
On Tue, 30 Aug 2005 19:50:31 +0200, Chris Herborth <cherborth@qnx.com
wrote:

Armand Ciejak wrote:

Garry Turcotte wrote:

I'd guess it's looking for the C++ name mangled version.
Do you have an extern "C" prototype defined?

Yes -> extern uint32_t mpc85xx_get_ccsr();


Try:

extern "C" uint32_t mpc85xx_get_ccsr();

Presumably there would be a header (protected by extern "C" { ... })
defining that prototype somewhere...


Now in my C++ file:

extern "C" {
#include <mpc8540_gpio.h
}

in mpc8540_gpio.h:

uint32_t mpc85xx_get_ccsr();

everything work fine except that I got no warning or error if I do that
(in the C++ file):

float tmp = mpc85xx_get_ccsr();

In other word I have to do data type checking myself :-(

Armand Ciejak

Re: problem with C++ project and custom C librarie

Post by Armand Ciejak » Wed Aug 31, 2005 11:52 am

I tried but It doesn't change anything!!!

On Wed, 31 Aug 2005 13:30:52 +0200, JohnMcClurkin <jwm@lsr.nei.nih.gov>
wrote:
The method I use to incorporate C libraries in C++ projects is
to begin the library header file with...
#ifdef __cplusplus
extern "C" {
#endif

Then, at the end of the header file are the lines
#ifdef __cplusplus
}
#endif

Armand Ciejak wrote:
On Tue, 30 Aug 2005 19:50:31 +0200, Chris Herborth <cherborth@qnx.com
wrote:

Armand Ciejak wrote:

Garry Turcotte wrote:

I'd guess it's looking for the C++ name mangled version.
Do you have an extern "C" prototype defined?

Yes -> extern uint32_t mpc85xx_get_ccsr();


Try:

extern "C" uint32_t mpc85xx_get_ccsr();

Presumably there would be a header (protected by extern "C" { ... })
defining that prototype somewhere...
Now in my C++ file:
extern "C" {
#include <mpc8540_gpio.h
}
in mpc8540_gpio.h:
uint32_t mpc85xx_get_ccsr();
everything work fine except that I got no warning or error if I do
that (in the C++ file):
float tmp = mpc85xx_get_ccsr();
In other word I have to do data type checking myself :-(

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Mario Charest

Re: problem with C++ project and custom C librarie

Post by Mario Charest » Wed Aug 31, 2005 12:46 pm

Now in my C++ file:

extern "C" {
#include <mpc8540_gpio.h
}

in mpc8540_gpio.h:

uint32_t mpc85xx_get_ccsr();

everything work fine except that I got no warning or error if I do that
(in the C++ file):

float tmp = mpc85xx_get_ccsr();

In other word I have to do data type checking myself :-(
That's normal C/C++ behavior, doesn't have anything to do with the extern C
stuff.

It's an automatic promotion.

David Gibbs

Re: problem with C++ project and custom C librarie

Post by David Gibbs » Wed Aug 31, 2005 4:05 pm

Armand Ciejak <armand.ciejak@free.fr> wrote:
On Tue, 30 Aug 2005 19:50:31 +0200, Chris Herborth <cherborth@qnx.com
wrote:
Now in my C++ file:

extern "C" {
#include <mpc8540_gpio.h
}

in mpc8540_gpio.h:

uint32_t mpc85xx_get_ccsr();

everything work fine except that I got no warning or error if I do that
(in the C++ file):

float tmp = mpc85xx_get_ccsr();
Because that is perfectly acceptable.

Would you expect a problem with:
float tmp = 5;

Nope. You've done the same thing -- assigned an integer to a float,
which is a perfectly acceptable (and expected) promotion, and will
not generate a warning or error.

-David
--
David Gibbs
QNX Training Services
dagibbs@qnx.com

Post Reply

Return to “qnx.development_tools”