Search code examples
c++buildpremake

Mix C++ with C in premake4?


I am trying to use premake4 to compile a C++ OpenGL project. And I choose glad to help me make it cross-platform.

Hence, I write the following script premake4.lua

solution "skinned-animation"
    configurations { "Debug", "Release" }

project "skinned-animation"
    kind "ConsoleApp"
    language "C++"
    linkoptions { "-L/usr/local/lib", "-lboost_system", "-lboost_filesystem", "-lglfw" }

    includedirs { "../prerequisite", "/usr/local/include" }
    files { "../skinned-animation/**.h", "../skinned-animation/**.cpp", "../skinned-animation/**.c" }

    buildoptions { "-std=c++14" }

However, the problem is that premake will exert the flag -std=c++14 to all both C(only glad.c actually) and C++ files. And that leads to an error.

How can we distinguish C and C++ and give them different flags because premake4 doesn't have filter?


Solution

  • In the end, I choose to compile glad.c to static library first with the following instruction and then link it to my project:

    clang -c glad.c
    ar rcs libglad.a glad.o