libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MSVC: Always dllimport the variable for MSVC in link-order.at


From: Peter Rosin
Subject: MSVC: Always dllimport the variable for MSVC in link-order.at
Date: Sat, 10 Jul 2010 10:15:09 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.4) Gecko/20100608 Thunderbird/3.1

Hi!

Next in to MSVC queue...

This is a variation of
95bdbc456f7c5d6d669121cf20d62a9c28bec2bf
"Always dllimport the variable for MSVC in link-order.at"

Patch previously discussed here:
http://lists.gnu.org/archive/html/libtool-patches/2008-08/msg00053.html

In that discussion I claim that "With MSVC, you can declare any variable
with __decspec(dllimport), even if you are not actually importing it"
and I must have been thoroughly confused when I arrived at that
conclusion. It doesn't hold when I now try it...

So, instead of just "#ifdef _MSC_VER", this version does
#if defined _MSC_VER && defined PIC
#  define LIBCEE_SCOPE __declspec(dllimport)

Now, the PIC part isn't truly what we want to test for, since we don't
really want to dllimport when we a *building* a PIC library. We want
to dllimport when we *use* a shared library. But in this case it happens
to coincide, and the notion of using a shared vs. static library isn't
really covered by libtool, i.e. there's no -DUSE_PIC or equivalent that
can be used to discriminate in the code.

Cheers,
Peter

2010-07-10  Peter Rosin  <address@hidden>

       dllimport the variable for MSVC in link-order.at
       * tests/link-order.at [MSVC]: Makes the test pass by dllimporting
       imported variables when working with shared libraries.


diff --git a/tests/link-order.at b/tests/link-order.at
index 0122a45..c1b53a5 100644
--- a/tests/link-order.at
+++ b/tests/link-order.at
@@ -48,13 +48,31 @@ for i in old new; do
   mkdir src

   cat >src/a_$i.c <<EOF
-extern int c;
+/* w32 fun, MSVC needs to dllimport when using a shared library, so use
+ * PIC/non-PIC to discriminate as that happens to coinside in this case.
+ * gnu has auto import.
+ */
+#if defined _MSC_VER && defined PIC
+#  define LIBCEE_SCOPE __declspec(dllimport)
+#else
+#  define LIBCEE_SCOPE extern
+#endif
+LIBCEE_SCOPE int c;
 extern int b_$i();
 int a_$i() { return c + b_$i(); }
 EOF

   cat >src/b_$i.c <<EOF
-extern int c;
+/* w32 fun, MSVC needs to dllimport when using a shared library, so use
+ * PIC/non-PIC to discriminate as that happens to coinside in this case.
+ * gnu has auto import.
+ */
+#if defined _MSC_VER && defined PIC
+#  define LIBCEE_SCOPE __declspec(dllimport)
+#else
+#  define LIBCEE_SCOPE extern
+#endif
+LIBCEE_SCOPE int c;
 int b_$i() { return 1 + c; }
 EOF





reply via email to

[Prev in Thread] Current Thread [Next in Thread]