Gmod Module ConCommand Help

Hello, I’m trying to add a console command through C++ in a GMOD Module. The code goes something like this.


	
CreateInterfaceFn VSTDLibFactory = Sys_GetFactory("vstdlib.dll");
cvar = ( ICvar* )VSTDLibFactory( CVAR_INTERFACE_VERSION, NULL );

cvar->RegisterConCommand(new ConCommand ( "test_concmd", concmd_f, "Test Comcommand through c++", 0)); 


The problem is when I compile it I get an error like this:


1>tier1.lib(tier1.obj) : error LNK2005: _cvar already defined in gm_main.obj

I’ve got it linked against tier0.lib and tier1.lib, and included icvar.h and convar.h, and I haven’t edited any of the headers. Any Ideas how I can fix this?

I thought I recognized your name. Making a binary version of Hemi-Hacks? :v:

That aside, don’t use the name cvar. It’s conflicting with the naming Source cvar uses internally and causes that error.

No, and wow thanks it was as simple as that.


ConCommand my_function( "my_function", MyFunction_f, "Shows a message.", FCVAR_CHEAT );

[editline]19th August 2012[/editline]

Atleast that is how you would do it in normal source. I don’t see why it wouldn’t work in gmod.

[editline]19th August 2012[/editline]

Whoops, didn’t even see you fixed it.

Thanks, I got it working. It was as he said, I just named it “cvar” which was already created in the sdk.