Search code examples
openglluapremake

Error when using premake with the function "UseLibs" with OpenGL sdk


I am using premake to make new projects using the OpenGL sdk. I am trying to put together my first real project, but I am having an error when I run premake4 vs2010 command. I am trying to use the UseLibs function to gain access the the OpenGL sdk elements, however premake is throwing an error which says:

"attempt to call global 'UseLibs' (a nil value)

Heres the lua code:

solution "OpenGL"
    configurations {"windows", "linux", "Debug", "Release"}
    project "MyProject"
        kind "ConsoleApp"
    language "c++"
files {"First OpenGL v3\*.cpp", "First OpenGL v3\*.h"}

UseLibs {"glimage", "glload", "freeglut", "glutil", "glmesh", "glfw", "glm"}

configuration "windows"
    defines "WIN32"
    links {"glu32", "opengl32", "gdi32", "winmm", "user32"}

configuration "linux"
    links {"GL"}

configuration "Debug"
    targetsuffix "D"
    defines "_DEBUG"
    flags "Symbols"

configuration "Release"
    defines "NDEBUG"
    flags {"OptimizeSpeed", "NoFramePointer", "ExtraWarnings", "NoEditAndContinue"};

Much of the code here is based on what it says to do on the tutorial so I am not sure why I am getting this error. I am fairly new at this, so if you see any other issues please tell me. Thanks.


Solution

  • Allow me to quote from what you linked to:

    Regardless of whether the main premake4.lua file does all the work, the first thing you should do is execute this instruction:

    dofile("path/to/GLSDK/links.lua")
    

    I don't see that line in your Premake4 build script.

    Also, there's no need to include both FreeGLUT and GLFW. You cannot possibly use them both in the same application, since they both do the same thing. They create OpenGL windows. I mean, I guess you could possibly use them both, but it seems unlikely to work.

    Your program uses one or the other. Whichever one it uses is the one you should put in the UseLibs command.

    Also:

    configurations {"windows", "linux", "Debug", "Release"}
    

    windows and linux are not normal, user-specified, configurations. They're OS configurations. You don't list them in the solution configuration's list; they're part of the system. Listing them here may cause problems.