* * *

Author Topic: Compiling a .dll  (Read 48092 times)

paul_H

  • New member
  • *
  • Posts: 13
Compiling a .dll
« on: March 12, 2006, 11:18:24 am »
I'm trying to compile a VST plugin (.dll) that I wrote using Delphi. Up to now, with various help in these pages (thanks), I managed to successfully compile, using essentially my original delphi code (with very minor changes). Great!

Except, my VST host doesn't recognize the .dll and reports 'dispatcher not found'.

I have a feeling that this may be related to the configuration of the project or compiler/linker (because all my units are compiled successfully without errors (some hints mind you)).

Also, when I start from a new Library project and simply compile, Lazarus produces a .exe file instead of a .dll. This seems counter intuitive. Does Lazarus, by default, always produce a .exe even when compiling a .dll?

Any insight into these matters will be appreciated.

There is a whole world of eager VST developers out there that would love to be able to develop in pascal and also be able to build for Linux and Mac (myself included).

mschnell

  • Full Member
  • ***
  • Posts: 131
    • http://www.lumino.de
Compiling a .dll
« Reply #1 on: March 13, 2006, 03:59:57 pm »
Sorry, I can't help with the problem :( .

Does your VST plugin done in Delphi actually work ?

I suppose your intention is to port it to Linux ?

What  VST host in Linux do you intend to use ?

-Michael

duncanparsons

  • Jr. Member
  • **
  • Posts: 83
Compiling a .dll
« Reply #2 on: March 13, 2006, 04:24:42 pm »
VST and Delphi go very well together.

I'm just embarking on doing a similar thing to Paul.. From what I can see the problem relates to how the cdecl directive is handled. Delphi makes code which works flawlessly - however FPC doesn't appear to. Searching the forae here suggests that this is not an isolated case.

The VST spec required cdecl, and all hosts will be expecting this. However, the function which VST dlls export takes one parameter, and returns a value indicating success. It may be that for FPC we might be able to get away with 'stdcall' or 'pascal', tho' I doubt it...

