egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Module in C++

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming
View previous topic :: View next topic  
Author Message
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Tue Jul 26, 2005 10:09 pm    Post subject: Module in C++ Reply with quote

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 Mad)
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 Wink

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


Thanks in advance Wink
Back to top
View user's profile Send private message
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Tue Jul 26, 2005 10:40 pm    Post subject: Reply with quote

Quote:

#undef dprintf
extern "C" void dprintf(int idx, const char * text, ...);


After the modules include seems to fix it Very Happy
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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Jul 26, 2005 10:49 pm    Post subject: Reply with quote

Code:

extern "C" {
// your C function prototypes here
}
Back to top
View user's profile Send private message Visit poster's website
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Wed Jul 27, 2005 6:40 am    Post subject: Reply with quote

Yeah. Just that i'll have to undecorate the stuff from module.h or something Mad
Anyway if that is the recommended way no problem Smile
Back to top
View user's profile Send private message
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Wed Jul 27, 2005 6:46 pm    Post subject: Reply with quote

Actually that only helped at first glance
Quote:

undefined reference to `dprintf(int, char const*, ...)'

Now i get that error while trying to link Sad

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 Sad

Help pls anyone Wink
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Jul 27, 2005 7:56 pm    Post subject: Reply with quote

post the exact error log (using [code] tag, not [quote]) and RTFM (doc/MODULES)
Back to top
View user's profile Send private message Visit poster's website
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Wed Jul 27, 2005 9:10 pm    Post subject: Reply with quote

The doc does not say anything about C++ Wink

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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Jul 27, 2005 10:29 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Wed Jul 27, 2005 11:35 pm    Post subject: Reply with quote

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 Very Happy

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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Thu Jul 28, 2005 12:31 am    Post subject: Reply with quote

no, you can't bind with spaces, eggdrop splits the server input long before it comes to your bind
Back to top
View user's profile Send private message Visit poster's website
Kappa007
Voice


Joined: 26 Jul 2005
Posts: 38

PostPosted: Thu Jul 28, 2005 4:57 am    Post subject: Reply with quote

Aye! Thx for your help! Exclamation
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Fri Jul 29, 2005 12:03 am    Post subject: Reply with quote

just out of curiousity, what are you coding in C++ in that module?
Back to top
View user's profile Send private message Visit poster's website
Galadhrim
Op


Joined: 11 Apr 2003
Posts: 123
Location: Netherlands, Enschede

PostPosted: Sat Jul 30, 2005 11:33 am    Post subject: Reply with quote

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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Jul 30, 2005 12:26 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Galadhrim
Op


Joined: 11 Apr 2003
Posts: 123
Location: Netherlands, Enschede

PostPosted: Sat Jul 30, 2005 3:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber