MinGW - Header incomplete <netfw.h> - c++

i am developing a networked application in C++ that should be able to add a rule to the windows firewall. I am following this example using the MingW g++ compiler.
The other examples are working without a problem, but this particular example won't work.
The exact problem i am facing, that NetFwRule is not defined in the <netfw.h> header provided by MinGW. When i try to compile that example with MSVC (in Visual Studio) it works flawlessly, since NetFwRule is defined in the header provided by MSVS. However it is absolutely neccessary for the project to use the MinGW g++ compiler.
This particular code snippet as shown in the example link won't work, since NetFwRule is not defined:
// Create a new Firewall Rule object.
hr = CoCreateInstance(
__uuidof(NetFwRule), // <- Problem in MinGW g++, but in MSVC it just works
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(INetFwRule),
(void**)&pFwRule
);
So what needs to be done in order to make this work using MinGW?
FYI: I have MinGW 32 bit with posix thread for the i686 architecture installed.
g++ --version gives g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
The error message is: 'NetFwRule' was not declared in this scope
In fact it really is not declared, since the <netfw.h> of MinGW does not declare NetFwRule. MSVC however does.

Your GCC was too old.
You can get a newer version via MSYS' pacman, or download a standalone build, for example from http://winlibs.com/ which will work just as well if you don't need MSYS2.

Okay, I have tried to use MinGW 64 bit just as IInspectable suggested, but that does not work either - the netfw.h header still does not provide NetFwRule. However i have installed g++ along with MSYS2 (the version that rustyx is using), which just works as expected. So if anyone faces the same issue I would suggest to use MinGW along with MSYS2 and not standalone.

Related

Can't build and run in C++ Codeblocks

So I just recently downloaded a C++ IDE called Code::Blocks and made a new project. But when I tried to Build and Run it, the code gave some errors. I know that it isn't a problem with syntax or anything like that because I ran the default code that Code::Blocks provided. The error is the following:
Project/Target: "firstcpp - Debug":
The compiler's setup (GNU GCC Compiler) is invalid, so Code::Blocks cannot find/run the compiler.
Probably the toolchain path within the compiler options is not setup correctly?!
Do you have a compiler installed?
Goto "Settings->Compiler...->Global compiler settings->GNU GCC Compiler->Toolchain executables" and fix the compiler's setup.
Tried to run compiler executable 'C:\MinGW/bin/gcc.exe', but failed!
Skipping...
Nothing to be done (all items are up-to-date).
It seems to me like there is some kind of issue with the C++ compiler, but I thought Code::Blocks already came with a C++ compiler, so I'm not too sure what the issue here. I also followed their instructions to go to Settings->Compiler...->Global compiler settings->GNU GCC Compiler->Toolchain executables, but I'm not too sure what they mean by fix the compiler. Here is a screenshot of what I'm seeing:
Also here's info on my PC if you need it:
At this point I'm not too sure what to do to fix this problem. I have asked my friends about this problem(they have already successfully downloaded and used Code::Blocks), and they said that they never encountered this problem while they were installing it.
You need to ensure that you have a working installation of the GNU Compiler Collection, and that the paths you select for your toolchain exist.
If you don't already have GCC Installed, the easiest way would be to download a Code::Blocks distribution that comes pre-bundled with MinGW from the download site. However, it's also possible for you to install GCC through other means, such as:
Installing GCC with MinGW through msys2, or
Installing GCC with scoop install gcc on Windows
In either case, you need to select the installation path that contains the bin directory when setting up the toolchain in Code::Blocks.
In case you didn't notice, C::B formed the path to compiler with both "\" back slashes and "/" slashes, which simply isn't a valid Windows path !!
Slashes are used in Linux not Windows! But for some reason C::B is not getting this. And probably your Mingw is well set !!
C:\MinGW/bin/gcc.exe should be C:\MinGW\bin\gcc.exe
I had pretty hard time trying to fix this in win 7 32 bit/C::B version 20.03 but with no success, i checked all available options and settings, and actually i started to think that it's a bug.

Why does mingw-w64 support strcpy_s() while tdm-gcc fails compiling that call?

I'm trying to compile an open source library from bitbucket for various platforms. Compiling for Windows works only using the mingw-w64/32 4.8 compiler. Other compilers like tdm-gcc 5.1 fail at those lines calling "strcpy_s", stating they are not defined in this scope. On Linux, compiling works without a problem using the standard gcc on Ubuntu 16.04. I'm aware of the workaround to replace the (c++ 11) strcpy_s with std::strcpy.
I don't understand why this is happening because the tdm-gcc is even more up to date than the mingw-w64 version.

