Log in

View Full Version : Problem compiling C-Plugin-Example with bcc32


AMSS0815
3rd September 2006, 11:52
Hi experts,

I'm doing my first steps in developing some plugins. I'd like to create them as C plugins since I don't have expensive compilers. I'm using bcc32 version 5.5.1.

As a first step I tried to compile the invert.c-example included in avisynth_c-0.15.zip (http://kevin.atkinson.dhs.org/avisynth_c/avisynth_c-0.15.zip).
The linker complained the format of the lib-file (avisynth_c.lib) is wrong, so I had to change the format with coff2omf.exe (Does anybody know what exactly that means??). After compiling invert.c with bcc32 -c invert.c and linking with ilink32 /Tpd invert.obj,invert.dll,,AviSynth_C_OMF.lib, and loading the plugin with
SetWorkingDir("C:\Temp\InvertTest")
LoadCPlugin("C:\Temp\InvertTest\invert.dll") into AviSynth 2.5.6a (by VirtualDub 1.6.15), it gives me a dialog box with Avisynth open failure: Unable to load C Plugin: C:\Temp\InvertTest\invert.dll (C:\Temp\InvertTest\Test.avs, line 2). Does anyone know what exactly that means?

I also tried the following variations:

Compiling with the option -u- to suppress the underscores in front of the function names
coff2omf seems to have 4 different modes, accessable via -lib:??. I tried all of them.
I added AviSynth_C.dll to the working directory.

I tried all possible combinations, with some the linker wouldn't link. All other yielded the same error box in VirtualDub.

Does anyone have any experiences in compiling C Plugins with bcc32? I couln't find anything about this here.

Thanks in advance for your help

AMSS(0815)

Fizick
4th September 2006, 19:49
you use STD call convention?

But in any case, advise: forget about C-plugins. Better use free MS VC Toolkit 2003 or VC9 express.

AMSS0815
5th September 2006, 12:21
Hi Fizick,

STD call convention? Good question - I'll try this in a few days (not at home right now).
As I didn't change the c-file, the init function declaration says
const char * avisynth_c_plugin_init(AVS_ScriptEnvironment * env),
all other functions have this AVSC_CC macro with their declaration. Maybe bcc uses its C-calling-convention instead of the STD call... ?

By the way: There are several reasons (for me) to use bcc:

BCC is much smaller than huge development environments.
I'm trying to be as much compatible as possible (ordinary C seems to be well understood by most programmers/scientists, and simple C compilers are available on almost every platform).
I only understand ANSI-C (and some Pascal). When I try to read the AviSynth-Code, I don't understand much.
The code for the plugins (which I already have in parts, but not wrapped for AviSynth) is in bcc-compileable C. (OK, this should also compile with any VC)
Hmm - I think I'm to lazy to start working with a new programming tool.

Maybe I'll switch to gcc in a few months. In spite of all this: Thank you for the advice. I might overcome my lazyness some day... :)

Thanks again for the advise - I'm looking forward to try this.

AMSS

Fizick
5th September 2006, 16:36
I used v0.14 only with C- calling convention and GNU CC and MS VCToolkit 2003.

AMSS0815
7th September 2006, 20:24
Hi Fizick,

as far as I could check, I'm using C calling convention when compiling (It seems to be the default for bcc32). Modifying the calling convention (with command line option -p*) always results in compiler error Type mismatch in redeclaration of 'avisynth_c_plugin_init'.

:thanks: Anyway - thanks for the advice.

Is there a way to exactly find out what goes wrong when AviSynth loads my C plugin?

AMSS

AMSS0815
9th September 2006, 17:46
Hi again,

now I combined three avisynth_c packages: avisynth_c-0.15.zip, avisynth_c-stdcall-def.zip, avisynth_c-stdcall.zip, which can be found here (http://kevin.atkinson.dhs.org/avisynth_c/). Depending on the compiler/linker options (and the coff2omf option), I get three different error messages:

Unable to load C Plugin: invert.dll
Not An Avisynth 2 C Plugin: invert.dll
Evaluate: System exception - Access Violation

Using the compiler switches -u- -pc, which suppress leading underscores and use C-calling-convention (which should be the right setting ..?) always results in the last error message.

Currently AviSynth_C.dll is contained in the working directory and I'm using this script:SetWorkingDir("C:\Temp\IT2")
LoadPlugin("avisynth_c.dll")
LoadCPlugin("invert.dll")
BlankClip
invertinplacewhich works nicely, when the original invert.dll from avisynth_c-0.15.zip is used.

How might I track down this strange error? I didn't change anything in invert.c.
Which AviSynth_C.dll/lib/h is the right one to use with AviSynth 2.5.6? I also found AviSynth_C.dll/h in the source files of AviSynth 2.5.6, but no .lib-file.

Thanks for your help in advance!

AMSS

Myrsloik
14th September 2006, 16:16
This is based on my own observations when making the pascal conversion of avisynth_c.h.

The avisynth_c.h file you should be using that's actually updated to match the latest avisynth is the one you get when you check out the entire avisynth source. Anything else is obsolete.

If your compiled plugins (or anyone else's) needs avisynth_c.dll they were compiled with an old version. This is not what you want as all stdcall functions have been included in avisynth.dll.

There is as far as I know no current .lib to use so you will have to make one yourself (you probably get it as a byproduct from compiling avisynth).

IanB
15th September 2006, 03:15
A more portable solution might be to use function pointers that you initialize in your avisynth_c_plugin_init routine.
const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment* env) {
...
HMODULE plugin = LoadLibrary("avisynth.dll");
...
F_avs_create_script_environment = (void)GetProcAddress(plugin, "avs_create_script_environment");
...Also maybe we could start including the avisynth.lib in the main distribution. Thorts people???

AMSS0815
18th September 2006, 21:01
Hi everyone,

it seems there is no chance to build the invert-plugin with bcc. :(
Now I'm trying gcc (with MinGW (http://www.mingw.org)). gcc builds the dll-file with avisynth_c.h and avisynth_c.lib which were included within the plugin, but I need to load avisynth_c.dll before I can load the plugin. After that it seems to work fine. :)
According to Myrsloik, I need the newest avisynth.lib (which I don't have).
IanB, sorry, I don't understand what you mean. What do I need F_avs_create_script_environment for ? :confused:
Anyway - thanks for your hints.

Out of curiosity, I also tried to compile the simplesample (1.7) with avisynth.h included in the 2.5.6-sources. Executing g++ SimpleSample.cpp -c gives :confused:

In file included from SimpleSample.cpp:38:
avisynth.h:257: error: integer constant is too large for "long" type
avisynth.h: In member function `BYTE* VideoFrame::GetWritePtr() const':
avisynth.h:383: error: `_ASSERT' undeclared (first use this function)
avisynth.h:383: error: (Each undeclared identifier is reported only once for each function it appears in.)
avisynth.h: In member function `BYTE* VideoFrame::GetWritePtr(int) const':
avisynth.h:392: error: `_ASSERT' undeclared (first use this function)

Is it possible to compile AviSynth-(not-c)-plugins with g++ ?

Thanks for your help in advance

AMSS
P.S. Can/shall I change the title of this thread to gcc/g++?

AMSS0815
21st September 2006, 22:44
Hi again,

Is it possible to compile AviSynth-(not-c)-plugins with g++ ?
Hmmm, it seems no.

Is the latest AviSynth_C.lib somewhere published? I'm still trying to avoid MS VC ++.

Will C-Plugins compiled with the latest h/lib-files load automatically when placed in the plugins folder (like non-c plugins do)?

Thanks for helping me in advance

AMSS