PINTERFACE_REFERENCE and MinGW W64 - c

I'm trying to compile my working 32-Bit DLL project which communicates with USB-Devices to a 64-Bit Windows-DLL.
The sources compile fine with MinGW32 but if I try to build them with MinGW W64 I get an error within hidclass.h:
hidclass.h|132|error: unknown type name ‘PINTERFACE_REFERENCE’
I can't find anything about PINTERFACE_REFERENCE so I'd be glad for every hint about this.
Building it in 32-Bit is not an option because it will be used within Java via JNI and I have to support both 32- and 64-Bit JVMs.
I know that I could do minor changes to my code and switch to Microsofts Visual C++ compiler using VisualDDK and the Windows Driver Kit but I'd love to continue using my free toolchain since it works flawless for 32-Bit builds and I don't have to think about licensing issues.

Related

How to compile my program with older versions of libraries for more compatibility

I'm making an application and I want to distribute the executable itself, but when I compile on my computer (using Arch Linux) it compiles with what I believe are the newest libraries available. This creates the issue that when I try and run said program in my vm, the glibc version is outdated. Is there any program or method to compile using the oldest/most backwards compatible versions of my required libraries so that my app works on as many Linux desktops as possible? Or should I just statically link and tank the size? Thanks.

using Clang in windows 10 for C/C++

