Stuck while compiling binary for linux

I have a module which utilizes some stuff from source engine and I’m completely stuck in compilation.

Here’s the beginning:


#include "interface.h"
#include "ivrenderview.h"
#include "eifacev21.h"
#include "game/server/iplayerinfo.h"
#include "vphysics_interface.h"

#define GMMODULE
#include "GarrysMod/Lua/Interface.h"

VEngineServerV21::IVEngineServer *engineserver;
float *absoluteframetime;
IPhysics *physics;
IPhysicsEnvironment *physenv;


And here’s me trying to get stuff compiled:


[**** Development]$ g++ gmsv_module.cpp -I gmod-module-base/include -I source-sdk-2013/mp/src/public/tier1 -I source-sdk-2013/mp/src/public -I source-sdk-2013/mp/src/public/tier0 -I source-sdk-2013/mp/src/public/game/server -D __i386__ -D GNUC -D gnuc -D POSIX -D _LINUX -o gmsv_module.o
In file included from gmsv_module.cpp:8:0:
gmod-module-base/include/GarrysMod/Lua/Interface.h:21:0: warning: "DLL_EXPORT" redefined
    #define DLL_EXPORT extern "C" __attribute__((visibility("default")))
 ^
In file included from source-sdk-2013/mp/src/public/tier1/interface.h:52:0,
                 from gmsv_module.cpp:1:
source-sdk-2013/mp/src/public/tier0/platform.h:543:0: note: this is the location of the previous definition
 #define  DLL_EXPORT   extern "C" __attribute__ ((visibility("default")))
 ^
In file included from source-sdk-2013/mp/src/public/tier0/platform.h:30:0,
                 from source-sdk-2013/mp/src/public/tier1/interface.h:52,
                 from gmsv_module.cpp:1:
source-sdk-2013/mp/src/public/tier0/threadtools.h: In instantiation of ‘CInterlockedIntT<T>::CInterlockedIntT() [with T = int]’:
source-sdk-2013/mp/src/public/tier0/threadtools.h:1071:22:   required from here
source-sdk-2013/mp/src/public/tier0/basetypes.h:365:20: error: size of array is negative
 #define UID_PREFIX generated_id_
                    ^
source-sdk-2013/mp/src/public/tier0/basetypes.h:366:23: note: in definition of macro ‘UID_CAT1’
 #define UID_CAT1(a,c) a ## c
                       ^
source-sdk-2013/mp/src/public/tier0/basetypes.h:372:19: note: in expansion of macro ‘UID_CAT2’
 #define UNIQUE_ID UID_CAT2(UID_PREFIX,__LINE__)
                   ^
source-sdk-2013/mp/src/public/tier0/basetypes.h:372:28: note: in expansion of macro ‘UID_PREFIX’
 #define UNIQUE_ID UID_CAT2(UID_PREFIX,__LINE__)
                            ^
source-sdk-2013/mp/src/public/tier0/dbg.h:558:50: note: in expansion of macro ‘UNIQUE_ID’
  #define COMPILE_TIME_ASSERT( pred ) typedef int UNIQUE_ID[ (pred) ? 1 : -1 ]
                                                  ^
source-sdk-2013/mp/src/public/tier0/threadtools.h:422:42: note: in expansion of macro ‘COMPILE_TIME_ASSERT’
  CInterlockedIntT() : m_value( 0 )     { COMPILE_TIME_ASSERT( sizeof(T) == sizeof(long) ); }


Wtf is generated_id_ and why’s it’s negative?

It doesn’t look like you’re linking against the libtier0/1 objects. Here’s a cross-platform project I did that uses source engine bindings. Read the build_linux.lua, the g++ parameters are in there. I’d also recommend using premake or some other makefile system to help with compilation.

[editline]27th April 2015[/editline]

Also a Lua library can be used as a source plugin as well. The project I linked above does this, see src/plugincallbacks.cpp. This makes it easier/more reliable to get engine interfaces, in my opinion.

Am I doing something wrong if I do this?



CreateInterfaceFn serverdll = Sys_GetFactory("garrysmod/bin/server.so");


Yes, you don’t need the full path. Only “server.so”

To be honest, the linux sdk pissed me off so much, I literally remade the parts I needed without it, got the exports myself, and used convars+engine+msg like that ( I was linking against all needd stuff, worked fine on windows - not linux, using code::blocks ).