Can't use threads

Pages: 1234
> -static-libstdc++ -static-libgcc -lboost_thread -lboost_system
> and it gives me the following message in the console:
> Cannot execute ....

Is the the directory containing the libboost_thread dll somewhere in the search path used to locate shared libraries?

No, and I can't find libboost_anthingin my boost files!
Last edited on
It compiles and runs on ideone with the detach line removed.
I know!!!!!!!!!!!!!!!!! That's why I started this thread*!!!!!! Because I can't work with threads on my computer!!!!!!!!!!!!!!!
*funny, I can start threads on a C++ forum, but not in my C++! *cry*
Have you removed the detach from your code because that line causes an error.
No, I am working with boost::threa dnow, and this is my(still errorfull) code:
1
2
3
4
5
6
7
8
#include <boost/thread.hpp>

using namespace std;

int main()
{
	boost::thread a;
}

I really don't know how to make this simpler!
What are the errors?
This works for me using boost 1.44
1
2
3
4
5
6
7
8
#include <iostream>
#include <boost/Thread.hpp>
int main()
{
	boost::thread mythread([](){std::cout<<"Hello World!";});
	//mythread.detach();
	mythread.join();
}
Last edited on
The error is that it can't find the librarys lboost_thread and -lboost_system!!
Is that a linker error or a runtime error? If its runtime try putting the thread dll in the directory with the executable. If its a linker error check that body is in your path. I don't use mingw often but maybe something similar to ldconfig is necessary.
Alright viliml, I'll walk you through this step by step, starting a new project in my IDE (Code::Blocks). Obviously since you're not new, I don't need to tell you it's a console project, or that you need main.cpp in it. But using your code you pasted, you need to add this to the Build Options (If using an IDE that handles compiling/linking steps). I have the following files linked:
Edit: You can typically add these somewhere in the Build Options of your Project. Mine were located under the Linker Options. (Notice the lib and .a were removed when adding them)
boost_system
boost_thread
boost_chrono


And here is the build log:
-------------- Build: Debug in Boost Threads (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions  -g  -Weffc++ -Wmain -pedantic-errors -pedantic -std=c++0x -Wextra -Wall    -c "C:\Programming\Boost Threads\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe  -o "bin\Debug\Boost Threads.exe" obj\Debug\main.o    -lboost_system -lboost_thread -lboost_chrono 
Output size is 1.67 MB


If you can't get that to work, then you might need to try the boost libraries again. I don't remember needing chrono, but I kept getting linker errors about chrono so I added it and it went away. System is also needed, as well as thread (duh!).

Since you're saying you have 4.7.1, are you sure that orwell's is using the correct compiler?

Please note: libboost_system.a, libboost_thread.a, and libboost_chrono.a are typically located in:
boost_root_directory/lib

If they don't exist, you didn't install the libraries correctly.
Last edited on
Nope, they don't exist!
Since you're saying you have 4.7.1, are you sure that orwell's is using the correct compiler?

Yea, I manually installed the newes MinGW and replaced all the regular file paths with those, and I tested everything that 4.7 can, and 4.6 can't, and it works (except for threads :()
Anyone? Please?
I cant find the file b2! Or .exe, or .bat OR ANYTHING!!!
Last edited on
Also, the bootstrap procedure says that
bootstrap wrote:
'cl' is not recognized as an internal or external command,
operable program or batch file.
, and exits.
Last edited on
http://www.boost.org/boost-build2/doc/html/bbv2/installation.html

added now:

'cl' is the Microsoft C compiler.

Why don't you just use a MinGW build with GCC 4.7.1 and pre-built Boost 1.50.0 binaries for now?
http://nuwen.net/mingw.html
Last edited on
IT DOESN'T WORK! I TRIED!!
EDIT: JLBorges, Didn't see your edit, I'll try that tnx.
Last edited on
OK, I installed that, made my IDE use that compiler, and those libs, and manualy checked that all those libs really are there (they are), and it still cna't find them! I'm sure I put the right path!
I tried with and without .a, with and without -static, and with and without -static...a! STILL NOTHING WORKS!!
Pages: 1234