29 July 2017, 00:56 | #1 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
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/ ULIB = /SDK/lib/ CFLAGS = cpu=68020 math=68881 nostkchk idir=$(UINC) idir=cxxinclude blink.p: blink.o sc link $(CFLAGS) startup=$(ULIB)serv_s.o $(ULIB)server.lib \ blink.o pname=$@ blink.o: sc $(CFLAGS) blink.cc all : blink.p can anyone explain what is wrong with extern "C" blocks ? Last edited by emufan; 01 August 2017 at 17:42. |
29 July 2017, 01:25 | #2 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,053
|
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) { // actual implementation } extern "C" { LWInstance create(LWError *error) { return create_impl(error); } ... } // extern "C" Last edited by a/b; 29 July 2017 at 01:35. |
29 July 2017, 01:58 | #3 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
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" TO "blink.p" LIB /SDK/lib/server.lib LIB:scm881.lib LIB:sc.lib LIB:amiga.lib i attached the source + includes + lw linker libs, if anyone wants try local.. |
29 July 2017, 10:08 | #4 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 720
|
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) |
29 July 2017, 15:46 | #5 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
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 ... GNU CPP version 2.95.3 20010315 (release) (68k, MIT syntax) #include "..." search starts here: #include <...> search starts here: include /opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/include/g++ /opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/include /opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../include /opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/include/../ndk/include /opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/../../../../m68k-amigaos/sys-include End of search list. The following default directories have been omitted from the search path: End of omitted list. /opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/cc1plus /tmp/ccMt00Up.ii -quiet -dumpbase blink.cc -m68020 -m68881 -version -o /tmp/ccV4uK2j.s GNU C++ version 2.95.3 20010315 (release) (m68k-amigaos) compiled by GNU C version 5.4.0. blink.cc: In function `unsigned int flags(void *)': blink.cc:285: warning: converting NULL to non-pointer type /opt/m68k-amigaos/m68k-amigaos/bin/as -mc68020 -o /tmp/ccS3uxt5.o /tmp/ccV4uK2j.s /opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/collect2 -fl libm020 -fl libm881 -L/opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3/libm020 -L/opt/m68k-amigaos/lib/gcc-lib/m68k-amigaos/2.95.3 -L/opt/m68k-amigaos/m68k-amigaos/lib/libm020 -L/opt/m68k-amigaos/m68k-amigaos/lib /tmp/ccS3uxt5.o -lstdc++ -lm -lgcc /opt/m68k-amigaos/m68k-amigaos/bin/ld: cannot open -lm: No such file or directory collect2: ld returned 1 exit status #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. Last edited by emufan; 29 July 2017 at 20:34. |
29 July 2017, 19:30 | #6 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
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 { public: BLINKER() : frame(0), period(30), fPer1(100), fPer2(0), uChannel(LUMINOUS) {} LWFrame frame; unsigned int period; unsigned short int uChannel; float fPer1, fPer2; private: }; Code:
LWFrame frame = 0; unsigned int period = 30; unsigned short int uChannel = 100; float fPer1 = 100; float fPer2 = 0; typedef struct BLINKER_TAG{ LWFrame frame, period, fPer1, fPer2, uChannel; }BLINKER; Last edited by emufan; 29 July 2017 at 20:30. |
29 July 2017, 20:39 | #7 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 720
|
not really, you have all the members in BLINKER typedef being of type LWFrame.
should be more like Code:
typedef struct BLINKER_TAG{ LWFrame frame; unsigned int period; unsigned short int uChannel; float fPer1; float fPer2; }BLINKER; |
29 July 2017, 21:51 | #8 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
ah, thank you, the comma fault.
but it does compile, w/o error/warning, strange. result is the same, must be something else |
29 July 2017, 22:25 | #9 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 720
|
Please attach c source code.
|
29 July 2017, 23:02 | #10 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
is attached in initial post - it's the original c++ source.
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 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. Last edited by emufan; 29 July 2017 at 23:14. |
29 July 2017, 23:45 | #11 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 720
|
initial post has the c++ code and not the c code. Unless, I am overseeing something.
|
30 July 2017, 00:29 | #12 | |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
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. Last edited by emufan; 01 August 2017 at 17:42. |
|
30 July 2017, 01:28 | #13 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 720
|
Any chance this works?
Last edited by alkis; 30 July 2017 at 01:36. |
30 July 2017, 02:31 | #14 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
oh, yes
i have to figure out, what it is really about, but it seems working thanks alot #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. Last edited by emufan; 05 September 2017 at 20:45. |
01 August 2017, 17:47 | #15 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
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. Last edited by emufan; 02 August 2017 at 19:05. |
02 August 2017, 15:32 | #16 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
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 { public: LWPanelFuncs *panel; LWPanelID panelid; STATIMAGE *user; private: }; ... callback *udata = new callback; Code:
typedef struct callback_TAG { LWPanelFuncs *panel; LWPanelID panelid; STATIMAGE *user; }callback; ... callback *udata; |
03 August 2017, 13:35 | #17 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
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); Last edited by Leffmann; 03 August 2017 at 13:55. |
03 August 2017, 14:12 | #18 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
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)"? |
03 August 2017, 15:39 | #19 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
there is an important part in the LW plugins, those save/load function.
original c++: Code:
VIDIMAGE *saveptr = (VIDIMAGE *)(inst); char saveline[64]; ostrstream ostr(saveline,64); for (int i=0; i<64; i++) saveline[i]='\0'; ostr << saveptr->spln << " "; ostr << saveptr->dirn << " "; ostr << saveptr->thickness << " "; ostr << saveptr->darken << " "; ostr << saveptr->brighten; // Now write the data into the file... lwss->write(lwss->writeData, saveline, 64); Code:
const char * const SPACE = " "; strcpy (saveline, saveptr->spln); strcpy (saveline, SPACE); strcpy (saveline, saveptr->dirn); strcpy (saveline, SPACE); strcpy (saveline, saveptr->thickness); strcpy (saveline, SPACE); strcpy (saveline, saveptr->darken); strcpy (saveline, SPACE); strcpy (saveline, saveptr->brighten); 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 EndPlugin Last edited by emufan; 03 August 2017 at 16:12. |
03 August 2017, 17:15 | #20 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 720
|
Well, from blinkc.c
Code:
//Load function. // XCALL_(LWError) load(LWInstance *inst, const LWLoadState *lwls) { BLINKER *defInst = (BLINKER*)(inst); BLINKER cData; lwls->read(lwls->readData, (char *)&cData, sizeof(BLINKER)); *defInst = cData; return (NULL); } //Save function. XCALL_(LWError) save(LWInstance *inst, const LWSaveState *lwss) { BLINKER *defInst = (BLINKER *)(inst); BLINKER cData; cData = *defInst; lwss->write(lwss->writeData, (char *)&cData, sizeof(BLINKER)); return (NULL); } |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
"Voices8" 8 Channel Soundtracker "DemoSongI" song - "This is the Amiga with 8 Voices" | DemosongIHunter | request.Music | 45 | 23 May 2022 20:07 |
"Screech!! v2.41" & "Screech!! [AGA] v2.51" - "HD install" --> "ADFs" | DamienD | request.Old Rare Games | 45 | 15 June 2020 12:42 |
"Reminder "Lincs Amiga User Group aka "LAG" Meet Sat 5th of January 2013" | rockape | News | 4 | 30 January 2013 00:06 |
CD32 Image-Name-Bug: "...(bla)[!].zip" -> "...(bla)[" / "...[test].zip" -> "...[tes" | cfTrio | support.WinUAE | 8 | 18 December 2012 16:31 |
Problems with "Thespywholovedme", "Flood", "Shinobi" | sareks | support.Games | 12 | 03 May 2006 14:52 |
|
|