C++ Module - Linking to access UTIL_TraceLine()

Hi,

I want to use the function ‘UTIL_TraceLine()’ in my C++ module.

I am including these headers in order to access the function:


shareddefs.h
enginecallback.h
util_shared.h

This compiles, but does not link. Here are the linker errors:


RegionModule.obj : error LNK2001: unresolved external symbol "class ConVar r_visualizetraces" (?r_visualizetraces@@3VConVar@@A)
RegionModule.obj : error LNK2001: unresolved external symbol "class IEngineTrace * enginetrace" (?enginetrace@@3PAVIEngineTrace@@A)
RegionModule.obj : error LNK2001: unresolved external symbol "void __cdecl DebugDrawLine(class Vector const &,class Vector const &,int,int,int,bool,float)" (?DebugDrawLine@@YAXABVVector@@0HHH_NM@Z)
RegionModule.obj : error LNK2001: unresolved external symbol "public: __thiscall CTraceFilterSimple::CTraceFilterSimple(class IHandleEntity const *,int)" (??0CTraceFilterSimple@@QAE@PBVIHandleEntity@@H@Z)

I have tried linking with everything in the “SDK\lib\public” directory however nothing seems to work. Any ideas ?

I’m using the Episodic SDK code.

Thanks.

I’d take this to the programming forum, this is C++ and they generally have better knowledge on that.

Sorry I couldn’t help.

(also to any mods, I’m just giving him a recommendation)

This is the right place because it’s a GMOD Lua Module.

There are links missing.
Search the source SDK for *.lib and include the necessary one.
I’m quite for math.lib, tier0.lib, tier1.lib and vstdlib.lib

Thanks for the replies. I decided to go with the context rather than the language, but I guess it could go in either area.

I just tried again with the libraries ‘mathlib.lib tier0.lib tier1.lib vstdlib.lib’ and rebuilt the project, but ended up with the same error. I double checked the library directory and added speech marks around it as it has spaces in it but that didn’t solve it either.

The only library outside of the SDK/lib/public/ directory is MsXml2.Lib, but that is only for converting the project files to make files.

You can only use exported methods and some of the classes with virtual methods. You have to sigscan for the rest.

Ah I see, it’s annoying that this method must be used to access such a common function. (Trace.)

I was hoping to get the performance boost from using native C, but I may just try calling trace through Lua for now and see it that’s acceptable.

Thank you for your help.



inline void UTIL_TraceLine( const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask, 
					 ITraceFilter *pFilter, trace_t *ptr )
{
	Ray_t ray;
	ray.Init( vecAbsStart, vecAbsEnd );

	enginetrace->TraceRay( ray, mask, pFilter, ptr );

	if( r_visualizetraces.GetBool() )
	{
		DebugDrawLine( ptr->startpos, ptr->endpos, 255, 0, 0, true, -1.0f );
	}
}


UTIL_TraceLine is inline function
You need define and get IEngineTrace interface in your code
For example



IEngineTrace* enginetrace = NULL;
enginetrace = (IEngineTrace*)interfaceFactory(INTERFACEIVERSION_IENGINETRACE,0);


How to bump a 7 year old topic. :godzing: