[Top][All Lists]

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

Re: [PATCH] tests: import variables for MSVC.

From: Peter Rosin
Subject: Re: [PATCH] tests: import variables for MSVC.
Date: Fri, 24 Sep 2010 20:46:14 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20100802 Thunderbird/3.1.2

Den 2010-09-24 19:30 skrev Charles Wilson:
> On 9/23/2010 6:25 PM, Peter Rosin wrote:
>> I don't know how to set up the defines so that EXTERN becomes
>> 1. "extern" when you use a static library
>> 2. "extern" when you build a static library
>> 3. "extern declspec(dllimport)" when you use a shared library
>> 4. "extern declspec(dllexport)" when you build a shared library
>> I could fix 2 and 4, but separating 1 and 3 is not possible. Since
>> extern declspec(dllimport) works everywhere with MSVC I'm taking the
>> easy option with this patch.
>> Or should I add -DBUILDING_FOO to and variations of the below
>> to the code?
> That is the typical approach.  The drawback -- usually an acceptable one
> -- is that if you are building a "stack" of dependent DLLs:
> EXE --> C.DLL -> B.DLL
>     --> A.DLL
> Then (a) you must link exe using .obj's compiled as pic (e.g. with
> -DDLL_EXPORT, even tho the EXE *itself* is not a "shared library").
> libtool does this by default IIRC.  (b) You MUST link EXE against shared
> C.DLL and shared A.DLL; you can't link against static C.lib and B.lib,
> but dynamic A.DLL, or vice versa (because DLL_EXPORT, for EXE's objs,
> either IS, or IS NOT, defined).

Now I'm also confused.

/me double checks (see below)

WHAT? It doesn't work as I stated!?!

*ponders that for a bit*
*scratches head*

Ahh, you said "libtool does this by default IIRC". If that's actually the
case than that is what has have me fooled for years.

*deep sigh*

Thanks for setting me straight.

What now?  Is the patch still good?  (with a reworded changelog of course)

*thinks again*

But now I'm really confused.  What made the original patch work?  It had
"#define EXTERN extern __declspec(dllimport)" unconditionally for MSVC.
And that patch also had two SKIPs and one FAIL (libfoo.a vs. foo.lib).
I.e. the exact same result, which means I can't be completely wrong.  Or
is the testsuite not doing any static builds?  But that seems highly
unlikely indeed.  WTF?


$ echo "extern __declspec(dllexport) int variable; int variable = 0;" > dllfoo.c
$ cl -nologo -Fefoo.dll -MD dllfoo.c -link -dll -export:variable 
   Creating library foo.dll.lib and object foo.dll.exp
$ echo "extern __declspec(dllimport) int variable; int main(void) { return 
variable; }" > bar.c
$ cl -nologo -Febar.exe -MD bar.c foo.dll.lib
$ ./bar
$ echo $?
$ echo "extern int variable; int variable = 0;" > libfoo.c
$ cl -nologo -c -MD libfoo.c
$ lib -nologo -out:foo.lib libfoo.obj
$ cl -nologo -Febar.exe -MD bar.c foo.lib
bar.obj : error LNK2019: unresolved external symbol __imp__variable referenced 
in function _main
bar.exe : fatal error LNK1120: 1 unresolved externals

reply via email to

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