Adding own native mods/libraries

hi everyone, im trying to add new stuff to game but struggling with some topics:

added these to end of the makefile

CXX ?= g++
TARGETS := $(B)/haptics/libhaptics.a $(TARGETS)
CLIENT_LIBS := $(CLIENT_LIBS) -L$(MOUNT_DIR)/haptics/dhd/lib -L$(B)/haptics \
	-ldhd -lpthread -lusb-1.0 -lrt \
	-lGL -lGLU -lglut \
	-lm -lstdc++ -lhaptics
$(B)/haptics/%.o: $(MOUNT_DIR)/haptics/%.cpp
	-mkdir -p $(B)/haptics
	$(CXX) -g -fPIC -DLINUX -I$(MOUNT_DIR)/haptics/dhd/include -I$(MOUNT_DIR)/haptics -o $@ -c $<
$(B)/haptics/%.a: $(B)/haptics/haptics.o
	ar rcs $@ $<

i created folder inside code named ‘haptics’ and i put 2 files 1 directory there:

  • haptics.cpp
  • haptics.h
  • dhd/
    • include/
      • dhdc.h
    • lib/
      • libdhd.a

the dhd folder is the linux x64 library i got from forcedimension website
( http://www.forcedimension.com/download/sdk )
under ‘Other Releases’ Haptics SDK, dhd-3.2.2, i renamed out folder as dhd and put it in code/haptics/

when i compile i see build/release-linux-x86_64/haptics/libhaptics.a there and when i run ‘ar t’ on archive i see haptics.o inside

*I CAN SUCCESSFULLY COMPILE BUT FAIL WHEN LINKING CLIENTBIN AKA IOQUAKE3.$(ARCH)

btw i have these codes:

haptics.h:

#ifndef _HAPTICS_H_
#define _HAPTICS_H_

void haptics_init(void);
#endif

haptics.cpp:

#include <dhdc.h>
#include "haptics.h"

void haptics_init() {
	if(dhdOpen() < 0)
		return;
	dhdWaitForReset(); // blocking function
	return;
}

and in code/sdl/sdl_input.c

i added ‘#include “…/haptics/haptics.h”’ after normal inclusions (line 35)
and added haptics_init(); to end of the IN_Init() function (line ~970) after dash print

i cannot pass linking stage due to error:

build/release-linux-x86_64/client/sdl_input.o: In function `IN_Init':
code/sdl/sdl_input.c:(.text+0xfbb): undefined reference to `haptics_init'

what should i do to pass linking stage?

Maybe it’s because you’re compiling haptics as C++ and trying to link it with a C program? Try adding extern "C" before the the haptics_init function in haptics.h and haptics.cpp.

haptics.cpp

extern "C" void haptics_init( void ) {
    // code
}

haptics.h

#ifdef __cplusplus
extern "C" {
#endif

void haptics_init( void );

#ifdef __cplusplus
}
#endif

SDL2 has haptics support for joysticks/gamecontrols built in. I don’t know if it would work with your device. https://wiki.libsdl.org/CategoryForceFeedback

1 Like

thanks man, it solved everyting

i first thought when i convert to .o file nothing differs between c, c++

btw they are not actual ‘gaming joysticks’ they are like ftdi devices, serial (arduino like etc)

even sdl initialization (already in the code in_joystick) doesnt light up these devices… and libraries are closed…

Okay, I’m glad it worked.