Some trouble compiling binary modules

Hello everyone,

Full disclosure, I am not trying to make my life harder by substituting something I can easily do with lua with c++ (at least I don’t think). Also it’s worth mentioning that I indeed have had zero experience with binary modules prior to this, but a fair amount of experience with c++ and lua.

I am working on a project that requires me to read and write from a FIFO that I have symlinked to the data folder. What I’d like to do is create a custom hook that executes whenever the FIFO is fed data. Writing the module seems pretty straightforward after referencing garry’s example and the official lua C API documentation; however, I am having issues with compiling the modules. Right now I am just trying to compile garry’s example using a (admittedly poorly written) makefile that I threw together.

I have no trouble compiling garry’s example using premake, but I personally am not a big fan of premake and nor am I concerned about cross-platform availability. I’ll try to keep this short and post my makefile.


CXX=g++
CFLAGS= -Wall -dynamiclib -Iinclude/

all:
    ${CXX} ${CFLAGS} *.cpp -o gmsv_example_foo.dll

…and the errors (at least the relavent ones).


g++ -Wall -dynamiclib -Iinclude/ *.cpp -o gmsv_example_foo.dll
gm_example.cpp:18:7: error: use of undeclared identifier 'LUA'
        if ( LUA->IsType( 1, Type::NUMBER ) )
             ^
-snip-

gm_example.cpp:51:1: error: C++ requires a type specifier for all declarations
GMOD_MODULE_CLOSE()
^~~~~~~~~~~~~~~~~
10 errors generated.

Thanks in advance for anyone who’s willing to help me through this.

Is GarrysMod/Lua/Interface.h being included properly? Have you defined GMMODULE in files that include it?

You could try changing CFLAGS to



-Wall -dynamiclib -Iinclude/ -DGMMODULE


You sir deserve to be sent a gift basket full of chocolates. -DGMMODULE is exactly what it needed. Might I ask what that flag does exactly? I’m not finding any documentation on clang’s nor gcc’s manual.

EDIT: Scratch that, I just looked a little deeper. Now I get it. Thanks for all the help.