Syn*_*ose 5 c++ makefile clang constexpr c++11
我正在尝试在我的linux机器(ubuntu)上编译一个非常简单的线程程序,但是即使我指定了libc ++,clang似乎仍然会向我抛出错误.我的计划是:
#include <iostream>
#include <thread>
void call_from_thread() {
std::cout << "Hello, World!" << std::endl;
}
int main()
{
std::thread t1(call_from_thread);
t1.join();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
生成文件:
CC=clang++
CFLAGS=-std=c++11 -stdlib=libc++ -pthread -c -Wall
#proper declaration of libc++, but still an error...
LDFALGS=
SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=bimap
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
.cpp.o:
$(CC) $(CFLAGS) $< -o $@
Run Code Online (Sandbox Code Playgroud)
具体错误:
In file included from main.cpp:2:
In file included from /usr/include/c++/4.6/thread:37:
/usr/include/c++/4.6/chrono:666:7: error: static_assert expression is not an
integral constant expression
static_assert(system_clock::duration::min()
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [main.o] Error 1
Run Code Online (Sandbox Code Playgroud)
我不确定为什么clang没有使用libc ++,因为如果我没有错误,clang将使用这个库来编译线程.任何帮助表示赞赏!
在某些(早期)版本的 libc++ 中,某些函数没有标记为constexpr,这意味着它们不能在static_assert. 您应该检查它system_clock::duration::min()实际上是那样标记的。[您可能需要检查一下numeric_limits,因为我似乎记得那是问题所在]
好消息是,如果这是问题所在,那么您可以constexpr自己添加到数字限制头文件中;它不会导致任何其他问题。