I have written a small program (it depends on big libraries, so I will not post the actual code) that performs correctly, but segfaults at the very end (main return).

int main()
{
 ..... my code here...
	std::cout << "Finished." << std::endl;
	
	return 0;
}

I see "Finished." printed, and then there is a segmentation fault. Is there a common thing that could cause this (i.e. memory not released, etc) that I can look for?

David

comment out code by code to see where the error occurs.

I used the debugger to step through the code and it gets all the way to the end with no errors. Only when I run the program without the debugger does it segfault after everything finished.

Perhaps you're doing something illegal in a destructor somewhere? It's a bit hard to tell without seeing code.

[edit]
Something horrible like...

class crash {
public:
    int foo[];
    ~crash(){delete[] foo;}
};

int main(){
    crash cr;
    cout << "hi!";
    return 0;
}

...will probably have the same effect as your own program.

remove the std....

cout << "Finished." <<end1;

commented: Award for the most horrible reply! -4

remove the std....

cout << "Finished." <<end1;

Perhaps you should learn C++ first, before you try replying to a thread. end1; != endl; , so your code won't compile. Also learn namespaces and find out why your suggestion about removing std:: is wrong.

[edit]
I just found out that you're programming C++ for > two years now. So you really should know these basics. :icon_eek:

commented: Well said. BTW, a remark on your signature: maybe put a space between 'tags' and 'when' ? :P +21

you tell me that you are using many libraries. tell me are they statically
linked or not ?

In the C++ it's more than main method. There may be static objects on the global scope that are created already. For example STL's input and output objects are some objects that created.
and the order of the static initialization isn't guaranteed across the
many compilation units. so when the destructor is called there can
be a problem. so after the main even those things are happning.
a good pratice for avoid this is avoid static initializations.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.