MinGW-w64 can't resolve threadpoolapiset.h declared functions - c++

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.)

Related

Building GSL (GNU Scientific Library) in Windows for use with VS2015

I am trying to build GSL as a library(DLL,lib) to use with my application. I have tested both GSL ports(gladman) to VS and CMake route and I do not want to go that path due to various reasons.
Currently I am using nuget version and I am not too happy about it as some functions are missing. I want to build it myself to be absolutely sure about what I am getting. The objective is to build four set of dll and libs---win32, win32d, win64 and win64d.
I know that from a MinGW library I can build lib file(for VS2015) and thereafter dll using Microsoft LIB tool if I have DEF file available.
My open source experience is very limited. Till now I have successfully built gsl for MinGW using ./config, make, make install. But I am not finding any DEF file generated and I do not know how to utilize this build to generate required DEF and dll to be used with Microsoft Visual Studio 2015.
Thank you
Building and linking has always been a pain for me as well. For mac, I use Homebrew, which downloads frameworks and libraries through a simple one-line-command in the terminal. I would then simply add the library into my program by adding the directory of the libs necessary. In XCode, there was an "add framework/library"-button where I added the directories, but I'm sure there's an analogue in VS.
However, you seem to be using Windows (so Homebrew will not work). I searched the web for Windows versions of Homebrew, and it seems that Scoop is pretty similar. You might want to check that out.
Hope this helped, despite me using different tools :)

Upgraded to win 10 and then my Direct3D11 project wouldn't link

This is a very specific problem, - I apologize for that.
I've been building a graphical real-time application using Direct3D 11. I started it on the Win7 OS. I then upgraded to Win10 and when I tried compiling the solution again, the linker barfed like it had caught the plague for silicon microchips.
It spews out Unresolved symbols in objects that don't even use the given functions.
__imp__wassert
strlen
fabs
__imp__CrtDbgReportW
sprt
and more
I've concluded that the majority of the functions in question is mostly C functions. I'm aware that the c functions are no longer included in the C++ headers and libraries, so I made sure to include all the relevant C-libraries explicitly.
I've read and followed the solutions of some of most of the other folks having problems with Windows 10 screwing their code. one of them is this : Upgraded to Windows 10 and now WAMP won't work
I also tried actually telling the linker where to look for the -lib-files, in case the compiler or project missed the memo.
On my PC, the location for the Direct3D libs is here: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\arm64
As you can see, I am trying to force it to use Win10 lib versions in case this was a requirement.
I started in one end to try and catch myself doing something stupid:
I looked for full include paths to see it this had started an avalanche: FAILED
I tried removing the /ZI compiler option: FAILED
Relinking the DirectX libs to all different version one at the time: FAILED
Explicitly include the vcrumtime.lib to the additional linker libs: SUCCESS (removed half the errors)
Create An entirely new project and include everything from scratch: FAILED
Add MSVCRTD.lib : FAILED
Change the target platform to 64bit: FAILED
Tried including stdio.h in certain independant tool classes: FAILED
Tried including Winmm.lib in the linker: FAILED
I've roamed the internet for what feels like a decade (only a month irl) to find some solution, but nothing.
I hope some of you have an idea of what noobiness I might have committed.
All suggestions will help.
Most likely you are linking with a static library that is not compatible with VS 2015 because it uses the Universal CRT. For example, the legacy DirectX SDK library DXERR.LIB fails to link when using VS 2015. Make sure you rebuild all your code with VS 2015 and avoid the use of static libraries build for other versions of Visual C++.
You also won't be able to get your project to link and run on an x86 or x64 PC linking with the 64-bit ARM libraries.
You do not need to use the Windows 10 SDK for Win32 desktop apps, although you certainly can.

How to configure Eclipse to use a particular MinGW toolchain

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.

boost asio giving You must add -D__USE_W32_SOCKETS to your compiler options on cygwin

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.

wWinmain, Unicode, and Mingw

I am working on learning the windows API and am using mingw as my compiler with Code::Blocks as my IDE. I have run into an issue with using the wWinMain function. I used the program located here link text. It compiles fine on VSC++ 2008 express but when using mingw i get the "undefined reference to WinMain#16" error. I have figured out what the problem is (i think). By replacing the wWinMain with just Winmain and the String pointer PWSTR with LPSTR it compiles perfectly. My question is, how can i fix this, and if not, is not using Unicode that big of a deal.
Thanks.
For old versions of MinGW, you can use a wrapper:
mingw-unicode-main:
https://github.com/coderforlife/mingw-unicode-main/
Simple wrappers to add wmain and wWinMain support in MinGW
These wrappers allow for use of wmain / wWinMain in MinGW seamlessly
with Unicode (WCHAR), regular (CHAR), or the ability to choose
(TCHAR).
The instructions for using them are in the files. Also take a look at
other programs that use them.
For new versions of MinGW, you should use the -municode option, like it says in the mingw-unicode-main readme:
Note: This should no longer be used as MinGW now has a built-in
solution. Add -municode to the command line (and possibly extern "C"
to the wmain function).
The -municode option works with MinGW-w64. In 2012-07, when I tried MinGW, it did not have the -municode option.
Here is how to install MinGW-w64:
Target Win32:
Home > Toolchains targetting Win32 > Personal Builds > rubenvb > gcc-4.7-release:
http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-4.7-release/
On Windows, you want "i686-w64-mingw32-gcc-4.7.2-release-win32_rubenvb.7z".
Extract folder to the root of your drive.
Rename the "mingw32" folder to "MinGW-32".
Target Win64:
Home > Toolchains targetting Win64 > Personal Builds > rubenvb > gcc-4.7-release:
http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/gcc-4.7-release/
On Windows, you want "x86_64-w64-mingw32-gcc-4.7.2-release-win32_rubenvb.7z".
Extract folder to the root of your drive.
Rename the "mingw64" folder to "MinGW-64".
Unicode-related questions:
How do I use the wmain() entry point in Code::Blocks?
Compiling Windows program in Dev-C++ gives error
#define _UNICODE not working with MinGW + CodeBlocks
Use the plain (non unicode) WinMain function, and then get your unicode command line using GetCommandLineW. MinGW doesn't know about wWinMain.
You are probably going to find working on MinGW difficult; last time I used it it did not support most of the wchar_t components of the C++ standard library (i.e. std::wifstream, std::wstring, etc) which made interfacing with Unicode Windows bits difficult.
Do you have anything against MSVC?
I know that I should have commented instead of answering, but I don't have enough reputation.
I want to add that I had to change the links to exe files in [Settings > Compiler... > Toolchain Executables > Program Files] in order to get the version of Community to run.
Also my CodeBlocks from 2016 claimed that it was Unicode but the -municode option didn't work, only the MiniGW update to the version by Community worked.
If you want to use main instead of wmain again, you have to delete -municode option.