title: How to link a DLL in a Delphi package?
body: <p>I'm creating a Delphi package using OpenGL and the GLEW extension. I downloaded GLEW from the official website. That was a painful way to make it usable with Embarcadero, but I finally succeeded. At this point, I'm able to compile and use GLEW in any C++ Builder or Delphi application project.</p>
  
  <p>However, I experiment difficulties to use GLEW in my Delphi package. As GLEW is a DLL, I declare the external functions that I need as in the following example:</p>
  
  <pre><code>procedure glBindVertexArray(glArray: GLuint); external 'glew32.dll' name '__glewBindVertexArray';
  </code></pre>
  
  <p>This works well when I compile an application project, so I'm sure that the declaration is correct. I can compile and link my package without problems. However, when I try to use it in a demo project, I receive the following link error:</p>
  
  <pre><code>[ilink32 Error] Error: Unresolved external '__glewBindVertexArray' referenced from C:\USERS\PUBLIC\DOCUMENTS\EMBARCADERO\STUDIO\15.0\DCP\QRMODELS.LIB|TQRMD2_OpenGL
  </code></pre>
  
  <p>So my GLEW functions are not found by the linker. The problem is that I don't know how to link an external DLL into a Delphi package. When I try to add the DLL in the "Requires" section, my package can no more be compiled and I receive the following error:</p>
  
  <pre><code>[dcc32 Fatal Error] QRModels.dpk(35): E2202 Required package 'glew32' not found
  </code></pre>
  
  <p>I also tried to add glew32.lib in my package, and tried to link GLEW in my target project, but without success.</p>
  
  <p>So, what is the correct way to link an external standard DLL, that isn't a .dcp, in Embarcadero Delphi packages? I remember you that I can use this DLL without problems in any Delphi application project, and I own the corresponding .lib too, that is already converted to be used with Embarcadero compiler.</p>
  
  <p>Regards</p>
  
  <p><strong>NOTE</strong>: As suggested in the comment posted by David Heffernan, I tried to create a small package that includes an external function to the user32.dll. This worked well. I also tried to include one of my GLEW external function. Now the issue is different: the package links and builds well, and the target project too. But when the exe runs, I get an error message saying that glew32.dll is missing on my computer. So my issue is basically a bad installation of the GLEW library. However, all my other projects using GLEW works well, including those I create with other compilers, as e.g. Code::Blocks.</p>
  
  <p>I also compared my package options, and the only thing that is different is that the package I create is divided in 2 projects, one for the design time and one for the runtime. I already created such other packages without problems, but I never tried to include external DLL in them.</p>
  
  <p>Here is my test unit:</p>
  
  <pre><code>unit Unit1;
  
  interface
  
  uses OpenGL;
  
  function MessageBeep(uType: Cardinal): LongBool; stdcall; external 'user32';
  procedure glBindVertexArray(glArray: GLuint); stdcall; external 'glew32.dll' name '__glewBindVertexArray';
  
  type
      TTest = class(TObject)
          public
              procedure TestBeep; virtual;
              procedure TestGlew; virtual;
      end;
  
  implementation
  procedure TTest.TestBeep;
  begin
      MessageBeep($40);
  end;
  
  procedure TTest.TestGlew;
  begin
      glBindVertexArray(0);
  end;
  
  end.
  </code></pre>
  
  <p>Regards</p>