0
votes

I have some troubles with Embarcadero C++ Builder XE3. When I run my program, I have an access violation BEFORE the first instruction in the main...So I can't debug, it's very weird.

I used to have this problem a couple of weeks ago : I was forced to full rebuild the entire projet (even if only a comma was missing...) and the violation didn't occurs anymore. I solved it by ckecking the option "Disable incremental link".

I was very happy, but today, the problem is back, and whatever I do, my application crash before enterring in the main ...

Does anyone have an idea ? It's a big project, so I can't really post an exemple because I don't really know what to show...

Thanks a lot

1
Do a clean (manually delete all .obj files and other build files). Another thing that can cause this problem is if some files are compiled with runtime linking of the RTL and/or packages, and some files compiled with static linking. Yet another thing is if the exe depends on a DLL that is not found. To debug it, cut down your project to just int main() {}, get that working, and then work from there. I'd also highly recommend using source control (e.g. git) so that you can save a known-good build and quickly identify what might have changed. - M.M
If it's happening before main, then it's most likely the initialisation of a static/global variable. Be very careful of the "initialisation order fiasco", where the initialisation of one static variable uses another which hasn't yet been initialised. Avoid global variables if you can. - Mike Seymour
If it is a static init problem then the debugger would step into it - M.M
Thanks a lot ! Both of you helped me :) I use SVN for source control, so I restored the previous version, and check one by one each modification... And, as you expected, it's a static initialisation : .h class MyClass { public std::string MyString; } .cpp : string MyClass::MyString = NULL; I didn't know it was impossible...I replaced NULL with an empty string, and it's now OK ! string MyClass::MyString = ""; Thank you two again :) - Katsudon
You do realize that std::string is a class that does its own initialization, right? You don't need to manually initialize it with a blank value, it is already blank to begin with. - Remy Lebeau

1 Answers

0
votes

Probably you have a bug in a constructor of a static global object. These constructors are all executed before getting into main(), so this can happen without being a runtime environment or a compiler bug.

As you told, debugging these is difficult as you probably don't know which class is failing, and probably you don't have exception info also.

As you say it's a large project, perhaps you have to resign to use large project toolkits/methodologies to deal with these problems, like unit testing and lean methodologies (like scrum or the like).

With the information you post I think this is the most can be said.