I'm trying to build a static C++ 20 library using CMake 3.25 on Linux Mint with CLion.
The build fails when trying to compile any file which includes the <string>
header.
I'm getting a lot of error messages like this one:
In file included from /usr/include/c++/11/bits/localefwd.h:40,
from /usr/include/c++/11/string:43,
from /home/foo/repos/RMC/SE/src/sstd/misc/output.h:3,
from /home/foo/repos/RMC/SE/src/animation/animation_channel.cpp:2:
/usr/include/x86_64-linux-gnu/c++/11/bits/c++locale.h: In function ‘int std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)’:
/usr/include/x86_64-linux-gnu/c++/11/bits/c++locale.h:92:48: error: expected primary-expression before ‘,’ token
92 | const int __ret = __builtin_vsnprintf(__out, __size, __fmt, __args);
| ^
In file included from /usr/include/c++/11/string:44,
from /home/foo/repos/RMC/SE/src/sstd/misc/output.h:3,
from /home/foo/repos/RMC/SE/src/animation/animation_channel.cpp:2:
/usr/include/c++/11/bits/ostream_insert.h: In function ‘void std::__ostream_write(std::basic_ostream<_CharT, _Traits>&, const _CharT*, std::streamsize)’:
/usr/include/c++/11/bits/ostream_insert.h:51:37: error: expected primary-expression before ‘.’ token
51 | const streamsize __put = __out.rdbuf()->sputn(__s, __n);
| ^
/usr/include/c++/11/bits/ostream_insert.h:53:14: error: expected primary-expression before ‘.’ token
53 | __out.setstate(__ios_base::badbit);
| ^
/usr/include/c++/11/bits/ostream_insert.h: In function ‘void std::__ostream_fill(std::basic_ostream<_CharT, _Traits>&, std::streamsize)’:
/usr/include/c++/11/bits/ostream_insert.h:63:31: error: expected primary-expression before ‘.’ token
63 | const _CharT __c = __out.fill();
| ^
/usr/include/c++/11/bits/ostream_insert.h:66:57: error: expected primary-expression before ‘.’ token
66 | const typename _Traits::int_type __put = __out.rdbuf()->sputc(__c);
| ^
/usr/include/c++/11/bits/ostream_insert.h:69:20: error: expected primary-expression before ‘.’ token
69 | __out.setstate(__ios_base::badbit);
| ^
The code builds perfectly fine on Windows using MSBuild. I've tried switching g++ executables, changing the C++ version to 17 and building outside of CLion, with the same result. Here are the files that g++ is complaining about (no errors in CLion):
animation_channel.cpp
#include "animation_channel.h"
#include <misc/output.h>
namespace SE::Animation
{
Transform AnimationChannel::Sample(const float time) const
{
// Check if the parameter is inside the bounds.
auto lastKeyFrameTime = mKeyTimes[mKeyCount - 1];
SE_ASSERT(time <= lastKeyFrameTime);
// Get 2 keys which are the closest to the time; one after and one before it.
int t;
for (t = 1; t < mKeyCount; t++)
{
if (mKeyTimes[t] > time) break;
}
Transform next = mData[t];
Transform prev = mData[t - 1];
return Transform::Interpolate(prev, next, time);
}
}
output.h
#pragma once
#include "../buildsystem.h"
#include <string>
#include <cstdint>
#ifdef SE_DEBUG
#define SE_ASSERT(condition) sstd::Output::Assert(condition, #condition, __FILE__, __LINE__)
#else
#define SE_ASSERT(condition) sstd::Output::Assert(condition, #condition, "unnamed file", __LINE__)
#endif
namespace sstd
{
enum class MessageType : uint32_t
{
Error,
Warning,
Info,
Debug,
Success,
ErrorQuit,
};
class Output
{
public:
static void WriteLine(const std::string& message, MessageType type);
static void WriteLine(const std::string& message);
static void WriteLog(const std::string& message, MessageType type);
static void Assert(bool condition, const char* conditionString, const char* file, int line);
};
}
Here's the CMakeLists.txt:
cmake_minimum_required(VERSION 3.25)
project(SE)
set(CMAKE_CXX_STANDARD 20)
include_directories(include)
add_library(SE STATIC
...
)