Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem compiling SFML: 'GetThreadId' not declared in scope  (Read 3914 times)

0 Members and 1 Guest are viewing this topic.

Kian

  • Newbie
  • *
  • Posts: 44
    • View Profile
I only just started using SFML and running a few tutorials. I used Git to get the project from GitHub, and ran CMake and compiled without problems. A couple days later I saw there were a few more commits to the project, so I ran fetch, merge, and tried to recompile. It then ran into a couple problems, but I assumed I had done something wrong and still had the compiled libraries, so I didn't think much of it.

Today I downloaded the project for a fresh install into another computer, so I could code on it as well, and again the make failed. So I thought I'd post it here.

I'm using Win7 with MingW, using MSYS for the console (I tried with the Git Bash and had the same issue).

After configuring the makefile for MinGW in CMake, I cd to the directory and run mingw32-make install, and this is the output:

Code: [Select]
$ mingw32-make install
Scanning dependencies of target sfml-system
[  1%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Clock.cpp.obj
[  2%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Err.cpp.obj
[  3%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Lock.cpp.obj
[  5%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Mutex.cpp.obj
[  6%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Sleep.cpp.obj
[  7%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/String.cpp.obj
[  8%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Thread.cpp.obj
[ 10%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/ThreadLocal.cpp.obj
[ 11%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Win32/MutexImpl.cpp.obj
[ 12%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Win32/Platform.cpp.obj
[ 14%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Win32/ThreadImpl.cpp.obj
D:\libs\SFML\src\SFML\System\Win32\ThreadImpl.cpp: In member function 'void sf::priv::ThreadImpl::Wait()':
D:\libs\SFML\src\SFML\System\Win32\ThreadImpl.cpp:63:33: error: 'GetThreadId' was not declared in this scope
mingw32-make[2]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/Win32/ThreadImpl.cpp.obj] Error 1
mingw32-make[1]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/all] Error 2
mingw32-make: *** [all] Error 2


Can't tell right now if it's the same problem I ran into in the other computer (meaning a commit maybe did something?) or some configuration issue on my end.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem compiling SFML: 'GetThreadId' not declared in scope
« Reply #1 on: June 14, 2011, 08:09:58 am »
It's already fixed ;)
Laurent Gomila - SFML developer

Kian

  • Newbie
  • *
  • Posts: 44
    • View Profile
Problem compiling SFML: 'GetThreadId' not declared in scope
« Reply #2 on: June 14, 2011, 03:21:12 pm »
Thanks. I took a moment to see the change yesterday, and look up the function. It appears on http://msdn.microsoft.com/en-us/library/ms683233%28v=vs.85%29.aspx, mentioning it should be in Winbase.h (with _WIN32_WINNT defined as 0x0502 or later, which should be Windows Server 2003 with SP1, Windows XP with SP2 if I understood the "Using the Windows Headers" page right), but at least in my compiler's headers it didn't appear.

Guessing maybe the next version of the compiler might have it? Not really used to the Windows API, that's one of the reasons why I'm using SFML in the first place :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem compiling SFML: 'GetThreadId' not declared in scope
« Reply #3 on: June 14, 2011, 03:22:39 pm »
Apparently this function is quite new in the Win32 API, someone told me that it exists only in Windows >= Vista. So that could explain why it's not in your MinGW headers.
Laurent Gomila - SFML developer

Silvah

  • Guest
Problem compiling SFML: 'GetThreadId' not declared in scope
« Reply #4 on: June 14, 2011, 04:42:26 pm »
There's a solution to the problem you were trying to solve that works on older Windowses, here's the patch for you ;):
Code: [Select]
--- a/src/SFML/System/Win32/ThreadImpl.hpp
+++ b/src/SFML/System/Win32/ThreadImpl.hpp
@@ -87,6 +87,7 @@ private :
     // Member data
     ////////////////////////////////////////////////////////////
     HANDLE myThread; ///< Win32 thread handle
+    unsigned myThreadId; ///< Win32 thread ID
 };

 } // namespace priv

--- a/src/SFML/System/Win32/ThreadImpl.cpp
+++ b/src/SFML/System/Win32/ThreadImpl.cpp
@@ -38,7 +38,7 @@ namespace priv
 ////////////////////////////////////////////////////////////
 ThreadImpl::ThreadImpl(Thread* owner)
 {
-    myThread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &ThreadImpl::EntryPoint, owner, 0, NULL));
+    myThread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &ThreadImpl::EntryPoint, owner, 0, &myThreadId));

     if (!myThread)
         Err() << "Failed to create thread" << std::endl;
@@ -57,7 +57,12 @@ ThreadImpl::~ThreadImpl()
 void ThreadImpl::Wait()
 {
     if (myThread)
-        WaitForSingleObject(myThread, INFINITE);
+    {
+        // The following condition avoids a deadlock if Wait() is called from its
+        // owner thread. This makes the behavior consistent with the Unix implementation.
+        if (myThreadId != GetCurrentThreadId())
+            WaitForSingleObject(myThread, INFINITE);
+    }
 }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem compiling SFML: 'GetThreadId' not declared in scope
« Reply #5 on: June 14, 2011, 04:57:08 pm »
Oh nice, thanks :)
Laurent Gomila - SFML developer

 

anything