PDA

View Full Version : non_lazy_ptr



anoopmj
30th June 2010, 12:08
Hi Guys,

I am new to Qt and have been trying to compile a program which works on linux and windows on a mac. Unfortunately while doing so, I get the following error:


"typeinfo for std::bad_alloc", referenced from:
__ZTISt9bad_alloc$non_lazy_ptr in CConfigHandler.o
(maybe you meant: __ZTISt9bad_alloc$non_lazy_ptr)

I traced this back to the following lines in the file qvector.h inside qt framework:

QT_CATCH (const std::bad_alloc &) {
if (aalloc > d->alloc) // ignore the error in case we are just shrinking.
QT_RETHROW;

I don't understand why qt itself is giving this error.. if I understand right, this error is only on a mac, and is due to the pointer not being linked.

Any suggestions?

ChrisW67
1st July 2010, 00:29
Is this message coming from the compiler, the linker, or the resulting program when run? What is CConfigHandler doing with the QVector?

anoopmj
1st July 2010, 12:37
The message from the program when I run it, but i think it is a linker issue, CConfigHandler just includes QVector (below). I am not too sure what it is doing with it. However, std::bad_alloc is not in any other flies besides QVector.h.

#include <QVector>

Why does it say:
"typeinfo for std::bad_alloc", referenced from:
__ZTISt9bad_alloc$non_lazy_ptr in CConfigHandler.o
(maybe you meant: __ZTISt9bad_alloc$non_lazy_ptr)
collect2: ld returned 1 exit status
make[1]: *** [/qdoas.app/Contents/MacOS/qdoas] Error 1
make: *** [sub-qdoas-make_default-ordered] Error 2

Doesn't this indicate a library problem? If it is, then I don't know which library I need!

Thanks!

SixDegrees
1st July 2010, 12:51
So, if CConfigHandler just includes QVector, then get rid of the include statement, since it isn't needed.

Or, post the code for CConfigHandler, and perhaps your project file. Without them, there's no way to tell what the problem is.

anoopmj
1st July 2010, 12:56
I tried removing it and it stops. Apparently it uses it here in CConfigHandler.h:

QVector<QString> m_paths;

the project files are really large.. but i could post a link to the whole thing here if necessary.

Cheers!

SixDegrees
1st July 2010, 13:05
It's possible that you are using typeinfo/typeid incorrectly.

It's possible that you are trying to store something other than a QString in the QVector noted.

It's possible that your compiler doesn't support, or wasn't configured to use typeinfo.

It's possible it is something else altogether.

Try stuffing your error message into Google. There seem to be some discussions on this elsewhere; it may be related to an old C++ compiler version.

Just for grins, see what happens if you add '#include <new>' to your file. This should be where std::bad_alloc is defined.

anoopmj
1st July 2010, 13:08
This is the project which was given to me and I know it works on Unix other unix systems. They also have a windows version, but I have a mac and really want to make it work on the mac. The documentation is also in the folder... i know its a lot, but hopefully someone knows what is going wrong!


http://dl.dropbox.com/u/8655075/qdoas_1.161_Linux.tar.gz

anoopmj
1st July 2010, 13:14
It's possible that you are using typeinfo/typeid incorrectly.ç
I haven't changed anything in the code and apparently it words on other unix systems.

It's possible that you are trying to store something other than a QString in the QVector noted.
How can I check this?

It's possible that your compiler doesn't support, or wasn't configured to use typeinfo.
Is there some way I can change the configuration? I didn't change anything after the install.

It's possible it is something else altogether.
I am fearing that!!

Try stuffing your error message into Google. There seem to be some discussions on this elsewhere; it may be related to an old C++ compiler version.
Tried it.. and thats why i thought it was a library issue... but then, I have no clue.. :S

Just for grins, see what happens if you add '#include <new>' to your file. This should be where std::bad_alloc is defined.
I'll try doing this... how do I define a std:bad_alloc? The same as in Qvector?

anoopmj
1st July 2010, 13:35
So I tried removing the code from QVector

QT_CATCH (const std::bad_alloc &) {
if (aalloc > d->alloc) // ignore the error in case we are just shrinking.
QT_RETHROW;


And now it gives an error at the same place, but without the std::bad_alloc

"std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)", referenced from:
CHelpImplAssistant::slotAssistantError(QString const&) in CHelpSystemImpl.o
CHelpImplAssistant::slotAssistantError(QString const&) in CHelpSystemImpl.o
CHelpImplAssistant::slotAssistantError(QString const&) in CHelpSystemImpl.o
CWMain::slotErrorMessages(int, QString const&)in CWMain.o
CWMain::slotErrorMessages(int, QString const&)in CWMain.o
CWMain::slotErrorMessages(int, QString const&)in CWMain.o
CWMain::slotErrorMessages(int, QString const&)in CWMain.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [/qdoas.app/Contents/MacOS/qdoas] Error 1
make: *** [sub-qdoas-make_default-ordered] Error 2


So, I think that all the std::... are not being recognized. Why it stops at the same place, I don't know. I think this is a linking problem... any ideas how I can make sure that stdlib.h is linked in QVector? I made sure that

#include <stdlib.h>

is there, but it doesn't seem to work!! Do I have to define something else somewhere? It happens only with the non lazy pointers.

SixDegrees
1st July 2010, 13:57
Did you try including <new>? That's where std::bad_alloc is defined, as noted earlier.

I wouldn't go messing around with the Qt code unless someone at Nokia advises you to. It is very unlikely there are any problems there.

There may be a problem with your C++ compiler installation. Try reinstalling it. There could also be a problem with your project file, or with your compiler flags; check your compiler documentation and make sure you have set up your flags to allow processing of the std namespace, and haven't overridden any default, system settings.

Zlatomir
1st July 2010, 14:06
Disclaimer: I'm not sure about Qt containers, but they (just a guess) behave like stl ones, so:

std::bad_alloc exception is trown when new cannot allocate memory (usually remain out of RAM memory)

Now, a couple of questions:
1) how big is your vector?
2) are you passing your vector/s to functions by value? //usually you use const reference, if you don't need to modify the vector

