Hi everyone,
I’m trying to include the Klein library in ioquake. I want to use it in code/qcommon/q_shared.c and code/qcommon/q_math.c. The goal of this is to replace some of the geometry functions and see if there are any performance benefits. I’m doing this for my bachelor thesis.
The Klein library consists of two files: klein.h and libklein_c.a
I’ve added the following code
code/qcommon/q_shared.h:
#include "../klein/klein.h"
In the Makefile I added the following lines at the top:
KLEIN_LIB?=./code/klein/libklein_c.a
In the Makfile I made the changed these lines:
$(B)/$(CLIENTBIN)$(FULLBINEXT): $(Q3OBJ) $(LIBSDLMAIN)
$(echo_cmd) "LD $@"
$(Q)$(CC) $(CLIENT_CFLAGS) $(CFLAGS) $(CLIENT_LDFLAGS) $(LDFLAGS) $(NOTSHLIBLDFLAGS) \
-o $@ $(Q3OBJ) \
$(LIBSDLMAIN) $(CLIENT_LIBS) $(LIBS)
...
$(B)/$(SERVERBIN)$(FULLBINEXT): $(Q3DOBJ)
$(echo_cmd) "LD $@"
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(NOTSHLIBLDFLAGS) -o $@ $(Q3DOBJ) $(LIBS)
To these lines respectively:
$(B)/$(CLIENTBIN)$(FULLBINEXT): $(Q3OBJ) $(LIBSDLMAIN)
$(echo_cmd) "LD $@"
$(Q)$(CXX) $(CLIENT_CFLAGS) $(CFLAGS) $(CLIENT_LDFLAGS) $(LDFLAGS) $(NOTSHLIBLDFLAGS) \
-o $@ $(Q3OBJ) ${KLEIN_LIB} \
$(LIBSDLMAIN) $(CLIENT_LIBS) $(LIBS)
...
$(B)/$(SERVERBIN)$(FULLBINEXT): $(Q3DOBJ)
$(echo_cmd) "LD $@"
$(Q)$(CXX) $(CFLAGS) $(LDFLAGS) $(NOTSHLIBLDFLAGS) -o $@ $(Q3DOBJ) ${KLEIN_LIB} $(LIBS)
When I run make, I get the following errors:
CGAME_Q3LCC code/cgame/cg_main.c
) in #if/#elsif/../klein/klein.h:6 code/cgame/../qcommon/q_shared.h:26 code/cgame/cg_local.h:23 code/cgame/cg_main.c:24 Bad operator (
cpp: code/cgame/../klein/klein.h:11 code/cgame/../qcommon/q_shared.h:26 code/cgame/cg_local.h:23 code/cgame/cg_main.c:24 Syntax error in #include
) in #if/#elsif/../klein/klein.h:166 code/cgame/../qcommon/q_shared.h:26 code/cgame/cg_local.h:23 code/cgame/cg_main.c:24 Bad operator (
cpp: code/cgame/../klein/klein.h:168 code/cgame/../qcommon/q_shared.h:26 code/cgame/cg_local.h:23 code/cgame/cg_main.c:24 No newline at end of file
CGAME_Q3LCC code/game/bg_misc.c
make[2]: *** [Makefile:2864: build/release-linux-x86_64/baseq3/cgame/cg_main.asm] Error 1
make[2]: *** Waiting for unfinished jobs....
) in #if/#elsif../klein/klein.h:6 code/game/../qcommon/q_shared.h:26 code/game/bg_misc.c:25 Bad operator (
cpp: code/game/../klein/klein.h:11 code/game/../qcommon/q_shared.h:26 code/game/bg_misc.c:25 Syntax error in #include
) in #if/#elsif../klein/klein.h:166 code/game/../qcommon/q_shared.h:26 code/game/bg_misc.c:25 Bad operator (
cpp: code/game/../klein/klein.h:168 code/game/../qcommon/q_shared.h:26 code/game/bg_misc.c:25 No newline at end of file
make[2]: *** [Makefile:2861: build/release-linux-x86_64/baseq3/cgame/bg_misc.asm] Error 1
The log above says that the errors are on lines 6, 11 and 166 of klein.h. Below you can see the relevant sections of klein.h:
1. // File: klein.h
2. // Purpose: Klein C interface, suitable for binding to other languages
3.
4. #pragma once
5.
6. #if __cplusplus
7. extern "C"
8. {
9. #endif
10.
11. #include <xmmintrin.h>
...
166. #if __cplusplus
167. }
168. #endif
Does anyone know what is going wrong and how to solve it?
There is another problem I’ve come across. To be able to use malloc in q_shared.c, I added #include <stdlib.h>
in q_shared.h. When I compile, I get the error:
cpp: code/game/../qcommon/q_shared.h:26 code/game/bg_pmove.c:26 Could not find include file <stdlib.h>
cpp: code/game/../klein/klein.h:8 code/game/../qcommon/q_shared.h:27 code/game/bg_pmove.c:26 Syntax error in #include
Klein library github: GitHub - jeremyong/klein: P(R*_{3, 0, 1}) specialized SIMD Geometric Algebra Library