Friday, July 17, 2009

Visual C++ 'per-appdomain symbol error' and Compiler Warning C4394

I've been trying to debug my telephony test application the past week to no avail. I asked Aculab for technical support and their engineer asked me to enable the built-in trace capability of their library. When I enabled it, I got all sorts of Compiler Warning C4394:

per-appdomain symbol should not be marked with __declspec(dllimport)
Visual Studio also refuse to link the application citing those cryptic unresolvable externals on the trace variable and function. Doing a Google search on the strange error revealed that there are other people who have experienced the same problem. The error does not seem to appear if the application is a console app (such as the demo SimpleCall that came with Aculab's SDK). But the moment you switch to a graphical CLI/.NET environment, it appears.

According to MSDN, the C4394 is related to variables or functions written and compiled using native C/C++. When they are linked to a program compiled in Microsoft's Intermediate Language (MSIL) format running in a .NET managed environment (CLI), the incompatibility in permission access level appears.

Somone suggested in the forum from the other guy who reported the same problem to switch from a "pure" CLR environment to a normal one. This can be achieved by changing the compiler flag from /clr:pure to just /clr. From the Visual Studio IDE, one goes to Project >> Properties >> Configuration Properties and change the Common Language Runtime support dropdown value to regular /clr instead of the default "Pure".

And what do you know? It worked! The compiler and linker errors disappeared and I was able to generate by trace logs. So its now back to trying and figure out what is wrong with my demo program. :(

No comments: