So I spent all day trying to get c++ threads to work with eclipse Kepler and mingw. I have tried adding the -std=c++11 flag, -lpthread flag, another flag and even added a symbol to the table GXX_EXPERIMENTAL_CXX0X. My latest attempt at getting threads to work is to follow this advice
std::thread is not a member of namespace std using Eclipse Kepler MinGW
which says:
Plain MinGW cannot support std::thread. You will need to use a
MinGW-w64 toolchain (such as those shipped with Qt 5) that has "posix"
threading enabled, so that libstdc++ exposes the thread, mutex and
future functionality. You can find an installer here.
Now I have a folder called:
C:\Program Files\mingw-builds\x64-4.8.1-posix-seh-rev5
How do I get this to work with eclipse so I can use threading? Do I have to replace something in my mingw file or somehow link this to eclipse? I have no clue where to even begin.LET ALONE if this is recommended.
Take a look at this FAQ
I think it is along the lines of what you want to do because basically you need to show eclipse a different version of MinGW. It looks like you'll need to set the PATH variable correctly so eclipse can find the new version.
Related
When I try to build the following code using MinGW-w64 in Eclipse, I get the error "Function 'CreateThreadpool' could not be resolved"
The code:
#define WINVER 0x0603
#define _WIN32_WINNT 0x603
#include <threadpoolapiset.h>
int main(void)
{
CreateThreadpool(nullptr);
return 0;
}
Note: If I remove the defines for windows version, then I get 2 errors:
'CreateThreadpool' was not declared in this scope
Function 'CreateThreadpool' could not be resolved
This means that the defines are making posible for threadpoolapiset.h header to declare the windows API functions.
So back to the initial example, the problem here is that the linker can't find the library where this function is defined.
According to MSDN this function is defined in library kernel32.lib and DLL kernel32.dll.
I found that in MinGW-w64 directories the kernel32 library is found as libkernel32.a, so I tryed including paths and libraries in C/C++ Build > Settings | Tab 'Tool Settings' > GCC C++ Compiler > Includes
I tryed including the directory, the library file and both. Also I did this in MinGW C++ Linker > Libraries
Does any one know how can I make it work?
The threadpool APIs were only added to the linker files in MinGW 4.0. You will need to upgrade.
Windows
If you downloaded MinGW-w64 through MSYS2, then upgrading should be simple; just follow the instructions here.
If you installed the Win-Builds binary package, simply uninstall that, download the new one, and install it.
If you got your MinGW-w64 as part of an IDE, you'll need to consult the IDE vendors to see how to upgrade.
Linux
Unfortunately MinGW-w64 4.0 is newer than most distributions provide. If you use Ubuntu, 15.10 is just around the corner and that should have it. If not, then you will need to build from source. The process for building from source is a little convoluted; go to the MinGW-w64 IRC channel on OFTC and ask there :/ That's what I had to do, anyway. Good luck.
Note to David Hefferman and company
MinGW-w64 doesn't use the same SDK model Microsoft uses. What is available is based on the version of MinGW used, and new things are added frequently and available in subsequent releases. (In fact the reason to use MinGW-w64 over vanilla MinGW is that it has support for most of the APIs that were introduced starting with XP.)
Qt and Code blocks download package have their MinGW compiler. And there's standalone MinGW itself. Is there any difference between them?
Can I use Qt's MinGW to build Code blocks project or vice versa?
Did I need another MinGW if i want to build C++ project without Qt Creator or Code Blocks?
Or, can I just use Qt's or Code Blocks' MinGW without standalone version of MinGW?
Both Qt Creator and CodeBlocks just bundle a version of MinGW (GCC) in their installations for convenience, so that users don't have to install it and configure it manually. In both cases, you can choose to download or install the IDE without installing MinGW (GCC), in which case, you need to configure the IDE to use whatever compiler you want it to use (which not only can be any standalone MinGW/GCC installation, but also any other compiler, including MSVC (Microsoft compiler), ICC (Intel's compiler), or Clang).
Here are instructions to configure a custom compiler for Qt Creator. And here are instructions for CodeBlocks.
Is there any difference between them?
As far as I know, there is no significant difference between them, except for the version, of course. IDEs that are bundled with MinGW-GCC will typically come with one particular (and often a bit older / more stable) version of it. When you install a standalone MinGW-GCC, it can be whatever version you choose. There are differences between versions, but usually not anything that would "break" code, just faster / better compilations or additional advanced features (which are not used by "default" projects in any case).
Can I use Qt's MinGW to build Code blocks project or vice versa?
I'm pretty sure you can. I don't see any reason why not. Of course, you have to get the configuration right, as per the instructions I linked to above.
Did I need another MinGW if i want to build C++ project without Qt Creator or Code Blocks?
If you want to build things outside of an IDE that is configured with a particular compiler or installation of MinGW, then you will have to make sure to setup a few things. This process is easier when doing a standalone installation of MinGW, but you can also figure out how to take an existing MinGW installation (that came from Qt / CodeBlocks) and make it work under CMD / PowerShell / MSYS, but it's a bit trickier and more unusual.
I was trying to use the boost library first time. Using as an environment Eclipse 4.3 with CDT and as compiler gcc 3.4 and boost 1.53.
I was browsing various sites to find info on how to setup boost, but it doesn't seem to work. When I compile trying to include boost/asio.hpp I get the error:
You must add -D__USE_W32_SOCKETS to your compiler options
However, I don't want to use windows sockets, I want to use posix, so I don't really know what is wrong. As I need the project to run on HP-UX later, I dont want to get to Windows specific. If I use now windows sockets will the program later be easily portable to Unix, or are all the details encapsulated in boost, and I don't have to care anyway?
I tested a simple testprogram using FOREACH loop to confirm that boost itself works, and this is the case.
I also found this: https://svn.boost.org/trac/boost/ticket/7881 so does it mean that this problem is currently currently not supported, or am I doing something wrong?
It seems what you're trying to do is not supported by the library, the documentation states the following under supported platforms
The following platforms and compilers have been tested:
Win32 and Win64 using Visual C++ 7.1 and Visual C++ 8.0.
Win32 using MinGW.
Win32 using Cygwin. (__USE_W32_SOCKETS must be defined.)
Linux (2.4 or 2.6 kernels) using g++ 3.3 or later.
Solaris using g++ 3.3 or later.
Mac OS X 10.4 using g++ 3.3 or later.
added emphasis is mine. If that's not possible, you might try the patch suggested in the linked ticket. However, grepping through the source code I see several occurrences of #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) so it's not obvious that simply patching io_service.hpp will resolve anything. You might try adding -U__CYGWIN__ to your CXXFLAGS, though the cygwin toolchain may not like that.
Full disclosure: I am not a Windows guy so hopefully someone else will chime in.
The libboost-devel package in the Cygwin distribution includes patches to not use Winsock on Cygwin in Boost.Asio. I suggest trying that in conjunction with the gcc4 packages, which provide more recent versions of GCC.
I've been trying multithreaded C++. I installed the new Dev C++ 5.4.1 and added -std=c++11 to the compiler options. Then I added #include <thread> somewhere in my source code, and std::thread mythread (some_func).
When I compile the source file, I get a compiler error "thread defined in this scope".
What do I have to do to have it working?
You have to get the correct package of Mingw like sad here:
http://gameprog.it/articles/90/c-11-getting-started-on-windows
the package is found at:
http://sourceforge.net/projects/mingwbuilds/
The article is about code::blocks, but you can easily setup DevC++ too. Just pay a bit care about file names.
There's no longer need for boost threads at all. (Boost still remain a very good library and I encourage you to take a deeper look, but that is out of topic)
Official build of MinGW (that compiler Dev-C++ uses) has no support for standard library threads now.
You can use boost::thread as a drop in replacement (API is similiar enough) or use Microsoft Visual C++, or try programming with g++ on Linux (this is what I have done recently, using a virtual machine).
Basically I want to compile C/C++ using the GCC on Windows. The two competing platforms, as i see it, are MinGW and Cygwin. Each have their own benifits and limitations. MinGW compiles for Windows, whereas Cygwin needs the cygwin .dll. However installing libraries on MinGW is difficult, whereas on cygwin it's easier, using the setup.exe as a 'package manager'.
My question is what's the best way to compile on Windows. Would it be better to use MinGW and struggle with libraries (in which case is there an easy way of installing libraries on MinGW). Or should I use Cygwin, if so how do I get it to compile without needing the cygwin .dll, effectively compile for normal Windows.
The easiest and best way to compile on windows is to use visual studio express. It is free. A good reason for using cygwin is for cross platform builds. A good reason to use gcc is it supports some compiler candy the Microsoft compiler doesn't.
But all in all VC++ Express is the way to go for windows only development.
There is always the option of using -mno-cygwin with Cygwin to compile against Windows libraries like MinGW does:
gcc -mno-cygwin file.c -o test
It's not an easy choice and mainly depends on how much you will rely on other libraries. Cygwin really adds an additional layer, which is heavier but "emulates" the Linux environment better than MinGW.
Edit:
Qt Creator allows you to compile with MinGW on Windows (and gcc on Linux, ...), has an IDE that makes debugging more friendly than gdb. If you need libraries, you still have the option of using the Qt libraries. That would be a good alternate solution to the Visual Studio if you really want to stick to gcc for future portability.
You might want to look at CodeBlocks. It is generally used to build WxWidgets apps, but it wraps MinGW nicely.
Actually, there's option #3: if your edition of Windows permits it, you can install Microsoft Services For Unix / Subsystem for Unix Applications, and then get gcc from SUACommunity. It has a package manager, too. Of those 3 options, this will give you behavior closest to a true Unix system.
However, the resulting applications aren't Win32 applications; they're SUA applications, and will require SUA to run. If you write code for yourself, it's usually not a problem if you write code for yourself, but if you want to write and distribute a proper Windows application, I would suggest staying away from anything that tries to emulate Unix, so MinGW it is.
Qt Creator comes with MinGW as standard and can be used to build projects that don't actually use the Qt framework.
There's an easy to install MinGW wrapped GCC at equation.com.
Click "Programming Tools" then "Fortran, C, C++", download the release you prefer, install and use.
One possible method is to use CMake which can build Visual Studio project from your sources and then compile from Visual Studio. It can build project for other IDEs too, so you can go cross platform.
I think the answer depends on whether you intend to use libraries or compile programs that are targeted to POSIX or a POSIX-based target. That's what Cygwin is intended for, while MinGW is more intended for compiling Windows-targeted programs using GCC.
Another option is TDM MinGW: http://www.tdragon.net/recentgcc/
It's basically an unofficial fork of MinGW with the latest GCC compiler available for both 32- and 64bit windows machines. Even some MinGW developers themselves use it.
Equation Gcc is even better: http://www.equation.com/servlet/equation.cmd?fa=fortran