I was following a programming example for writing a small application the details of the application itself are not important. The issue or concern here is that within that application the provider is using the POSIX function popen().
The line of code looks like this:
static FILE* fp = popen( "resample mr1789800 r48000 | aplay -fdat 2>/dev/null", "w" );
And they were compiling their code with g++, I don't know what version they were using.
I am working on a Windows 7 x64 platform in Visual Studio 2017 with compiler set to latest drafted standard, all other options are default or standard settings. This is the general scenario.
All of the other code in the providers example is seems to be portable, this is the only piece of code that I've seen that is native to POSIX functionality.
It appears that they are using popen to load a file to an external program and by the looks from the code above it appears that the program is unix based aplay.
If I'm trying to mimic this behavior on Windows using Visual Studio what would be the required tools to use?
Will _popen() do the same thing, meaning are they nearly equivalent? If so, then the second half of the question is if aplay is the program that is opening the audio file, what options are available to me that are for windows that will handle the audio file the same way as the one that is found in a typical Unix type system? If not; what are the differences between the two and where would I go from here?
Related
This question already has answers here:
Can I program for Macs without owning one?
(3 answers)
Closed 3 years ago.
Recently I have been working on creating a game using Visual C++ 2017 and SDL2. I want to make my game accessible to users on all different kinds of systems, not just Windows. I tried starting with making my game also usable on Mac OS, but I cannot figure out any ways of doing this. I figured the best method would be to get Visual Studio to compile my code into a file type like ".APP" rather than ".EXE" since I don't own any form of Mac or Apple computer that can use software made to create apps for Mac. However, I cannot figure out how to change the options in Visual Studio to compile the code into a different file type or even if doing so is possible.
I've searched all over the internet for methods of converting ".EXE" to other file types, using different C++ compilers for compiling into Mac-compatible files, etc. but I haven't been able to find anything that works without requiring a virtual machine or having a physical Mac computer (neither of which I've tried yet since it would take a lot of effort and I'd like an easier solution).
If anybody could tell me how to change the type of file that Visual Studio compiles your code into or if they could suggest a different compiler that works on Windows, is compatible with SDL2, and can compile C++ code into file types that work on Mac computers like ".APP", that would solve my problem. Thank you in advance!
You need to compile your code on all the different platforms you want to support. Using a compiler supported on each of those platforms.
Code compiled on one platform can not run on another (except cross compiling, see below, but that's painful).
Cross compiling is an option on some platforms and with some compilers, but it's usually more pain than gain if you can in any way set up a local tool chain. Cross compilers generate code for a different platform than you are currently running, but getting that working can be hard. And you then also have no way to test your code on the target platform (unless you have one, in which case native compiling would just be easier in the first place).
You should automate the building of your code on different systems with different compilers in your Continuous Integration systen (CI) btw. So you always know after you push a commit, on what platforms it fails and why.
Easiest way forward (IMHO): Buy a cheap Mac. Buy a cheap PC and install Linux on it. Setup a CI system to build all code you commit to your code repository on all your systems (Windows, Mac, Linux) and make it scream at you when the build fails. Also use that system to build installable packages for each platform and again, scream when that fails.
Do the same for all your unit tests.
That's the only serious way to go forward supporting multiple platforms.
I want to learn C++ and I want to know if using Microsoft VC++ will tie me to Windows. I specially need my project to also run on Mac. My projects are all Class libraries and have no dependency to UI. They are just calculations or file/network IO.
I really like working in Visual Studio and Microsoft way overall. So my priority is to go VC++ unless it makes painful to build cross platform apps for Windows and Mac. I mean at the compiler, libraries and language level. I don't want my parallel app to fall apart on certain platforms.
I personnaly use Visual Studio to build my code on Windows and other compilers to build the same code on other platforms (Mac, Linux, Android...).
To be sure you don't get locked with Windows, make sure (at least, it's not exhaustive):
You don't use any win32 API (prefer cross plateforme libraries like boost for instance for network, file system access...)
You don't use 3rd party libraries only available for Windows
Don't use CString, or anyother Microsoft class. Prefer STL.
Be careful with file system case sensitiveness too! (#include "Foo.h" while file is "foo.h" on disk will work on PC, not under Mac/Linux). Prefer naming ALL your files in lower case.
...
You may want to have a look at CMake. This tool can help you generating compilation project file for the same source to be compiled on different plateform. Then, you can generate vcproj/sln files to compile your code with Visual Studio on Windows, MakeFile(s) to compile it under Linux and XCode project files to compile it under MacOS. If somewone wants to compile you code under Windows with another compiler than Microsoft, it's also possible!
Also note that recent version of VS (2015) propose to compile for other targets that Windows (at least Android). But never tried that.
The compiler itself is pretty standard confroming by know (if you turn off the extensions) and more importantly, you can use the clang frontend (which is the default compiler on Mac) directly from within VS2015, so it is definitvely possible to write cross-platform code in VS (although it's certainly easier to use Windows specific constructs than it where if you'd use e.g. cygwin).
However, the windows API for network I/O is different from the one for Mac, so you should probably use a corssplatform library like boost asio for that.
As far as multithreading is concerned, you can do it in a standard and portable manner using the standard library's functions, classes and synchronization primitives, but the past has shown that they are often not the most efficient way to go. However, in most situations you'll want to use a more highlevel library for parallel programming anyway. The default on Windows is the PPL which is - I believe - not cross-platform, but there are other libraries you can use
Finally, you can use VS to remotely build your applications on Mac or Linux PCs using their local compilers and libraries. However, I don'T know, how well that works in practice.
I'm working on a C++ project in Visual Studio 2013 which is a console app and produces exe file, which I want to run under Linux - Ubuntu. I already tried with wine and the app is working fine , but my goal is to run it with mono . Any ideas how can I achieve this run ?
Mono doesn't execute binary C++ applications, it executes CIL applications. In effect, Mono acts as a Free Software Common Language Runtime and set of development tools. As such, the Mono CLR is a virtual-machine, similar to the JRE, and isn't responsible for executing binary compiled applications.
I'm not certain why you would need to run this with Mono instead of Wine, but if it works with Wine I would imagine you could stick to that. Another option may be to write your C++ code in such a way as to be compilable on any platform, than you can simply compile the C++ program using GCC on GNU/Linux. This way it will run as a native GNU/Linux program which would be the fastest executable time. Another option is to call C++ precompiled code from the Mono Runtime using CppSharp.
I have successfully written a c++ code for finding the names of section headers and their range of virtual addresses in visual studio (working in windows XP) by reading an executable file.
Problem - Now I want to implement the same code in Linux environment.I am not an experienced Linux user , so therefore I am not aware of all the tools Linux provides. Is it possible to execute windows environment specific code in Linux . If yes how will it recognize header files such as windows.h & winNt.h.And of-course I have to make the executable file available in Linux too.
You should be able to write the code you describe portably, using only functions described in the C++ standard. Use std::ifstream, not CreatFile(), for example.
If you can write your program in visual studio with no reference to <windows.h>, then it will very likely run under Linux, too.
On the other hand, if all you are trying to do is to list the section headrs, try objdump -x foo.exe.
I've already googled the **** out of the web in search of a simple way to get data from a connected midi device. I'm using I Visual Studio 2010 on a Win7 64bit PC.
I've already tried libaries like Improv, JDKSmidi, Portmidi
All their example programs compiled with errors and Portmidi did not really provide a useful documentation.
All I want to do, is to read midi input on windows in my program. (Maybe even without an extern libary?)
Take a look at rtmidi. It is small (2 headers and one .cpp file) and very easy to use.
http://www.music.mcgill.ca/~gary/rtmidi/
If you are on windows, you may use Windows multimedia API.
It's quite simple.
MSDN MIDI Reference
There are several articles on codeproject :
http://www.codeproject.com/Articles/2771/Wrapper-Library-for-Windows-MIDI-API
http://www.codeproject.com/Articles/36313/MIDI-Star