Auto-linking when using Visual Studio compiler

Issue #76 resolved
Thomas Moeller created an issue

How about adding auto-linking support into Coin for Visual Studio projects? As the Windows binaries carry the major version name in the target it is a bit cumbersome to update projects from one version to the other. For other platforms symbolic links in the file system are used to point to the default (latest) version of the library without having to change all project settings or makefiles.

I saw the auto-linking mechanism being used in the Inventor libraries from both Mevis and VSG. In my opinion it would also benefit users of the Coin library to set defaults for compiler options and use auto-linking.

Below is a proposal what we could add to C/basic.h before the “Precaution” comment block.

/* For Visual Studio compiler use COIN_DLL by default and auto-linking. */
#if !defined(COIN_INTERNAL) && defined(_MSC_VER)
# if !defined(COIN_NOT_DLL) && !defined(COIN_DLL)
#  define COIN_DLL
# endif
# define COIN_STRINGIFY(str) SO__QUOTE(str)
# ifdef COIN_DLL
#  ifdef _DEBUG
#   pragma comment(lib, "Coin" COIN_STRINGIFY(COIN_MAJOR_VERSION) "d.lib")
#  else
#   pragma comment(lib, "Coin" COIN_STRINGIFY(COIN_MAJOR_VERSION) ".lib")
#  endif
# else
#  ifdef _DEBUG
#   pragma comment(lib, "Coin" COIN_STRINGIFY(COIN_MAJOR_VERSION) "sd.lib")
#  else
#   pragma comment(lib, "Coin" COIN_STRINGIFY(COIN_MAJOR_VERSION) "s.lib")
#  endif
# endif
# undef COIN_STRINGIFY
#endif


/* Precaution to avoid an some errors easily made by the application
   programmer. */

This block would default to COIN_DLL if neither COIN_DLL nor COIN_NOT_DLL have been defined and then pick the correct library names to be linked.

Comments (5)

  1. Roy Walmsley

    Thomas,

    Well... no comments from anyone else!

    I have had a quick look at this and in principle I think it is a good idea. However, I think we might want to discuss a few issues. For example, where does the "config.h" file fit in? This file is included in lots of places. One example is "win32.cpp", line 40. Also there is an earlier section in the file "basic.h" which covers the coin versioning.

    Perhaps this is something we can talk about. I will send you a private e-mail to see if we can set something up.

    Roy

  2. Log in to comment