MinGW build of 3.2.0: shared libstdc++

Benjamin Lindner lindnerben at gmx.net
Fri Jun 5 13:58:36 CDT 2009


Alexander Mamonov wrote:
> Hello Benjamin,
> 
> I still haven't lost the hope of building 3.2.0 with MinGW, and I've
> been looking into the shared libraries problem that I had before. I
> would like to ask your advice. Everybody else familiar with MinGW is
> welcome to comment as well (Tatsuro?).

I have had a reply to your last question on my in-mind-to-do list, sorry 
to keep you waiting.

> Consider a simple code (main.cxx):
> 
> #include <iostream>
> 
> void exthrow(void){
> 	int exval = 1;
> 	std::cout << "Exthrow: throwing exception:" << exval << std::endl;
> 	throw exval;
> }
> 
> int main(int argc, char* argv[]){
> 	
> 	try{
> 		exthrow();	
> 	}catch(int exval){
> 		std::cout << "Caught exception from exthrow: " << exval << std::endl;	
> 	}	
> 	
> 	return 0;
> }
> 
> Here is what happens:
> 
>> g++ -c main.cxx
>> g++ -o extest_static.exe main.o
>> ./extest_static.exe
> Exthrow: throwing exception:1
> Caught exception from exthrow: 1
> 
>> g++ -c -D_DLL main.cxx
>> g++ -o extest_shared.exe main.o -lstdc++_s
>> ./extest_shared.exe
> Exthrow: throwing exception:1
> terminate called after throwing an instance of 'int'
> 
> This application has requested the Runtime to terminate it in an unusual way.
> Please contact the application's support team for more information.
> 
> I tried this under GCC 4.3.0 TDM-2. I tried both SJLJ and DW2
> versions. Which compiler did you use to compile your Windows release
> of 3.0.5? Did you ever observe such problem?
> 

The point is, you *must* link with shared libgcc to be able to throw 
exceptions. So this should read
g++ -c -D_DLL main.cxx
g++ -o extext_shared.exe -shared-libgcc main.o -lstdc++_s

Bear in mind that *all*, I repeat *all* libraries you link your 
executable with must be linked with -shared-libgcc, even if they are 
C-only code and the question of the shared libstd++ does not arise.
If you miss one library, then you might be able to load the library or 
might be not, and if you might be able, you certainly will core-dump on 
an exception.

So for octave 3.2.0 I link all libraries with -shared-libgcc, otherwise 
the whole thing will not work.

By the way, you are not throwing exception across a dll boundary in your 
example. So even if you find a setting that works in your example, you 
should try with a test case involving a dll.

benjamin


More information about the Help-octave mailing list