reading the other posts around (they are few and far between, I get the feeling that cdecl isn't used much...), it seems that this is a known issue, and one that the FPC devs haven't been eager to resolve, alas.

DSP

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2660
    • My Lazarus wiki user page
Compiling a .dll
« Reply #3 on: March 13, 2006, 04:55:01 pm »
Quote from: "duncanparsons"

reading the other posts around (they are few and far between, I get the feeling that cdecl isn't used much...), it seems that this is a known issue, and one that the FPC devs haven't been eager to resolve, alas.

DSP


What is the number of the fpc bug report describing this problem? I don't know if it has a simple test case, but if not, maybe you can create it.

paul_H

  • New member
  • *
  • Posts: 13
Compiling a .dll
« Reply #4 on: March 13, 2006, 05:37:56 pm »
Hi,

I think the problem has more to do with the way that Lazarus is creating .dlls than with the VST details.

I made a small test procedure. It consists of an application written in Lazarus called “test_dll.exe”. This application opens a window with two buttons. One button executes a procedure contained in a .dll written using Lazarus, and the other button executes a similar procedure contained in a .dll written in Delphi.

The code for both .dlls is essentially identical between Lazarus and Delphi. However, the Delphi .dll is successfully executed by the “test_dll.exe” and the Lazarus .dll causes an error.

I make the source code available for test routine and .dlls at this link.

Download DLL_Test.zip

Unizip to a temporary directory:

Under Lazarus open the “test_dll.lpi” project and compile.
Under Lazarus open the “mydll.lpi” project and compile.
Under Delphi open the “mydllD.dpr” project and compile.

Double click the “test_dll.exe” and try clicking the buttons.

The Lazarus compiled .dll does not work.

Maybe it's a config item - I don't know.

Complied using Lazarus 0.9.12 Beta.

duncanparsons

  • Jr. Member
  • **
  • Posts: 83
Compiling a .dll
« Reply #5 on: March 13, 2006, 07:11:46 pm »
Quote from: "Vincent"
Quote from: "duncanparsons"

reading the other posts around (they are few and far between, I get the feeling that cdecl isn't used much...), it seems that this is a known issue, and one that the FPC devs haven't been eager to resolve, alas.

DSP


What is the number of the fpc bug report describing this problem? I don't know if it has a simple test case, but if not, maybe you can create it.


I searched on the FPC and lazarus sites, and the most pertinent posts seemed to be:

1 which highlights the problem in athread about sockets;

2 which says it has a specific problem with cdecl,

and

3 relates to scintilla, but it relates pretty well here. I tried paul's test above, and when debugging got the SIGSEGV mentioned in theis post.


This one is targetting Linux; and there are a number of topic around which have problems with sqlitedb.

Pauls test is interesting, I tried using the standard register, stdcall, and cdecl.. the delphi dll worked each time, but the fpc one always gave the SIGSEGV.. I haven't tried loading the dll using delphi.. has seemed worth it yet. My feeling is that FP should be able to load it's own dlls..

HTH
DSP

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2660
    • My Lazarus wiki user page
Compiling a .dll
« Reply #6 on: March 13, 2006, 07:34:47 pm »
If you want this to be fixed you need to get the attention from the fpc developers. To get their attention, I would advice you do to one of the following:

    post a message to one their mailing lists, for example the
fpc-pascal list.

submit a bug report with a small test program at the fpc bug tracker.[/list]

paul_H

  • New member
  • *
  • Posts: 13
Compiling a .dll
« Reply #7 on: March 13, 2006, 10:53:21 pm »
In my example from above

Code: [Select]
library mydll;

{$mode objfpc}{$H+}

uses
  Classes,
  SysUtils,
  Windows;

procedure DllMessage; export;
begin
 MessageBox(0,PChar('Hello world from a Lazarus DLL'),PChar('Lazarus'),mb_ok)
end;

exports DllMessage;

begin
end.


WORKS!

Code: [Select]
library mydll;

{$mode objfpc}{$H+}

uses
  Classes,
  SysUtils,
  Dialogs;

procedure DllMessage; export;
begin
 ShowMessage('Hello world from a Lazarus DLL');
end;

exports DllMessage;

begin
end.


Doesn't work!

Some problem with the Dialogs unit in Lazarus?

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2660
    • My Lazarus wiki user page
Compiling a .dll
« Reply #8 on: March 13, 2006, 10:58:52 pm »
Dialogs is LCL. LCL needs to be initialized by using the interfaces unit and calling Application.Initialize.

I don't know if using the LCL in libraries will work, even if you intialized it properly.

paul_H

  • New member
  • *
  • Posts: 13
Compiling a .dll
« Reply #9 on: March 13, 2006, 11:08:47 pm »
Quote from: "Vincent"
Dialogs is LCL. LCL needs to be initialized by using the interfaces unit and calling Application.Initialize.

I don't know if using the LCL in libraries will work, even if you intialized it properly.


I should qualify my first statement a bit more "seems to be a problem with Dialogs when compiling .dlls". Dialogs works fine in an Application.

So, is this a free pascal issue or a Lazarus issue?
Can you suggest a work around?

paul_H

  • New member
  • *
  • Posts: 13
Compiling a .dll
« Reply #10 on: March 13, 2006, 11:21:52 pm »
Code: [Select]
library mydll;

{$mode objfpc}{$H+}

uses
  Interfaces,
  Classes,
  SysUtils,
  Dialogs;

procedure DllMessage; export;
begin
 ShowMessage('Hello world from a Lazarus DLL');
end;

exports DllMessage;

begin
end.  


i.e. adding the Interfaces, seems to work but then the buttons don't respond when I want to close the window.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2660
    • My Lazarus wiki user page
Compiling a .dll
« Reply #11 on: March 13, 2006, 11:23:06 pm »
You did not add Application.Initialize

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2660
    • My Lazarus wiki user page
Compiling a .dll
« Reply #12 on: March 13, 2006, 11:24:12 pm »
Quote from: "paul_H"

Can you suggest a work around?


Don't use the LCL in your dll, but I don't know if that is acceptable for you.

paul_H

  • New member
  • *
  • Posts: 13
Compiling a .dll
« Reply #13 on: March 13, 2006, 11:30:20 pm »
Quote from: "Vincent"
You did not add Application.Initialize


Where should I put it? I tried between begin and end, but it causes an error. "identifier not found".

P.S. Not using LCL is probably not acceptable in a VST plugin application.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2660
    • My Lazarus wiki user page
Compiling a .dll
« Reply #14 on: March 13, 2006, 11:36:50 pm »
Quote from: "paul_H"

Where should I put it?

I don't know, I never used the LCL in an DLL.
Quote
I tried between begin and end, but it causes an error. "identifier not found".

The application variable is in the forms unit.
Quote

P.S. Not using LCL is probably not acceptable in a VST plugin application.

What is a VST plugin?

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus