Reputation: 13172
This test code is OK, the problem must be in the way I build it:
#include <boost/thread.hpp>
#include <iostream>
void Wait(int seconds)
{
boost::this_thread::sleep(boost::posix_time::seconds(seconds));
}
void Thread()
{
for (int i = 0; i < 5; ++i)
{
Wait(1);
std::cout << i << std::endl;
}
}
int main()
{
std::cout << "Boost threads test:" << std::endl;
boost::thread t(Thread);
t.join();
}
This is the CMakeLists.txt file:
project(BoostThreadsTest)
cmake_minimum_required(VERSION 2.8)
find_package(Boost 1.46 REQUIRED COMPONENTS thread)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
message(STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}")
else()
message(WARNING "Boost headers/libraries not found.")
endif()
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME}
${Boost_LIBRARIES}
${THREADING_LIBRARY}
)
Built with:
cmake -G "MinGW Makefiles" .
mingw32-make.exe
Everything goes well, with only this warnings:
In file included from C:/boost/include/boost-1_48/boost/thread/win32/thread_data.hpp:12:0,
from C:/boost/include/boost-1_48/boost/thread/thread.hpp:15,
from C:/boost/include/boost-1_48/boost/thread.hpp:13,
from C:\Users\pietro.mele\projects\tests\buildSystem_test\BoostTest\BoostThreadsTest\BoostThreadsTest\main.cpp:4:
C:/boost/include/boost-1_48/boost/thread/win32/thread_heap_alloc.hpp:59:40: warning: inline function 'void* boost::detail::allocate_raw_heap_memory(unsigned int
)' declared as dllimport: attribute ignored [-Wattributes]
C:/boost/include/boost-1_48/boost/thread/win32/thread_heap_alloc.hpp:69:39: warning: inline function 'void boost::detail::free_raw_heap_memory(void*)' declared
as dllimport: attribute ignored [-Wattributes]
I get the executable, but when I run it it does absolutely nothing. Not even the "Boost threads test:" string is printed, which is not involved in multithreading, yet. No error is produced. It is just like pressing the [return] key.
Thank you.
Upvotes: 0
Views: 117
Reputation: 121971
(Just pasting in my comment so question can be marked as closed).
I suspect a DLL is not being found. I have seen this behaviour when executing an exe from cygwin: nothing happens at all. But, when I double-click in the exe in Windows explorer I see a message box complaining about a missing DLL: try that. If this is the cause, adjust you PATH
to enable DLL to be located.
I am unsure of the reason that the message box is suppressed, if I discover it (or if someone adds it as a comment) I will update this answer.
Upvotes: 2