Hello,
I try to cross compile the Windows project, that works since about 6 years with wxMSW 3.1.3 to the Linux wxGTK 3.1.3 and/or 3.0.0.
The Project consist from one shared lib and main app. the problem is, that first thing occurs in a lib is some wxString assignments.
And there is a segmentation fault occurs.
On the assignment :
ConfigData.Options.wsLANAddress = wxT("");
The gdb debugger shows the line (string.h line 1933):
m_impl = ImplStr(pwz);
I did installed the wxWidgets with apt-get. But with the self compiled version the same thing happens.
The compiler switches in the last case are the same as the switched for the lib and app, except that for the lib there is -fpic switch.
Can some one tel me, what did I missed with that shared libs, may be some Init of wxWidgets or some thing?
Thaks in Advance!
[Solwed (32 bit vs 64 bit ) ] Re: wxString class crashes in shared lib
-
- In need of some credit
- Posts: 5
- Joined: Fri Jan 22, 2021 2:58 pm
[Solwed (32 bit vs 64 bit ) ] Re: wxString class crashes in shared lib
Last edited by MasterAlexei on Tue Jan 26, 2021 12:15 pm, edited 1 time in total.
Re: wxString class crashes in shared lib
Code: Select all
ConfigData.Options.wsLANAddress = wxT("");
Please show the complete call stack.The gdb debugger shows the line (string.h line 1933):
m_impl = ImplStr(pwz);
Use the source, Luke!
-
- In need of some credit
- Posts: 5
- Joined: Fri Jan 22, 2021 2:58 pm
Re: wxString class crashes in shared lib
Here is the screenshot of Callstack:
from 3 to 1 is my shared lib.
on the left is the place, where debugger is stopped.
Point 6 is an OnActivate event handler. Also the context of the line is a wxFrame::OnActivate handler.
Conf is a member variable of the base class of the ComLibConfig.
and is assigned in the Open() function:
Conf = new wxFileConfig( "", "", wsFileName, "", wxCONFIG_USE_LOCAL_FILE );
Hope I put everything needed here.
from 6 to 4 is my Main programm,from 3 to 1 is my shared lib.
on the left is the place, where debugger is stopped.
Point 6 is an OnActivate event handler. Also the context of the line is a wxFrame::OnActivate handler.
Code: Select all
void DeviceETH::SetConfigFile( wxString cfgFN )
{
...
m_config = new(std::nothrow) ComLibConfig( wxT(""), cfgFN );
if( m_config )
{
m_config->Init( wxT(""), cfgFN );
m_config->Load(); // <<< here it is
LOG(LOG_DEBUG, wxT("Config file set"));
}
}
Code: Select all
bool ComLibConfig::Load()
{
...
...
Open(); // Creates the Conf in a Heap
...
...
Conf->SetPath("/");
...
...
ConfigData.Options.wsLANAddress = wxT(""); // <<< here it is
and is assigned in the Open() function:
Conf = new wxFileConfig( "", "", wsFileName, "", wxCONFIG_USE_LOCAL_FILE );
Hope I put everything needed here.
Re: wxString class crashes in shared lib
I usually work under Windows only and i have hard time interpreting the debugger output. The two pointer addresses look ok to me, so i'm not sure why or where exactly it crashes.
Do you link wxWidgets itself as a shared library (you should)?
Does your shared lib also link to wxWidgets?
Does it make any difference if you change wxT("") to "" ?
Do you link wxWidgets itself as a shared library (you should)?
Does your shared lib also link to wxWidgets?
Does it make any difference if you change wxT("") to "" ?
Use the source, Luke!
-
- In need of some credit
- Posts: 5
- Joined: Fri Jan 22, 2021 2:58 pm
Re: wxString class crashes in shared lib
For me too. I think that there is something not intialised in wxWidgets itself in the library context.
Difference with the windows is that in linux libs there is no main, where the initialisation may be done. There are just functions there. As I know it. May be I am wrong here, but on Raspi debian the same portion of code works without any problems. And now it is an ubuntu 18.04
Yes.
Yes
No.
The behavior is the same.
There is more. If I change that line to
ConfigData.Options.wsLANAddress.Empty();
then it crashes there:
Code: Select all
// delete characters from nStart to nStart + nLen
wxString& erase(size_type pos = 0, size_type n = npos)
{
wxSTRING_INVALIDATE_CACHE();
size_t from, len;
PosLenToImpl(pos, n, &from, &len);
m_impl.erase(from, len); // <<<<< here it is
return *this;
}
Re: wxString class crashes in shared lib
Hi,
I've no experience of cross-compiling (BTW, why not build in linux direct, in e.g. a virtualbox guest?) but:
Try changing that handler so that it just creates a delay, using e.g. CallAfter().
Regards,
David
I've no experience of cross-compiling (BTW, why not build in linux direct, in e.g. a virtualbox guest?) but:
makes me wonder if the handler is called too early, when something is not yet initialised.the context of the line is a wxFrame::OnActivate handler
Try changing that handler so that it just creates a delay, using e.g. CallAfter().
Regards,
David
-
- In need of some credit
- Posts: 5
- Joined: Fri Jan 22, 2021 2:58 pm
Re: wxString class crashes in shared lib
May be I sad it wrong here. I build in Linux (in virtual machine) direct but the same code, as for Windows. And it is not working in linux.
But I also building the same code in really cross compiling on Windows Host for Raspi, with RaspiGcc 6.3 Compiler. And there, on Raspi, it is working.
And there may be something. Raspi is a little bit slower as Intel I7... Ill try to make some delay before that call.
-
- In need of some credit
- Posts: 5
- Joined: Fri Jan 22, 2021 2:58 pm
[Solwed (32 bit vs 64 bit ) ] Re: wxString class crashes in shared lib
Well... Hello here.
I did find the cause of the problem: it is the 32 bit vs 64 bit.
The lib and the app are not yet checked for the 64 bit World. But they are compiles very well, and partly worked, but the transition of control in runtime between the app and lib is not so smooth, as it should be. The segmentation faults occurs partly in malloc func with the message "malloc corrupted size vs. prev_size". And, what makes me very curious, mostly (almost only) in wxString class.
So.
The problem is solved only after chrooting in 32 bit world, compile wxWidgets there with bunch of -m32 flags, and using THIS libs in 64 bit World, to compile lib and app with the same flag -m32.
Now it works!
But I think there will be a problem if I would want to make annother app but 64 bit. Bekaus, as I read out, it is very difficult to hold two versions of the same lib in one system...
But till now I produce mostly 32 bit apps, and can live with that some time.
I did find the cause of the problem: it is the 32 bit vs 64 bit.
The lib and the app are not yet checked for the 64 bit World. But they are compiles very well, and partly worked, but the transition of control in runtime between the app and lib is not so smooth, as it should be. The segmentation faults occurs partly in malloc func with the message "malloc corrupted size vs. prev_size". And, what makes me very curious, mostly (almost only) in wxString class.
So.
The problem is solved only after chrooting in 32 bit world, compile wxWidgets there with bunch of -m32 flags, and using THIS libs in 64 bit World, to compile lib and app with the same flag -m32.
Now it works!
But I think there will be a problem if I would want to make annother app but 64 bit. Bekaus, as I read out, it is very difficult to hold two versions of the same lib in one system...
But till now I produce mostly 32 bit apps, and can live with that some time.