2013-05-16 38 views
5

我想編譯一個真正簡單的線程程序在我的Linux機器上(ubuntu),但鏗鏘似乎仍然拋出一個錯誤,即使當我指定libC++。我的計劃是:表達式不是一個整數常量叮噹libC++線程

#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; 
} 

生成文件:

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 [email protected] 

.cpp.o: 
     $(CC) $(CFLAGS) $< -o [email protected] 

特定的錯誤:

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 

鐺爲什麼不使用的libC++我不知道,因爲如果我沒有弄錯,clang會使用這個庫來編譯線程。任何幫助表示讚賞!

+0

也許向我們展示clang提供的錯誤。 – hetepeperfan

+0

你錯誤地拼寫了'LDFLAGS'。 – kennytm

+2

請注意,這是一個已知問題。 [LLVM報告](http://llvm.org/bugs/show_bug.cgi?id=12893),[Ubuntu報告](https://bugs.launchpad.net/ubuntu/+source/clang/+bug/1081905) ),[Debian報告](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=666539),[Clang郵件列表](http://lists.cs.uiuc.edu/pipermail/cfe -dev/2011六月/ 015641.html) – Albert

回答

3

在libC++的某些(較早)版本中,某些功能未標記爲constexpr,這意味着它們不能在static_assert中使用。您應該檢查system_clock::duration::min()實際上是以這種方式標記的。 [你可能必須檢查出numeric_limits,因爲我似乎記得那是問題的原因]

好消息是,如果這是問題,那麼你可以將constexpr添加到數字限制頭文件自己;它不會導致任何其他問題。

相關問題