On Mon, 2011-07-18 at 10:26 +0800, JonY wrote:
On 7/18/2011 05:15, Jean-Claude Gervais wrote:
> Hello!
> 
> I am unable to link a DLL:
> 
> i686-pc-mingw32-g++ --version (Gentoo 4.5.2 p1.1, pie-0.4.5) 4.5.2
> 
> ------ libmain.cpp
> 
> #include <vector>
> 
> extern "C" int simplecall( const char * pszHello ) {
> 
>     std::vector<int> s;
>     
>     return 0;
> 
> }
> 
> ------
> 
> i686-pc-mingw32-g++ -g -I/usr/i686-pc-mingw32/usr/include  -DWINDOWS
> -D_WINDOWS -DWIN32 -D_M_IX86   -DDEBUG  -Wall   -c -o libmain.o
> libmain.cpp
> 
> i686-pc-mingw32-g++ -o ./libsimplelib.so.1~ -shared -lwsock32 -lcomctl32
> -Wl,-soname,libsimplelib.so.1 libmain.o
> libmain.o: In function `~vector':
> /usr/lib/gcc/i686-pc-mingw32/4.5.2/include/g++-v4/bits/stl_vector.h:312:
> undefined reference to `___gxx_personality_sj0'
> libmain.o: In function `~_Vector_base':
> /usr/lib/gcc/i686-pc-mingw32/4.5.2/include/g++-v4/bits/stl_vector.h:131:
> undefined reference to `___gxx_personality_sj0'
> libmain.o: In function _ZN9__gnu_cxx13new_allocatorIiE10deallocateEPij':
> /usr/lib/gcc/i686-pc-mingw32/4.5.2/include/g
> ++-v4/ext/new_allocator.h:95: undefined reference to `operator
> delete(void*)'
> 
> The same code compiles OK with g++
> Please help me, I'm sure I forgot something but I can't figure out what
> 

You are mixing C++ code between compilers, don't do that. C++ doesn't
define ABI, compile  everything using the same compiler to fix it, don't
use precompiled libraries.


JonY, Earnie,

Thank you for taking the time to read my query!

I have not explained correctly: I am building a dll that does NOT link to any 3rd-party dll or library.

The example supplied is self-contained c++ code that compiles and links OK as long as no instance of STL objects are created.

I'm using i686-pc-mingw32-g++ to compile the code and the STL headers.

Then I again invoke i686-pc-mingw32-g++ to link the object compiled above to produce a dll.

Of the libraries mentioned on the link line, all are supplied by mingw.

How is this mixing code between compilers?

Thanks again