Which Windows compilers support <future> class

I was trying to run the test code for the future class on Windows but I had several problems. First I tried using the default compiler of Code::Blocks which in my case is MinGW 4.7.1 obtaining the error
error: variable 'std::future<bool> fut' has initializer but incomplete type|
As suggested in this question it seems that
No one has provided the necessary code to make the C++11 thread features work on Windows yet.
Since the question was from 2012 I gave it a try with more recent compilers. I had no luck using both MinGW 4.8.1 and MinGW 5.1
Surprisingly, when I tried the default compiler for Qt Creator which in my case is MinGW 4.9.1 it worked fine.
How is this possible?
MinGW != MinGW
Multiple GCC-for-Windows projects exist, like MinGW, MinGW and MinGW, with different development states (last one supports the most).
Future objects are part of concurrency which got attention in GCC 4.8 and MSVC 11.
C::B uses TDM-GCC, QT Creator MinGW64 - that's the point.

Relationship between gcc, g++, cygwin, and wingw?

I know for my class, I had to install cygwin to get my Netbeans IDE running, but I see options during setup for both g++ and gcc and I am not sure if they are the same thing or not, and where does wingw? is it another compiler, and if so why choose on over the other?
g++ and gcc are the gnu C++ and C compiler respectively. They're really the same compiler with different flags though.
MinGW is "Minimalist Gnu for Windows". It's a port of the gnu compiler to run on Windows.
Cygwin is another port of the gnu compiler (and various other utilities) to Windows. More accurately (IMO, anyway), it's leaving the compiler/programs running on POSIX, and porting a POSIX layer to run on Windows.
As to choosing between them: if you're running Linux, you probably want ot just get a package of gcc/g++ for the distro you're using.
If you're running Windows, it'll depend on your intent. Cygwin works well for porting existing Linux/POSIX code to Windows. If, however, you plan to write code, and just want a compiler, I'd go for MinGW instead.
One other note: the MinGW at MinGW.org hasn't been updated in years. If you decide to go with MinGW, I'd advise getting it from nuwen.net instead (it's updated quite regularly).
gcc will compile: .c/.cpp files as C and C++ respectively.
g++ will compile: .c/.cpp files but they will all be treated as
C++ files.
Also if you use g++ to link the object files it automatically
links in the std C++ libraries (gcc does not do this).
gcc compiling C files has less predefined macros.
For wingw, did you mean mingw? Because MinGW is for compatibility with Windows. MinGW uses GCC/G++, and MinGW is not a compiler, it's basically a stripped version of Cygwin that uses MS libs wherever possible.
Depends upon what you are building;
gcc is for C programs.
g++ is for C++ programs.
I've not heard of wingw.

Install gcc 4.9 on windows and configure it in Netbeans

Preamble
If anything I wrote is not correct, please be so kind and correct me. I am a php developer mainly - I am not into this compiling stuff. I know there are a lot of topics around the www but they seems to be either old/outdated, very complex or links to a bunch of files on sourceforge (I have no clue what files I should download and what to do with them after downloading them).
Searching a couple of days by now
I am researching for a couple of days by now and tried different compilers and settings but I don't get a standalone executable for a c++14 programme.
First compiler
The first compiler I used was cygwin. I was able to compile it with c++14 but on other computers cygwin had to be installed as well as a cygwin dll was missing. I googled and figured out that programmes compiled using Cygwin requires this dll but cannot be included to the programme itself - or did I missed something?
Current compiler
I then switched to MinGW which seems to be a better choice as it allows to compile standalone executables which is correct as I am able to do so. Well, the MinGW setup I downloaded from http://www.mingw.org/ installed among other the gcc version 4.8.1. I need 4.9.1 for c++14.
As the title says I want to configure it in Netbeans but if there is a proper tutorial for a command line compiling it's no problem either but I try to avoid using another IDE as we use it at work, too.
drangon.org
I also heard about http://www.drangon.org/mingw/ but there are tons of links linking to similiar stuff.
My goals
Get a better understanding about gcc and this compiling stuff in general.
Install gcc 4.9.1 (preferred into MinGW as it's currently installed)
Configure it in Netbeans 8.
I suggest you to try MinGW-w64. (Download.)
It's similar to MinGW, but have better multitreading support, can easily compile x64 applications, and what's more important, at this moment it uses GCC 4.9.2.
By the way, MinGW applications require some .dlls to work too. Usually you just provide these libraries with your application, but another option is to add -static flag at linking phase. Applications that are compiled with it do not require any external library files (unless you're using 3rd party libraries that don't support static linking).