7

I'm trying to compile a really simple thread program on my linux machine(ubuntu), but clang seems to still throw an error at me even when I specify libc++. my program is:

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

makefile:

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 $@

specific error:

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

I'm not sure why clang isn't using libc++, because if i'm not mistaken clang will compile threads by using this library. Any help is appreciated!

Syntactic Fructose
  • 18,936
  • 23
  • 91
  • 177
  • Perhaps show us the error clang provides. – hetepeperfan May 16 '13 at 21:50
  • You have spelled `LDFLAGS` wrongly. – kennytm May 17 '13 at 06:07
  • 2
    Note that this is a known issue. [LLVM report](http://llvm.org/bugs/show_bug.cgi?id=12893), [Ubuntu report](https://bugs.launchpad.net/ubuntu/+source/clang/+bug/1081905), [Debian report](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=666539), [Clang mailinglist](http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-June/015641.html) – Albert Apr 03 '14 at 10:09

1 Answers1

8

In some (earlier) versions of libc++, some functions were not marked as constexpr, which means that they can't be used in static_assert. You should check that system_clock::duration::min() is actually marked that way. [ You'll probably have to check out numeric_limits, since I seem to recall that that was where the problem was ]

The good news is that, if that's the problem, then you can add constexpr to the numeric limits header file yourself; it won't cause any other problems.

Marshall Clow
  • 15,972
  • 2
  • 29
  • 45