-3

So I spent 2 hours trying to narrow down the cause of my code not working and I think it might just be something weird. Here's the exact example code I have and I can't minimize it further (yes, bar does literally nothing) :

// thread example
#include <iostream>       // std::cout
#include <thread>         // std::thread

void bar()
{
  // do stuff...
}

int main() 
{
    std::cout << "please run" << std::endl;

    std::thread t(bar);

    t.join();

    std::cout << "completed.\n";

    return 0;
}

Here's how I build it :

g++ -std=c++0x -o test test.cpp -pthread

When all of this is done in a blank directory, it works perfectly, but if I put test.cpp in my project directory, compile it here and run it, it crashes before even entering main. Here's the crash report but I translated it from French so it's not the exact text:

"The entry point of the procedure std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) cannot be found in the library of dynamic links [project directory]\test.exe"

Note that this message did not appear in the console command but in a separate window pop-up from where I can't copy-paste.

Here's what's the project directory is (not quite exactly because script files were updated but it's the same structure and libraries) : https://github.com/Leroymilo/RTX_Cpp

It has SFML and jsonCpp in it if it changes anything.

Also I am on Windows10 and I'm using VScode if it makes any difference.

I did what's advised in this post : Segmentation Fault while creating thread using #include<thread> but it does not change the result.

Leroy
  • 62
  • 8
  • 2
    The problem must be somewhere in the "do stuff" part. If you attempt to compile the shown code, exactly as is, it will work flawlessly when executed from any directory, so it's unclear how anyone on Stackoverflow could possibly figure anything out. – Sam Varshavchik Jul 04 '22 at 21:32
  • Turns out it doesn't , even with nothing in the function. – Leroy Jul 04 '22 at 21:37
  • Then it must be something in the environment of your system, some installation or configuration problem. Unfortunately, the only information that's available here is the shown code and there's nothing wrong with it. – Sam Varshavchik Jul 04 '22 at 21:43
  • @Leroy preparing a [mcve] as it's required to post here, might help in isolating, and identifying the problem. – πάντα ῥεῖ Jul 04 '22 at 21:55
  • When you run from blank directory, you use C++ runtime DLLs listed in `PATH`; probably those that came with your GCC installation. When you run from project directory, you use C++ DLLs in that directory; I see `libstdc++-6.dll` there. I can only assume that the two DLLs are somehow different, in a way whereby one works and the other doesn't. – Igor Tandetnik Jul 05 '22 at 00:41
  • Why do you have libstdc++-6.dll and libgcc_s_dw2-1.dll in your project directory? Surely you would use the one in the system library directory? And libgcc_s_dw2-1.dll is the same - it doesn't belong in your project directory either. – Jerry Jeremiah Jul 05 '22 at 01:04

1 Answers1

0

The issue was the presence of a file called "libstdc++-6.dll" in my project directory. I have no memories of why it's here because I copied all libraries from another project but if anyone does the same mistake, here's your solution.

Edit : I found out about why I had this in my files : it's because my build wasn't static and launching the built executable on another computer showed a pop-up asking for these. I fixed my static build issue with the answers provided in this post : Issues with libgcc_s_dw2-1.dll and libstdc++-6.dll on build .

Leroy
  • 62
  • 8