help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MinGW build of 3.2.0: shared libstdc++


From: Benjamin Lindner
Subject: Re: MinGW build of 3.2.0: shared libstdc++
Date: Fri, 05 Jun 2009 20:58:36 +0200
User-agent: Thunderbird 2.0.0.18 (Windows/20081105)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]