and check constructors/ destructors of your type (that you store in QVector) you might have some memory leaks
Check copy constructors as well, they are used by the containers (stl, and most likely Qt's too, i'm not 100% sure about the Qt's ones ;) )

LE: If your class has pointers members make sure you define the copy constructor and copy what the pointers point to (not the pointer itself)
the default generated copy constructor (the one provided by compiler if you don't write one) will fail (not copy the data) if you have pointer members in your class.

anoopmj
1st July 2010, 14:58
Hi Guys,

Thanks for the help.

1) I tried including #include<new> but it didn't make a difference.
2) I don't know how big the vector is, but the code runs on a windows machine which is pretty low in memory and I am trying it on an iMAC with 8 gb RAM.. so I really doubt that this is a problem.

I checked through QVector again and there is

#include <stdlib.h>

in the header... I removed this and it still gives the exact same error. This to me says that the file is not being included and the std defs are not working... as I mentioned earlier, a linker problem.
Any way to work around this?

Zlatomir
1st July 2010, 15:13
You said it's a error when you run the application?
Removing included files from QVector isn't gonna help you.

And for us to give anything else but suggestions, we need to see some code. //or at least explain how we can replicate the problem.

As i said check the following: How you use the QVector (how big it gets, how it is passed to functions... ) and check the "things" that you put in the QVector, because the QVector will copy that things (probably many times, depending on what you do, like if you add a lot of elements, or sort, etc... )

And last thing, memory issues behave differently on different operating systems (and even different versions of the same OS), so if that code runes fine on Windows there is no guarantee that the code doesn't leak or do some other "nasty" things with dynamically allocated memory.

anoopmj
1st July 2010, 15:20
Hi Zlatomir

I've put the code here.

http://dl.dropbox.com/u/8655075/qdoa...1_Linux.tar.gz

I doubt that things would be so different from one unix system to another though. And this computer has a lot of memory - much much larger than any of the other computers. Additionally, the vector isn't getting called at all... the problem is before the application is run, its when the main program is being compiled.

Cheers!

Zlatomir
1st July 2010, 15:36
I didn't said it's definitely a memory leak... it might have been something else

But if it's a compile error this changes a little bit the problem.

And check the link, it's broken.

It's a exact copy of the project folder that you compiled on Linux and now it won't compile on Mac?
Qt Creator ask to import build settings, when you open a project, if it finds some (if you answered yes, do the following cleanup)
if it is the case, delete the make files and all the temporary files generated by moc, c++ compiler, or qmake. (a Clean All from the Build menu in Qt Creator usually does the trick, but in some cases you need to manually "clean" the project folder)

anoopmj
1st July 2010, 15:44
Hi,

Oops. Sorry for the link: http://dl.dropbox.com/u/8655075/qdoas_1.161_Linux.tar.gz

The program comes uncompiled and I am trying to compile it on the mac. I did do a cleanup using distclean before starting... at then every time I was going to qmake it.

anoopmj
1st July 2010, 17:44
Hi,

To update, I just found this in the output during compiling... do you think the second one has some bearing on the std:bad_alloc problem I am having? Any idea how to correct it?

ld: warning: in /usr/local/lib/libcoda.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /usr/local/lib/libstdc++.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

JD2000
1st July 2010, 19:08
First off, #include <stdlib.h> should be replaced with #include <cstdlib> to include the correct library

It looks like you are trying to build your programme for an i386 machine when your libraries have been built for a different architecture (64 bit perhaps?). Can you recompile the whole package including dependancies?

anoopmj
2nd July 2010, 18:53
Hi JD.. finally it was a architecture problem for compiling. I uninstalled Qt and installed the 64 bit version and the program compiled!

But the story doesn't end there. If I try and double click on the app - it crashes. It still doesn't pick up a library, which is very much there and is defined using

QWT_LIB_PATH = /usr/local/qwt/lib
QMAKE_LFLAGS += -rpath=$$QWT_LIB_PATH

So I exported the library to my bash_profile and now if I launch the app from terminal it works. But if I launch it using double click, it does not work.

Any idea how to make sure that the library is always added?

anoopmj
2nd July 2010, 19:40
I have found a way around this by googling this:


sudo mkdir qdoas.app/Contents/Frameworks

sudo cp /usr/local/qwt/lib/libqwt.5.dylib qdoas.app/Contents/Frameworks/

sudo install_name_tool -id @executable_path/../Frameworks/libqwt.5.dylib qdoas.app/Contents/Frameworks/libqwt.5.dylib

sudo install_name_tool -change libqwt.5.dylib @executable_path/../Frameworks/libqwt.5.dylib qdoas.app/Contents/MacOS/qdoas

This works, but is not very elegant a solution.. so if you have some ideas, they are still welcome!