Hi,
I have an issue that I hope someone can help with. I’m building a multithreaded application, using C++11 thread_local to get thread specific memory. My problem is that when I use a statically linked library and this library uses thread_locale, then I get a “SIGSEGV” (Segmentation fault) when ever I try to single step with the debugger over the statement that has the thread_local. (If just run the program, or move the code out of the lib then all seems fine).
I have simplified the progam to the following:
main.pro:
TEMPLATE = subdirs
SUBDIRS += \
lib \
app
app.pro:
# Turn on C++11 support
QMAKE_CXXFLAGS = -std=c++11
CONFIG += c++11
# Turn on thread support
LIBS += -pthread
QT += core
QT -= gui
TARGET = app
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
unix:!macx: LIBS += -L$$OUT_PWD/../lib/ -llib
INCLUDEPATH += $$PWD/../lib
DEPENDPATH += $$PWD/../lib
unix:!macx: PRE_TARGETDEPS += $$OUT_PWD/../lib/liblib.a
main.cpp:
#include <QCoreApplication>
#include "lib.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Lib lib;
return a.exec();
}
lib.pro:
# Turn on C++11 support
QMAKE_CXXFLAGS = -std=c++11
CONFIG += c++11
# Turn on thread support
LIBS += -pthread
QT -= gui
TARGET = lib
TEMPLATE = lib
CONFIG += staticlib
SOURCES += lib.cpp
HEADERS += lib.h
unix {
target.path = /usr/lib
INSTALLS += target
}
lib.h:
#ifndef LIB_H
#define LIB_H
class Lib
{
public:
Lib();
};
#endif // LIB_H
#include "lib.h"
Lib::Lib()
{
static thread_local int i;
i++; // << When single stepping, this line crashes the program
}
I’m guessing there is something basic that I’m missing?
(Qt Creator 3.3.0, with QT 5.4.0, running Ubuntu 14.04 LTS.)
↧