Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was finally able to solve this problem with lots of trial and error and internet searches in and out of StackOverflow. At least the linker errors are gone, don't know what other things may pop up, but it's a good sign.<br> I will try to document as much as possible below:</p> <h2>Question in other words:</h2> <p>How to link 2 dlls under the same project with one being <code>/clr</code> and other non <code>clr</code>?</p> <h2>Actual Problem in Brief:</h2> <ul> <li>Everything is working fine, until a requirement comes where in one of the solutions, I have to make a call to the C# module.</li> <li>In order to make a call to C# code (or managed code), the project has to be a <code>/clr</code> project</li> <li>A project can be <code>/clr</code>, if it contains all .cpp code and no .c code</li> <li>In my case the main project in the solution was containing .c files; If I try to compile it with .cpp option then it will give lot of errors and I can't change that file for legacy reasons</li> <li>So the best option is to create a new project with .h and .cpp files which would contain the interface method and its implementation (which calls C# or C++/CLI) respectively</li> </ul> <p>So far it's good, but the problem comes when the new project (P2) function definition is not linked with the original project (P1). It gives various linker errors.</p> <h2>Solution:</h2> <p>The steps are with VC++2010 for novice users (like me).</p> <p><strong>Configuring P1</strong>: </p> <ul> <li>Right click the Solution S and <code>Add -&gt; New Project -&gt; Other languages -&gt; VC++ -&gt; CLR empty project</code> and name it (say P2) ;Add the header file and .cpp file in appropriate sections of the project</li> <li>This automatically sets the <code>Properties -&gt; Configuration Properties -&gt; C/C++ -&gt; Code Generation -&gt; Runtime Library to Multi threaded DLL: /MD[d]</code>; Which is essential</li> <li>For the original project P1, add the appropriate include paths under <code>Properties -&gt; Configuration Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</code>; So that you can include the new header file of P2 anywhere in the P1's source files</li> <li>Again for project P1, go to <code>Properties -&gt; Common Properties -&gt; Framework and Reference -&gt; Add New Reference</code> and you should be able to see the P2 there; Just add it</li> </ul> <p><strong>Configuring P2</strong>: </p> <ul> <li>The 1st step is optional as the build goes successful even without that, but I am documenting; <code>Properties -&gt; Common Properties -&gt; Framework and References -&gt; Add New Reference -&gt; &lt;Select the C# or whatever external DLL you would want to call from P2&gt;</code></li> <li>For new project P2, set the configuration as <code>DLL</code> under <code>Properties -&gt; Configuration Properties -&gt; General -&gt; Project Defaults -&gt; Configuration Type -&gt; Dynamic Library (DLL)</code></li> <li>If it makes sense for the project P2, In the same page you should set the <code>Output Directory</code> and <code>Intermediate Directory</code> also in sync (not exactly same) with that of P1</li> <li>Again for project P2 go to <code>Properties -&gt; Configuration Properties -&gt; Linker -&gt; General -&gt; Ignore Import Library -&gt; No</code>; I did this because it's like that in P1 as well</li> <li>Now the most important part: Whatever classes you have added inside the new header files of P2, we need to mention <code>__declspec(dllexport)</code> (or <code>__declspec(dllimport)</code>, not sure but both works); I got this crucial info from <a href="https://stackoverflow.com/questions/1201959/how-do-i-reference-one-vc-project-from-another-in-the-same-project">this question</a> and <a href="https://stackoverflow.com/questions/8863193/what-does-declspecdllimport-really-mean">this question</a></li> </ul> <p>And with above steps the build was successful!<br> Probably there could be things which are missed, and due to that I face some runtime issues. However at least I was able to link 2 DLL projects under the same solution which are with and without <code>/clr</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload