Index: build/premake/premake5.lua =================================================================== --- build/premake/premake5.lua +++ build/premake/premake5.lua @@ -109,6 +109,19 @@ end end +-- Test whether we need to link libatomic in clang +local link_atomic = false +if os.istarget("linux") and cc == "clang" then + os.execute(cc .. " -o atomic2.o -c ./tests/atomic2.cpp") + os.execute(cc .. " -o atomic1.o -c ./tests/atomic1.cpp") + local _, atomic_rc1 = os.outputof(cc .. " -o /dev/null -lstdc++ atomic1.o atomic2.o") + local _, atomic_rc2 = os.outputof(cc .. " -o /dev/null -lstdc++ -latomic atomic1.o atomic2.o") + if atomic_rc1 ~= 0 and atomic_rc2 == 0 then + link_atomic = true + end + os.execute("rm atomic1.o atomic2.o") +end + -- Set up the Workspace workspace "pyrogenesis" targetdir(rootdir.."/binaries/system") @@ -1059,6 +1072,12 @@ } end + if link_atomic then + links { + "atomic" + } + end + if os.istarget("linux") or os.getversion().description == "GNU/kFreeBSD" then links { -- Dynamic libraries (needed for linking for gold) Index: build/premake/tests/atomic1.cpp =================================================================== --- /dev/null +++ build/premake/tests/atomic1.cpp @@ -0,0 +1,9 @@ +#include "atomic2.h" +#include + +int main () +{ + if (test()) + printf(""); +} + Index: build/premake/tests/atomic2.h =================================================================== --- /dev/null +++ build/premake/tests/atomic2.h @@ -0,0 +1,4 @@ +#ifndef TEST +#define TEST +bool test(); +#endif Index: build/premake/tests/atomic2.cpp =================================================================== --- /dev/null +++ build/premake/tests/atomic2.cpp @@ -0,0 +1,9 @@ +#include +#include + +bool test() { + boost::lockfree::queue queue(128); + std::atomic test; + + return test; +}