Inappropriate occurrence of error C4945 
Author Message
 Inappropriate occurrence of error C4945

I get warning C4945 when I compile a file that #includes
more than one header file which reference (#using) the
same assembly. It does NOT happen with all assemblies. For
instance, the following compiles without complaint:

=== myfile.cpp

#using <mscorlib.dll>
#using <mscorlib.dll> // duplicate reference
#using <mscorlib.dll> // ...and another

However, if I do the following:

=== myfile1.hpp

#using "myassembly.dll"

=== myfile2.hpp

#using "myassembly.dll"

=== myfile3.cpp

#include "myfile1.hpp"
#include "myfile2.hpp"

...and compile myfile3.cpp, I get error C4945, which says:

myfile2.hpp(67) : warning C4945: 'MyClass' : cannot import
symbol from 'D:\MyAssemblies\myassembly.dll':
as 'MyNamespace::MyClass' has already been imported from
another assembly 'D:\MyAssemblies\myassembly.dll'

Note that the error message is complaining about a
conflict between assemblies with the *same path*. This
makes no sense to me, and have no idea how to fix it.

Any ideas?

Thanks in advance,

--Bob



Sat, 15 Jan 2005 00:43:15 GMT  
 Inappropriate occurrence of error C4945
Hi,

Could you post the sample project and tell me the detailed steps to
reproduce the problem? I will be glad to check it on my side.

Thanks,
HuangTM
This posting is provided "AS IS" with no warranties, and confers no rights.



Sat, 15 Jan 2005 14:19:06 GMT  
 Inappropriate occurrence of error C4945

Quote:
> Could you post the sample project and tell me the detailed steps to
> reproduce the problem? I will be glad to check it on my side.

I had this same problem months ago.  These 2 files will reproduce it:

Foo.cpp
    #using <mscorlib.dll>
    #using <System.Drawing.dll>
    public __gc class Foo {
    public:
        void Think(System::Drawing::Point) {}
    };

Bar.cpp
    #using <mscorlib.dll>
    #using <Foo.dll>
    __gc class Bar {
        Foo *f
    };
    #using <System.Drawing.dll>
    __gc class Fooey : public Foo {
        void Thunk(System::Drawing::Point) {}
    };

C:\> cl /clr /LD Foo.cpp
C:\> cl /clr /LD Bar.cpp

The work-around is to move '#using <System.Drawing.dll>'
somewhere before the first reference to Foo.

-Sean



Sun, 16 Jan 2005 09:09:57 GMT  
 Inappropriate occurrence of error C4945
With a little more investigation, I've come to this conclusion:

If B references A.
And C references B.
Then C must also reference A.

If you don't follow this rule, you can get this C4945 error.

If this is a bug, then I hope they fix it.
If this is by design, then there should be a better error message.

-Sean


Quote:
> > Could you post the sample project and tell me the detailed steps to
> > reproduce the problem? I will be glad to check it on my side.

> I had this same problem months ago.  These 2 files will reproduce it:

> Foo.cpp
>     #using <mscorlib.dll>
>     #using <System.Drawing.dll>
>     public __gc class Foo {
>     public:
>         void Think(System::Drawing::Point) {}
>     };

> Bar.cpp
>     #using <mscorlib.dll>
>     #using <Foo.dll>
>     __gc class Bar {
>         Foo *f
>     };
>     #using <System.Drawing.dll>
>     __gc class Fooey : public Foo {
>         void Thunk(System::Drawing::Point) {}
>     };

> C:\> cl /clr /LD Foo.cpp
> C:\> cl /clr /LD Bar.cpp

> The work-around is to move '#using <System.Drawing.dll>'
> somewhere before the first reference to Foo.

> -Sean



Tue, 18 Jan 2005 09:51:01 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Inappropriate behavior towards possibly inappropriate email.

2. Apology for Inappropriate Posting of Query to Comp.Lang.C

3. Disregard this inappropriate posting

4. Postings to inappropriate newsgroups

5. Q: Fastest search for first occurrence?

6. strstr() - how can I get the n-th occurrence

7. strange occurrences...

8. Occurrences of characters in string

9. A perplexing occurrence

10. Strange occurrence with subclassing..

11. newbie:Occurrences of a substring in a string

12. Get the number of character occurrences in a string

 

 
Powered by phpBB® Forum Software