SAS/C and extern "C"
i made some progress with the LW plugins, but I cannot convert some c++ function to c.
so the problem with original c++ source: SAS/C compiles the code only, if I remove the extern "C" blocks - resulting binary is not working with LW. if i compile with the extern "C" blocks it give some overloaded function errors. smakefile, i'm using: Code:
UINC = /SDK/include/ can anyone explain what is wrong with extern "C" blocks ? |
First you declare them as c functions (lines 18-36). Then you implement them as c++ functions (lines 80+).
Did you try to put the entire implementation, lines 80-285, inside extern "C"? EDIT: OK, I'm checking those functions. They actually are in c++. You will probably need c wrappers that call c++ counterparts. Something like: Code:
LWInstance create_impl(LWError *error) |
thanks for your help :)
these plugins were written in 96/97 - C++98 was not yet the standard, i guess. and i did not wrote the code, i just found the old sources :) I made the "lines 80-285" block, but i get the same overloaded error. i'm not sure about the wrapper or how to write the "actual implementation" code. but it's rather strange, sasc does build the binary, if the extern "C" is removed, so i thought it is possble to fix this issue first. the blink.lnk file: Code:
FROM /SDK/lib/serv_s.o "blink.o" i attached the source + includes + lw linker libs, if anyone wants try local.. |
extern "C" is usefull when you want to link functions defined in a cpp module with C (or asm or whatever) code.
This code doesn't get linked in such a way. (If it was, you'd get linker errors in linking) By that logic, you don't need extern "C". As you said, sasc compiles and links the code if you remove extern "C". But you don't get a working plugin. Your last chance is wrapping the return type of each function with the XCALL_() macro i.e int foo(whatever) turns into XCALL_(int) foo(whatever) |
1 Attachment(s)
so SASC is not the appropriate compiler for the (given) c++ code.
I went back to gxx 2.95.3, on the cygwin32 system ( crosscompiler). the only error i get is the missing "-lm" while linking. verbose output w/o definition part: Code:
$ m68k-amigaos-g++.exe -Iinclude blink.cc #2) XCALL_ macro: so i should wrap any variable in the original extern "C" block with this macro? #3) good progress with SASC and converting to C. initial values seems wrong, so there are still some bugs, but the plugin panel opens for the first time. i can change values and rendering with the active plugin does not crash LW. #4) if i get it right, this plugin is a big thing, since it makes it possible to animate different values over time, which is not possible for Surface parameters in LW5. |
so now I will verify my C++ to C conversation:
LUMINOUS i gave random value of 100, it is member of an enum, maybe it should be 0 or 1: Code:
enum CHANNELS { LUMINOUS, DIFFUSE, SPECULAR, MIRROR, TRANSP }; Code:
class BLINKER Code:
LWFrame frame = 0; |
not really, you have all the members in BLINKER typedef being of type LWFrame.
should be more like Code:
typedef struct BLINKER_TAG{ |
ah, thank you, the comma fault.
but it does compile, w/o error/warning, strange. result is the same, must be something else :) |
Please attach c source code.
|
1 Attachment(s)
Quote:
i also made some good progress with goo, also converted to C, disabled those c++ functions I dont understand. for now it starts in LW and option panel is working :D problem is for sure some pointer, things i dont understand: * value , (value), *(value) and those things. the initial values in the source are simply wrong, in the option panel of the plugins. |
initial post has the c++ code and not the c code. Unless, I am overseeing something.
|
Quote:
i made for sure some mistakes with definitions and stuff, so compare it with the original. fresnel.c is of good use too, so you can compare how they made some calls and definitions. |
1 Attachment(s)
Any chance this works?
|
Quote:
i have to figure out, what it is really about, but it seems working :) thanks alot :great #1) while we are at it, attached is the goo source. my WIP and the original. if you still have some minutes :) #2) original had a header file, but i'm not sure if it's really needed. #3) one thing does not work. if you setup a scene with a plugin and save the scene, you should have an entry in the scene file, with the plugin descsription and values set. this does not work. i'm not sure which of the API functions do this. i'll have a look and compare with some other working plugins. #4) i included LWGlobals.hh in goo-WIP.c, but there are some undeclared things i dont understand. |
I have another plugin: RGBshift. almost done using the working blink source :)
i can build and use it, but initial values are wrong again. it does not work when applied to a scene. original and my WIP attached. #1) fixed. just one XCALL_ was missing. :) |
i've converted a class to typedef struct.
the class is called at one occasion, so i'm not sure, how it has to be initialized in C: C++ original: Code:
class callback Code:
typedef struct callback_TAG |
If there's nothing more to that class then you can just do
callback *udata = malloc(sizeof (callback));, and for delete callback;you do free(callback);. EDIT: it should be delete udata;and free(udata); |
thanks, but this doesnt change the problem here.
there is an info panel, with some sub panels, callback is used to have a "callback", for safe return from sub to main panel. but lw crashs when i press "ok" or "cancel" on the sub panel. i thought is is due to bad forming of the callback structure. but i guess it is something else, i didnt find yet. btw. does it matter,if i'm using "(sizeof (callback)" or "(sizeof (callback_TAG)"? |
there is an important part in the LW plugins, those save/load function.
original c++: Code:
VIDIMAGE *saveptr = (VIDIMAGE *)(inst); Code:
const char * const SPACE = " "; it does build, but does not accomplish the same. next is from lw scene file, there should be some values in the blank line. Code:
Plugin ImageFilterHandler 1 T42_Vidlines |
Well, from blinkc.c
Code:
//Load function. |
All times are GMT +2. The time now is 08:41. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.