[xsd-users] Compile and link errors on Windows
Russ Loucks
rjl at third-monday.com
Mon Jan 3 18:34:50 EST 2011
On 01/03/2011 11:30 AM, Russ Loucks wrote:
> On 12/28/2010 12:11 PM, Russ Loucks wrote:
>> I have a small project that works on Linux (2.6.34), Mac (Snow
>> Leopard) and I'm now porting it to Windows (Vista).
>>
>> Since the project is rather portable, I'm using GNU make to build
>> everything, including the XSD structure (schema to source files,
>> source files to object files, then to dynamic library).
>>
>> I know there's some foo defined in the 'Using XSD with MS VS'
>> (Creating a DLL) online page, but I'm still having problems....
>> Here's a snapshot of what is happening:
>>
>> The xerces-c library I'm using is the 32-bit version.
>>
>> 1) I create a prolog file with the following text (exports.h):
>>
>> #ifdef XSD_EXPORTS
>> #define XSD_SYMBOL_DECL __declspec(dllexport)
>> #else
>> #define XSD_SYMBOL_DECL __declspec(dllimport)
>> #endif
>>
>> 2) I include the contents of this file into the generated .h files,
>> as follows:
>>
>> C:/Programs/xsd-3.3.0/bin/xsd cxx-tree --generate-serialization \
>> --show-sloc --generate-polymorphic --output-dir src/xsd
>> --hxx-suffix .h \
>> --cxx-suffix .cpp --generate-ostream --generate-inline \
>> --extern-xml-schema xmlSchema.h --hxx-prologue-fi le
>> src/xsd/export.h \
>> resource.xsd/channelListType.xsd resource.xsd/dataElementType.xsd \
>> resource.xsd/dataSourceType.xsd \
>> . . . .
>>
>> I verified the .h files do, indeed, include the contents of that
>> prolog file.
>>
>> However, I'm not sure what symbols need to be defined for compiles...
>>
>> 3) Compile line and warnings:
>>
>> g++ -IC:/Programs/xsd-3.3.0/libxsd
>> -IC:/Programs/xerces-c-3.1.1/include \
>> -DXSD_EXPORTS -c src/xsd/channelListType.cpp -o
>> build/xsd/channelListType.o
>>
>> In file included from
>> C:/Programs/xerces-c-3.1.1/include/xercesc/validators/datatype/DatatypeValidator.hpp:27,
>>
>> from
>> C:/Programs/xerces-c-3.1.1/include/xercesc/framework/XMLAttr.hpp:28,
>> from
>> C:/Programs/xerces-c-3.1.1/include/xercesc/framework/XMLElementDecl.hpp:25,
>> from
>> C:/Programs/xerces-c-3.1.1/include/xercesc/validators/common/Grammar.hpp:27,
>>
>> from
>> C:/Programs/xerces-c-3.1.1/include/xercesc/dom/DOMLSParser.hpp:29,
>> from
>> C:/Programs/xsd-3.3.0/libxsd/xsd/cxx/xml/dom/parsing-source.txx:7,
>> from
>> C:/Programs/xsd-3.3.0/libxsd/xsd/cxx/xml/dom/parsing-source.hxx:136,
>> from src/xsd/channelListType.cpp:43:
>> C:/Programs/xerces-c-3.1.1/include/xercesc/util/KVStringPair.hpp:178:
>> warning: 'void xercesc_3_1::KVStringPair::setKey(c onst XMLCh*,
>> XMLSize_t)' defined locally after being referenced with dllimport
>> linkage
>> C:/Programs/xerces-c-3.1.1/include/xercesc/util/KVStringPair.hpp:192:
>> warning: 'void xercesc_3_1::KVStringPair::setValue (const XMLCh*,
>> XMLSize_t)' defined locally after being referenced with dllimport
>> linkage
>>
>>
>> 4) Linking all of this (command line and errors):
>>
>> g++ -shared -o lib/libxsd.dll -LC:/Programs/xerces-c-3.1.1/lib
>> -lxerces-c_3 \
>> build/xsd/channelListType.o build/xsd/dataEl ementType.o \
>> build/xsd/dataSourceType.o
>> . . . .
>>
>> build/xsd/channelListType.o:channelListType.cpp:(.text$_ZN3xsd3cxx3xml3dom5clearIcEEvRN11xercesc_3_110DOMElementE[void
>> x sd::cxx::xml::dom::clear<char>(xercesc_3_1::DOMElement&)]+0x1a2):
>> undefined reference to `__imp___ZN11xercesc_3_16XMLUni
>> 14fgXMLNSURINameE'
>>
>> build/xsd/channelListType.o:channelListType.cpp:(.text$_ZN3xsd3cxx3xml3dom5clearIcEEvRN11xercesc_3_110DOMElementE[void
>> x sd::cxx::xml::dom::clear<char>(xercesc_3_1::DOMElement&)]+0x1bf):
>> undefined reference to `__imp___ZN11xercesc_3_113Schem
>> aSymbols9fgURI_XSIE'
>>
>> build/xsd/channelListType.o:channelListType.cpp:(.text$_ZN3xsd3cxx3xml3dom5clearIcEEvRN11xercesc_3_110DOMElementE[void
>> x sd::cxx::xml::dom::clear<char>(xercesc_3_1::DOMElement&)]+0x1f6):
>> undefined reference to `__imp___ZN11xercesc_3_113Schem
>> aSymbols21fgXSI_SCHEMALOCACTIONE'
>>
>> . . . .
>>
>> Is this a 32-bit vs. 64 bit issue?
>>
>> Thanks for you help.
>> r
>>
>
> Please note I get the exact same errors if I try to build n compile
> the examples, as well. Here's the 'make' line I use (in a Cygwin
> shell). This command is suggested in the README-CYGWIN.txt file in
> the distribution.
>
> $ make CPPFLAGS="-Ic:/Programs/xerces-c-3.1.1/include"
> LDFLAGS="-Lc:/programs/xerces-c-3.1.1/lib"
>
> I know it looks like I'm not specifying the Xerces library correctly,
> however, if I mistype, for example, the location of the Xerces
> library, I get the following error:
>
>
> $ make CPPFLAGS="-Ic:/Programs/xerces-c-3.1.1/include"
> LDFLAGS="-Lc:/xxxxx/xerces-c-3.1.1/lib"
> g++ -W -Wall -O3 -Lc:/xxxxx/xerces-c-3.1.1/lib -o driver driver.o
> hello.o -lxerces-c_3
> /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld:
> cannot find -lxerces-c_3
> collect2: ld returned 1 exit status
> make: *** [driver] Error 1
>
> Ideas?
>
I think I have this licked..... Pardon for the long post....
I needed to download and build the Xerces-c library. As per the
documentation,
I built the package as follows:
% ./configure LDFLAGS=-no-undefined
% make
This produced the following files:
cygxerces-c-3-1.dll
libxerces-c.a
libxerces-c.dll.a
libxerces-c.la
libxerces-c.lai
stricmp.o
strnicmp.o
Note the 'cygxerces-c-3-1.dll'. We'll use that later....
Then, back in the XSD/examples directory, I linked the 'hello' tree
example as follows
(and got the following warning messages):
$ g++ -W -Wall -O3 -Lc:/programs/xerces-c-3.1.1-src/lib -o driver
driver.o hello.o -lxerces-c
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld:
warning: auto-importing has been activated without --enable-auto-import
specified on the command line.
This should work unless it involves constant data structures
referencing symbols from auto-imported DLLs.Info: resolving
xercesc_3_1::XMLPlatformUtils::fgMemoryManager by linking to
__imp___ZN11xercesc_3_116XMLPlatformUtils15fgMemory ManagerE (auto-import)
Info: resolving xercesc_3_1::XMLUni::fgDOMComments by linking to
__imp___ZN11xercesc_3_16XMLUni13fgDOMCommentsE (auto-import)
. . .
This produced an executable with dynamic references to the
'libxerces-c.dll' file in the
Xerces-c/lib directory I just built. The test driver worked fine. (PATH
env variable must
include Xerces-c/lib directory.).
To get rid of the warning messages, I linked the example as follows:
$ g++ -W -Wall -Wl,--enable-auto-import -O3
-Lc:/programs/xerces-c-3.1.1-src/lib \
-o driver driver.o hello.o -lxerces-c
Are we done? No!
Turns out the 'hello' example is a bit, er, light on XSD usage. When I
tried building my
program with this library, I received the following error messages.
Note I create a DLL
containing all of my XSD source stuff:
$ g++ -Wl,--enable-auto-import -shared -o lib/libxsd.dll
-LC:/Programs/xerces-c-3.1.1-src/lib -lxerces-c build/xsd/dataSourceType.o
build/xsd/dataSourceType.o:dataSourceType.cpp:(.text$_ZN3xsd3cxx3xml3dom5clearIcEEvRN11xercesc_3_110DOMElementE[void
xsd::cxx::xml::dom::clear<char>(xercesc_3_1::DOMElement&)]+0x1a5):
undefined reference to `xercesc_3_1::XMLUni::fgXMLNSURIName'
build/xsd/dataSourceType.o:dataSourceType.cpp:(.text$_ZN3xsd3cxx3xml3dom5clearIcEEvRN11xercesc_3_110DOMElementE[void
xsd::cxx::xml::dom::clear<char>(xercesc_3_1::DOMElement&)]+0x1c1):
undefined reference to `xercesc_3_1::SchemaSymbols::fgURI_XSI'
. . . .
Here's where that 'cygxerces-c-3-1-1.dll' comes in..... If I use that,
I get the following:
$ g++ -Wl,--enable-auto-import -shared -o lib/libxsd.dll \
-LC:/Programs/xerces-c-3.1.1-src/lib -lxerces-c-3-1
build/xsd/dataSourceType.o
$
No error or warning messages!
I didn't use any of that '#define XSD_SYMBOL_DECL __declspec(dllexport)' or
'#define XSD_SYMBOL_DECL __declspec(dllimport)' either....
I believe this will work. Unfortunately, the project that includes XSD
includes
references to other 3rd party libraries and I'm now spending time
getting my
environment set up with those.
If I still have problems I'll re-visit this thread and post updates.
More information about the xsd-users
mailing list