Can't use threads

Pages: 1234
Aug 9, 2012 at 3:32pm
> -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?

Aug 9, 2012 at 3:38pm
No, and I can't find libboost_anthingin my boost files!
Last edited on Aug 9, 2012 at 3:43pm
Aug 9, 2012 at 3:53pm
It compiles and runs on ideone with the detach line removed.
Aug 9, 2012 at 3:58pm
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*
Aug 9, 2012 at 4:18pm
Have you removed the detach from your code because that line causes an error.
Aug 9, 2012 at 5:22pm
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!
Aug 9, 2012 at 6:13pm
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 Aug 9, 2012 at 6:14pm
Aug 9, 2012 at 6:27pm
The error is that it can't find the librarys lboost_thread and -lboost_system!!
Aug 9, 2012 at 6:50pm
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.
Aug 10, 2012 at 12:11am
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 Aug 10, 2012 at 12:43am
Aug 10, 2012 at 8:06am
Nope, they don't exist!
Aug 10, 2012 at 8:12am
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 :()
Aug 10, 2012 at 10:33am
Anyone? Please?
Aug 10, 2012 at 11:08am
Aug 10, 2012 at 11:27am
I cant find the file b2! Or .exe, or .bat OR ANYTHING!!!
Last edited on Aug 10, 2012 at 11:30am
Aug 10, 2012 at 11:46am
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 Aug 10, 2012 at 11:46am
Aug 10, 2012 at 11:51am
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 Aug 10, 2012 at 12:27pm
Aug 10, 2012 at 12:23pm
IT DOESN'T WORK! I TRIED!!
EDIT: JLBorges, Didn't see your edit, I'll try that tnx.
Last edited on Aug 10, 2012 at 12:45pm
Aug 10, 2012 at 1:06pm
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!
Aug 10, 2012 at 1:11pm
I tried with and without .a, with and without -static, and with and without -static...a! STILL NOTHING WORKS!!
Pages: 1234