[CMake] Making and using static and shared libraries on Windows with Visual Studio

Guillaume Dumont dumont.guillaume at gmail.com
Thu Jul 30 09:43:50 EDT 2015


Roger,

Did you try to remove all the explicit template exports? I never had to do
it and compiled many static and shared libraries on Windows. Of course VS
is going to complain about exporting template classes but as long as you
don't try to mix VS versions I think you can safely ingore those warnings.

Also, this block of code in a.h, b.h, etc.:

#ifndef A_H
#define A_H

#include <string>
#include "aexport.h"

#ifdef a_BUILT_AS_STATIC
#  define a_EXPORT_TEMPLATE
#else
#  ifndef a_EXPORT_TEMPLATE
#    ifdef a_EXPORTS
        /* We are building this library */
#      define a_EXPORT_TEMPLATE
#    else
        /* We are using this library */
#      define a_EXPORT_TEMPLATE extern
#    endif
#  endif

#  ifndef A_NO_EXPORT
#    define A_NO_EXPORT
#  endif
#endif

#ifdef _MSC_VER
// Explicit template exports.
#include <string>
a_EXPORT_TEMPLATE template class a_EXPORT std::allocator<char>;
a_EXPORT_TEMPLATE template struct a_EXPORT std::char_traits<char>;
a_EXPORT_TEMPLATE template class a_EXPORT std::basic_string<char,
std::char_traits<char>, std::allocator<char> >;
#endif

class a_EXPORT a
{
  std::string val;

 public:
  a();

  std::string const&
  getval() const;
};

#endif // A_H


seems redundant. I would remove it. Including aexport.h should be enough.

Hope this helps.

Guillaume

On Thu, Jul 30, 2015 at 8:45 AM, Roger Leigh <rleigh at codelibre.net> wrote:

> ibraries which





-- 
Guillaume Dumont
=========================
dumont.guillaume at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150730/ddbc4ed2/attachment.html>


More information about the CMake mailing list