| View previous topic :: View next topic |
| Author |
Message |
Kappa007 Voice
Joined: 26 Jul 2005 Posts: 38
|
Posted: Tue Jul 26, 2005 10:09 pm Post subject: Module in C++ |
|
|
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 )
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  |
|
| Back to top |
|
 |
Kappa007 Voice
Joined: 26 Jul 2005 Posts: 38
|
Posted: Tue Jul 26, 2005 10:40 pm Post subject: |
|
|
| Quote: |
#undef dprintf
extern "C" void dprintf(int idx, const char * text, ...);
|
After the modules include seems to fix it
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? |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Jul 26, 2005 10:49 pm Post subject: |
|
|
| Code: |
extern "C" {
// your C function prototypes here
}
|
|
|
| Back to top |
|
 |
Kappa007 Voice
Joined: 26 Jul 2005 Posts: 38
|
Posted: Wed Jul 27, 2005 6:40 am Post subject: |
|
|
Yeah. Just that i'll have to undecorate the stuff from module.h or something
Anyway if that is the recommended way no problem  |
|
| Back to top |
|
 |
Kappa007 Voice
Joined: 26 Jul 2005 Posts: 38
|
Posted: Wed Jul 27, 2005 6:46 pm Post subject: |
|
|
Actually that only helped at first glance
| Quote: |
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  |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Jul 27, 2005 7:56 pm Post subject: |
|
|
| post the exact error log (using [code] tag, not [quote]) and RTFM (doc/MODULES) |
|
| Back to top |
|
 |
Kappa007 Voice
Joined: 26 Jul 2005 Posts: 38
|
Posted: Wed Jul 27, 2005 9:10 pm Post subject: |
|
|
The doc does not say anything about C++
And that already was the exact error:
| Code: |
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: |
../../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 |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Jul 27, 2005 10:29 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Kappa007 Voice
Joined: 26 Jul 2005 Posts: 38
|
Posted: Wed Jul 27, 2005 11:35 pm Post subject: |
|
|
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
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: |
{"!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. |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Thu Jul 28, 2005 12:31 am Post subject: |
|
|
| no, you can't bind with spaces, eggdrop splits the server input long before it comes to your bind |
|
| Back to top |
|
 |
Kappa007 Voice
Joined: 26 Jul 2005 Posts: 38
|
Posted: Thu Jul 28, 2005 4:57 am Post subject: |
|
|
Aye! Thx for your help!  |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Fri Jul 29, 2005 12:03 am Post subject: |
|
|
| just out of curiousity, what are you coding in C++ in that module? |
|
| Back to top |
|
 |
Galadhrim Op
Joined: 11 Apr 2003 Posts: 123 Location: Netherlands, Enschede
|
Posted: Sat Jul 30, 2005 11:33 am Post subject: |
|
|
| 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... |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Sat Jul 30, 2005 12:26 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Galadhrim Op
Joined: 11 Apr 2003 Posts: 123 Location: Netherlands, Enschede
|
Posted: Sat Jul 30, 2005 3:05 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|