[xsd-users] Linker problem caused by using std::ifstream/std::ofstream/std::fstream together with xsd::cxx::tree::string

Krzynowek, Marek (CWM-NR) marek.krzynowek at rbccm.com
Fri Oct 1 07:43:57 EDT 2021


Hi,

>From Piotr Martynowicz who is helping me with the C++ side of the update:

In our solution we have a DLL project, and in that project we have a file, let's call it utils.cpp, which includes codesynthesis/base_xml_schema/base/xml_schema.hxx and defines a constructor of class X in which it creates an std::ifstream instance:
X::X(std::string& filePath)
{
  std::ifstream inFile;
  // read from file
}

xml_schema.hxx starts with a comment:
// Copyright (c) 2005-2014 Code Synthesis Tools CC
//
// This program was generated by CodeSynthesis XSD, an XML Schema to
// C++ data binding compiler.

and at the end it contains lines:
namespace xsd
{
  namespace cxx
  {
    namespace tree
    {
      template class XML_SCHEMA_API simple_type< char, ::xml_schema::Type >;
      template class XML_SCHEMA_API string< char, ::xml_schema::SimpleType >;
      template class XML_SCHEMA_API normalized_string< char, ::xml_schema::String >;
      template class XML_SCHEMA_API token< char, ::xml_schema::NormalizedString >;
      template class XML_SCHEMA_API name< char, ::xml_schema::Token >;
      template class XML_SCHEMA_API nmtoken< char, ::xml_schema::Token >;
      ...
    }
  }
}

This is where the quoted line came from. XML_SCHEMA_API is defined in codesynthesis/base_xml_schema/export.hxx:
#ifndef HAVE_XML_SCHEMA_EXPORT_HXX
#define HAVE_XML_SCHEMA_EXPORT_HXX

#ifdef _MSC_VER
   #if defined( BASE_XML_EXPORTS  )
      # define XML_SCHEMA_API __declspec(dllexport)
      // Magic trick to work around npos export VC bug.
      #if _MSC_VER >= 1600
         #ifdef _M_IX86
            #pragma comment(linker, "/include:_magic_magic_magic")
         #else
            #pragma comment(linker, "/include:magic_magic_magic")
         #endif // x86
      #endif
   #else
      # define XML_SCHEMA_API __declspec(dllimport)
   #endif // msc compiler
#else
    #define XML_SCHEMA_API    
#endif

#endif // HAVE_XML_SCHEMA_EXPORT_HXX

The linker issue arises when our utils.cpp includes xml_schema.hxx AND creates an instance of either std::ifstream or std::ofstream or std::fstream. More specifically, it looks like it has something to do with xsd::cxx::tree::string inheriting from std::basic_string.

I'm not sure but it looks like xml_schema.hxx is either your code or code generated by your software (as the comment suggests). But let us know if that's not the case.

The issue didn't appear in Visual Studio 16.6 but it appeared after updating to 16.11.3.

Best regards,
Marek


-----Original Message-----
From: Boris Kolpackov <boris at codesynthesis.com> 
Sent: 29 September 2021 15:49
To: Krzynowek, Marek (CWM-NR) <marek.krzynowek at rbccm.com>
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] Linker problem caused by using std::ifstream/std::ofstream/std::fstream together with xsd::cxx::tree::string

[External]<https://connect.fg.rbc.com/community/techhub/external-email-indicator>

Krzynowek, Marek (CWM-NR) <marek.krzynowek at rbccm.com> writes:

> template class __declspec(dllimport) xsd::cxx::tree::string<char, 
> SimpleType>;

Can you elaborate on how you end up with this situation in your project (I have my suspicions but it would be helpful to clarify this).
______________________________________________________________________ This email is intended only for the use of the individual(s) to whom it is addressed and may be privileged and confidential. Unauthorised use or disclosure is prohibited. If you receive this e-mail in error, please advise immediately and delete the original message. This message may have been altered without your or our knowledge and the sender does not accept any liability for any errors or omissions in the message. Emails are monitored by supervisory personnel in jurisdictions where monitoring is permitted. Such communications are retained and may be produced to regulatory authorities or others with legal rights to the information. Please see link for RBCCM disclosures. https://www.rbccm.com/rbccm/policies-disclaimers.page




More information about the xsd-users mailing list