Operating System - HP-UX
1833589 Members
4034 Online
110061 Solutions
New Discussion

Re: linking C++ STL and C libraries

 
SOLVED
Go to solution
HOUDOT
New Member

linking C++ STL and C libraries

I need to link a C++ program using the STL, with C libraries.

My binary dumps a core file when run with a BUS ERROR.

There seems to be a compatibility issue between "aCC -AA" and any other
compilation mode.

How can I create such a binary?

8 REPLIES 8
Adam J Markiewicz
Trusted Contributor

Re: linking C++ STL and C libraries

You shouldn't have any troubles in using C libraries from C++. Doesn't matter whather using STL or not. Most system libraries are C. (The other direction is not so easy.)

If there was a problem with dynamic linking it ends up with SIGABRT, not SIGBUS. SIGBUS is common for wrong data alignement for example...

Try analysig the core with debugger (i.e. gdb).

If you look for more detailed help don't be shy and describe the problem more preciselly. :)

Good luck

Adam
I do everything perfectly, except from my mistakes
HOUDOT
New Member

Re: linking C++ STL and C libraries

The C++ program linked without the C libraries work fine.
( no core dumped )

To enhance it, I need to use some functions from C object files ( compiled with cc ) linked to a shared library.

But when I ask to aCC to link to this library, there's no warning , everything semms okay.

Put when run, it failed before the main function and a core is dumped.

dde is unable to open it, seems like is trap in an infinite loop.
HOUDOT
New Member

Re: linking C++ STL and C libraries

The C++ program linked without the C libraries work fine.
( no core dumped )

To enhance it, I need to use some functions from C object files ( compiled with cc ) linked to a shared library.

But when I ask to aCC to link to this library, there's no warning , everything semms okay.

But when run, it failed before the main function and a core is dumped.

dde is unable to open it, seems like is trap in an infinite loop.
Adam J Markiewicz
Trusted Contributor
Solution

Re: linking C++ STL and C libraries

Hmmm.... really strange indeed.

What I would do is try to run the binary from the debugger.
It should stop your process at the signal, just before generating a core (at least this gdb does at defaut). So you could have a backtrace of function calls at least.

Good luck

Adam
I do everything perfectly, except from my mistakes
HOUDOT
New Member

Re: linking C++ STL and C libraries

gdb doesn't recognise such a binary.

All I've got as debugger is dde.

I succeed to make it logging something, with "-ui line" option.

"dde Bin/command core" fill the display with many lines like this one.

?(dde/obj_elf_som) Unexpected class member type detected (DNTT index 0x1).


Have anyone a clue ?
Adam J Markiewicz
Trusted Contributor

Re: linking C++ STL and C libraries

Good Lord, gdb doesn't recognise binary? I've never experianced such thing, so I'm not able to help.

The debugger entries are also strange. But you said the library was made with cc and your binnary with aCC. As there are two different compilers there could be mayby some sort of incompatibility? I think that compiling options for both (library and executable) could be worth to check. Mayby there is something that should be switched for this sort of library (something like position indepent code).
Is this library used by any other binary?

I use aCC by myself and also STL, but I don't have -AA. Actually my compiler supports only -Aa (I think it's too old). But I have no problems neither with STL nor with C libraries.

Honestly I feel pretty lost too. Have you tried to start the process from the dde without a core? As I wrote it could mayby catch the signal before dumping the core and let you see something more informative.

One more thought - as these are C functions: are they declared as extern "C" in your header? If not - this can cause troubles.

Last thing is that you gave me much points (thank you kindly) and this problem began to marked as 'solved'. Mayby it would be worth of starting a new one to show it's not solved yet.

Good luck

Adam
I do everything perfectly, except from my mistakes
Mike Stroyan
Honored Contributor

Re: linking C++ STL and C libraries

There are STL libraries for aCC with -AA mode and without -AA mode. You don't need to use -AA just to have STL.
If you do use -AA to put the system libraries in the std namespace, then you must recompile all C++ code with the -AA option. Mixing C++ code with and without -AA will cause trouble.
You can get a newer gdb from
http://www.hp.com/go/wdb
HOUDOT
New Member

Re: linking C++ STL and C libraries

Thank you to both of you.

I finally succeed to make a workable binary.

I learnt two points :
Don't forget "-mt" option ...

Don't link to useless libraries, if you don't call any of their fonctions ...


Any of them make a bad binary.