I am currently learning C, taking a CS50 online class via EDX/Harvard. They have us using Clang inside the CS50 IDE/Sandbox which is cloud-based. They haven't explained how to use Clang outside of that tho. Thus I am wondering; How do I setup clang in windows 10 ? as well as for use with VisualStudio Code?
On Windows, Clang is not self-sufficient, and is supposed to be used in combination with an other compiler: either MinGW (GCC) or MSVC. Clang is going to use the standard library (and other libraries/headers) of that compiler, since it doesn't ship with ones of its own.
If you want to use it with MSVC and have it installed, running clang-cl instead of cl should just work.
But since you mentioned VSC, I assume you don't want MSVC. Then...
If you want to use it with MinGW and have it installed, use clang --target=x86_64-w64-windows-gnu instead of gcc, and it should also just work. (That's assuming your MinGW produces 64-bit apps. Replace x86_64 with i686 if it's 32-bit.)
If you don't have MinGW yet, you can get a fresh version from MSYS2. Then you have an option to install their unofficial build of Clang instead of the regular one, which has an advantage of using --target=x86_64-w64-windows-gnu automatically (so you don't have to write it manually), but also takes up considerably more drive space, and used to be a bit unstable for me in the past.
Expanding on HolyBlackCat's answer. The simplest way to get up and running using clang is to download Visual Studio (not code) and choose the following toolsets during its installation-
Select "Desktop development with C++"
Under "Desktop development with C++" also select "C++ clang tools for windows"
Click install and clang will be usable to you through the commandline, just like the CS50 terminal. You usually won't have to worry too much about playing with extra cmdline options other than the ones cs50 has taught you.
To create a C project in VS with clang-
Create an empty C++ project (don't worry it's just named C++ but will work just fine with C - with the C compiler - not C++ compiler)
Go to project properties by right clicking on the project name and clicking properties
Set the platform toolset to LLVM - Clang in the project general config
Of course, this is not a silver bullet and will not guarantee an identical experience to development on linux. But if you're a beginner, you most likely will not notice any differences and this is a quick and easy way to get started with C dev on windows.
Also remember, once you have VS + Clang installed by following the above steps - you can also write code in VSCode (though it might need some configuration - specifically, you've to point it to the directory where the header files are) and use the terminal with clang to compile.

Will a program written in visual studios 2017 run in a linux or unix environment?

I'm currently very confused about something. I'm currently programming in C, and I'm confused about whether or not that counts as a Unix or Linux environment. Do I actually need to download a port of linux or am I good to use visual studios? The problem is the program I write will be graded via linux/unix.
There isn't a short answer to your question. Consider:
Visual Studio 2017's C++ toolchain, by default, only generates Win32 PE executable files (*.exe, *.dll, etc) which only run on Windows Vista or later (Windows XP support requires an optional VS component).
Linux cannot run these Win32 PE executables by default, though you can install Wine to attempt to run them on Linux installations on the same CPU instruction set. Wine enables Linux to run Win32 PE executables and also provides a Windows-like runtime environment (registry, simulated C:\Windows path, etc) for them to run in: https://www.winehq.org/
Visual Studio 2017 can cross-compile to Linux, macOS, iOS and other operating systems using two different approaches:
Visual Studio 2017's preferred method is to use remote build-servers: you would have a Linux or Macintosh computer on your local network that runs a build agent process which then builds the software on that remote machine, keeping the build toolchain on the Linux/Mac, and even debugging support by running the program on the remote machine with a remote debugger attached.
Microsoft's C++ team wrote a blog post demonstrating how to target Linux using this approach here: https://blogs.msdn.microsoft.com/vcblog/2017/04/11/linux-development-with-c-in-visual-studio/
The other approach is to use a custom makefile using a cross-compilation toolchain running on your local machine. You may need an environment like Cygwin or MINGW installed.
Excepting Wine, all other options assume your C++ code is actually portable: that you don't use any platform-specific APIs (i.e. you stick to the C++ standard library) or that you are using platform-specific APIs with conditional compilation.
Also remember that "Linux" is not a single platform: a binary executable built for Ubuntu 16.0 x64 might not work on RedHat x64, and especially won't work on FreeBSD or OpenBSD (which are not Linux, but a form of Unix).

How can I duplicate my Linux C environment in Windows with CLION?

I've been coding (C) directly in my production environment for a casual game I'm hacking together. The environment is:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
The GCC version I've been using is as followed:
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
My Windows environment that I want to make my development environment is:
Windows 10 Pro 64-bit, Intel
So, I'm not an expert on duplicating this for gcc or with C. I have CLION, which does support both C and C++, but pretty much everything out there is tailored for C++ or Visual C++ or whatever. I feel a bit outdated, but want to get a working environment so I can actually compile outside of directly in the shell.
As it stands, I use CLION to do everything, but upload the source files to the shell and then compile. I have tried to install CMake with MinGW, but have failed. Any help is much appreciated!
How can I duplicate my Linux C environment in Windows with CLION?
Since you are developing a game, which requires much more than what the standard C11 programming language defines (read n1570) you probably cannot.
The simplest approach is to install Linux on your laptop (perhaps in some VM).
Alternatively, perhaps the fellow members of your game project are all using some particular toolkit which happens to be ported to Windows (e.g. SDL, Qt, etc...). Then you might try using it.
Notice that CLION is not a compiler but an IDE (it uses an external compiler, perhaps GCC disguised as MinGW).
BTW, even on Windows (and of course on Linux also) you can (and probably should, at first) compile on the command line. You might want to use some build automation tool.

What is the difference between Orwell's MinGW and TDM Dev-C++ versions?

I am a newbie at this and yesterday I installed Win 8.1 x64 so I would like to use the most suitable program for making my tasks in C/C++.
Thanks
MinGW supports only 32 bit binaries, TDM supports 32 and 64 bit binaries (with usage of MinGW's API's).
If you need a good GCC for Windows, with the drawback of 32 bit only,
use MinGW.
If you want to build 64 bit binaries too, you can use TDM.
Both released GCC 4.8 approximately at the same time, so there's no real difference in up-to-dateness.
My recommendation: Use the 3rd alternative: MinGW-w64 instead - it's a extended MinGW with support for 64 Bit. See here for a short description of MinGW-w64.
Whatever choice you make, better use official developers website for downloading (not Orwell's) to get most up-to-date version.
MinGW
MinGW-w64
TDM-GCC
Btw., you'll find a good overview there, what makes one special about the others.
NB: the homepage of mingw-w64 used to be on sourceforge but is now at http://mingw-w64.org ; links have been updated accordingly.
For those interested in 32-bit binaries:
Note the code::blocks IDE comes with MinGW, but the compiler is the 32-bit version of TDM-GCC. The TDM version has static runtime linkage by default which makes executables portable to systems without MinGW installed. The TDM-gcc compiler also seems to implement the latest gcc version faster than the other projects.
The MinGW distribution also doesn't use posix emulation to access threads in Windows (unlike MinGW64 or TDM64). There is a separate download source for the headers providing C++11 compliant and functionality for MinGW.

Resources