Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

thread_local error #1897 cannot be dynamically initialized

John_M_Intel6
Employee
901 Views

Hi - I was trying to use some code on StackOverflow for a 'thread on exit' function, but it wouldn't compile:

http://stackoverflow.com/questions/20112221/invoking-a-function-automatically-on-stdthread-exit-in-c11

So I tried something simpler, and got the same problem:

#include <iostream>

class Test {
public:
  ~Test() {
    std::cout << "exit" << std::endl;
  }
};

thread_local Test aTest;

The error message is:

error #1897: thread-local variable cannot be dynamically initialized

Should it compile? This is Intel C++ 16.0, in Windows Visual Studio Pro 2012, with C++11 enabled.

0 Kudos
4 Replies
Melanie_B_Intel
Employee
901 Views

Dynamic thread_local variables require library support.  Microsoft added this support in vs2015.   If you'd like to use this feature please get the latest Intel 16.0 compiler (currently, update 1) to use with vs2015.

--Melanie 

0 Kudos
John_M_Intel6
Employee
901 Views

Hi Melanie - as I mentioned at the bottom of my post, I am using Intel C++ 16.0.

Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.1.146 Build 20151021

is there something else I need?

John

0 Kudos
John_M_Intel6
Employee
901 Views

Sorry - ignore my last reply. I'll try to update VS...

0 Kudos
John_M_Intel6
Employee
901 Views

Managed to update to VS2015 (eventually - required re-installation of Parallel Studio) and code now builds; thanks

0 Kudos
Reply