Hi all,

This one has good news and bad news.

The good: I've finally managed to compile Xerces under Cygwin cleanly
          and with no kludges

The bad: The linked library created with Cygwin does not define the
         symbols correctly!

Another good: I think I can fix it

Another bad: It requires a small modification to virtually every .cpp
        file under Xerces OR contact Cygnus and tell them to fix this.
        
I mean, everything compiles fine, but when trying to link a little
example program it doesn't find any of the defined symbols!

After many days of research I found the following: the problem seems
to be with Cygwin itself.

Here's a very small example of what's happening:

// -------------------------------------
// Foo.hpp

#include <stdio.h>
#if VARIANT
#define DLLEXP1 __declspec(dllexport)
#define DLLEXP2 
#else
#define DLLEXP1
#define DLLEXP2 __declspec(dllexport)
#endif

DLLEXP1 class Foo {
public:
        DLLEXP2 void bar();
        DLLEXP2 void bar2();
};

//-------------------------------------------
// Foo.cpp

#include "Foo.hpp"
#include <iostream>

DLLEXP1 void Foo::bar() { cout << "bar" << endl; }

        void Foo::bar2() { cout << "bar2" << endl; } // note DLLEXP1 missing

//-------------------------------------------
// Test.cpp
#include "Foo.hpp"
#include <iostream>

int main() {
    Foo f;
    f.bar();
    f.bar2();
    return 0;
}

//-------------------------------------------
// makefile
cpp:
        g++ -c Foo.cpp
        dlltool --dllname Foo.dll -e exports.o -l Foo.lib Foo.o
        g++ -shared Foo.o exports.o -o Foo.dll
        g++ -c Test.cpp
        g++ Test.o Foo.lib -o Test

//-------------------------------------------
  

If VARIANT = 0, then the program works perfectly.
IF VARIANT = 1, the linker exits while building Test (last line
                of the makefile) with bar2() undefined.

VARIANT = 0 prepends the __declspec(dllexport) to each METHOD
declaration. By using this variant, the same __declspec is NOT
needed in the .cpp.

VARIANT = 1 prepends the __declspec(dllexport) to each CLASS
declaration. This DOESN'T work under Cygwin, unless you prepend
this __declspec again in each .cpp. Look at the .cpp and see
that bar2() doesn't have it repeated and bar() does.

The problem is that this SHOULD work! I mean, those __declspec
where invented by Microsoft and are as well required to compile
a DLL under Cygwin (when linking against an import library, when
linking at run time there's no need to do it).

Clearly, Cygwin behavior doesn't adhere to the expected mechanism at
least as MS defined it.

The proof is that Xerces uses "VARIANT = 1" (__declspec in the class
headers) and doesn't repeat the __declspec in the .cpp (that's what
should be changed).

Does anyone know of an easier way or should I inform this to Cygnus?

If your reached this line then you should be really interested :)

-- 
Saludos,
 nacho                          mailto:[EMAIL PROTECTED]
--
"Yo no soy paranoico. Eso es lo que *ellos* quieren que piense"
--



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to