This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Module in C++

Discussion of Eggdrop's code and module programming in C.
Post Reply
K
Kappa007
Voice
Posts: 38
Joined: Tue Jul 26, 2005 9:53 pm

Module in C++

Post by Kappa007 »

Hey all,
i was wondering if it is possible to do a module in C++ not in C (i suspect it is - i found one on the web but it's kinda odd :x)
I'm getting wicked errors when i try to compile my module in C++....
Like dprintf() having too many arguments etc. I suspect it's the scary module.h who is causing that ;)

Anyone got experience with that?
Any template/tutorial/help?


Thanks in advance ;)
K
Kappa007
Voice
Posts: 38
Joined: Tue Jul 26, 2005 9:53 pm

Post by Kappa007 »

#undef dprintf
extern "C" void dprintf(int idx, const char * text, ...);
After the modules include seems to fix it :D
But guess i'd have to do that for all functions :/

Is that the correct work-around at all or is there some better way?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

extern "C" {
// your C function prototypes here
}
K
Kappa007
Voice
Posts: 38
Joined: Tue Jul 26, 2005 9:53 pm

Post by Kappa007 »

Yeah. Just that i'll have to undecorate the stuff from module.h or something :x
Anyway if that is the recommended way no problem :-)
K
Kappa007
Voice
Posts: 38
Joined: Tue Jul 26, 2005 9:53 pm

Post by Kappa007 »

Actually that only helped at first glance
undefined reference to `dprintf(int, char const*, ...)'
Now i get that error while trying to link :(

If I put a extern "C" around the C include stuff I get "undefined reference to `_dprintf'"
Adding modules.o to the linking process gives me a whole list of undefined references :(

Help pls anyone ;)
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

post the exact error log (using

Code: Select all

 tag, not [quote]) and RTFM (doc/MODULES)
K
Kappa007
Voice
Posts: 38
Joined: Tue Jul 26, 2005 9:53 pm

Post by Kappa007 »

The doc does not say anything about C++ ;)

And that already was the exact error:

Code: Select all

g++ -o ../../../mymod.dll ../mymod.o -L/usr/local/lib -ltcl8.4 -lm  /usr/lib/binmode.o
../../mymod.o: In function `TestCommand'
src/mod/mymod/mymod.cpp:54: undefined reference to `_dprintf'
If you add something like modules.o to your linker you get

Code: Select all

../../modules.o: In function `module_load':
/devel/eggdrop1.6.17/src/modules.c:791: undefined reference to `_H_load'
/devel/eggdrop1.6.17/src/modules.c:791: undefined reference to `_check_tcl_loadunld'
../../modules.o: In function `module_unload':
/devel/eggdrop1.6.17/src/modules.c:819: undefined reference to `_H_unld'
/devel/eggdrop1.6.17/src/modules.c:819: undefined reference to `_check_tcl_loadunld'
../../modules.o: In function `add_hook':
/devel/eggdrop1.6.17/src/modules.c:1027: undefined reference to `__rfc_ncasecmp'
/devel/eggdrop1.6.17/src/modules.c:1026: undefined reference to `__rfc_casecmp'
/devel/eggdrop1.6.17/src/modules.c:1028: undefined reference to `__rfc_tolower'
/devel/eggdrop1.6.17/src/modules.c:1029: undefined reference to `__rfc_toupper'
/devel/eggdrop1.6.17/src/modules.c:1037: undefined reference to `_block_dns_hostbyip'
/devel/eggdrop1.6.17/src/modules.c:1041: undefined reference to `_block_dns_ipbyhost'
../../modules.o: In function `del_hook':
/devel/eggdrop1.6.17/src/modules.c:1100: undefined reference to `_block_dns_hostbyip'
/devel/eggdrop1.6.17/src/modules.c:1104: undefined reference to `_block_dns_ipbyhost'
...

Seems it is not that easy to have it just compile ALL in C++.

I worked around that now by compiling the stuff that interacts with eggdrop directly (start, close, command functions) in C.
The other stuff i compile in C++ and then just link the stuff to one lib.
Seems to work for now.
Just need some ugly C functions to pass the input data to the classes *shrug*


Regards
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

well the thing is that eggdrop modules import global functions and vars via #define's in module.h which are actually indexes in a global table, so the extern "C" trick doesn't really apply here; besides, from the output you pasted I've got the feeling you somehow messed up your Makefile, you should link with ld -Bshareable, not with g++ -o; try to compile woobie.mod, adding some C++ stuff in woobie.c and making just one change in woobie's original Makefile: add CC=g++

hmm you are under cygwin... nevermind
K
Kappa007
Voice
Posts: 38
Joined: Tue Jul 26, 2005 9:53 pm

Post by Kappa007 »

That's what I initially did, changing CC to g++. Didn't work. But I did not use ld -Bshareable. You think it'll "just work" then?
Would be nice, but then again I just got it working quite smooth with 2 object files :D

Wouldn't help much anyway cause I only got few functions to share between C and C++.

Unless there's the posibility to bind commands with spaces:

Code: Select all

{"!trigger func1",           "",    (Function) func1,    NULL}
{"!trigger func2",           "",    (Function) func2,    NULL}
But no matter if i escape the space between trigger and func it did not work (yet), only gives me "Ambiguous command.". So I'm about to use one function and parse the input there.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

no, you can't bind with spaces, eggdrop splits the server input long before it comes to your bind
K
Kappa007
Voice
Posts: 38
Joined: Tue Jul 26, 2005 9:53 pm

Post by Kappa007 »

Aye! Thx for your help! :!:
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

just out of curiousity, what are you coding in C++ in that module?
G
Galadhrim
Op
Posts: 123
Joined: Fri Apr 11, 2003 8:38 am
Location: Netherlands, Enschede

Post by Galadhrim »

everything is coded in C would take a real long while to make your C++ module to work with it. Believe me I tried, it doesnt help performance either...
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

well obviously the guy's doing this for the sake of learning... it would be a completely different matter if eggdrop was built from the ground up in C++

C++ has been, is, and will be (at least in the foreseeable future) the programming language of choice for building the most important software products
G
Galadhrim
Op
Posts: 123
Joined: Fri Apr 11, 2003 8:38 am
Location: Netherlands, Enschede

Post by Galadhrim »

It would be cool to have it all in C++ so you can make 1 class which is your module. That would eliminate alot of worries.

Obviously it would take a very long time. And I can understand why the chap wants to use C++ as it is the 2nd programming language I learned and is easier to understand when you know only OO-languages. Still now knowing C my view on C++ has changed quite a bit.
Post Reply