How to run a C++ code in Matlab [duplicate] - c++

This question already has answers here:
Call C++ code from MATLAB?
(4 answers)
Closed 8 years ago.
I have codes which are written in C++ and I would like to use them in Matlab. In my folder I have these files:
do_it.cpp
hist (I guess it's a binary file)
hist_lebesgue.cpp
hist_lebesgue.hpp
tools.cpp
tools.hpp
The program is supposed to make a pdf distribution of your data set.
I was told that to run the code in Linux (I guess by C++ compiler) you need to call the binary 'hist' from the linux commandline. If you are in the
folder where the binary lies then you need to type for example
['./hist 1000 2 path_to_file'].
path_to_file is the path of your data file.
Now I want to use this code to run it in Matlab. Could someone please help me how I can do this. What should I type in Matlab's command Window?
PS. I am using mac.

Assuming you use Windows OS X: You can't run a Linux executable on Windows OS X. You have two options:
Compile the program for Windows OS X with the MinGW OS X version of gcc / g++.
If that doesn't work, or you find it too difficult: Install Linux (e.g. Debian) in a virtual machine (e.g. VirtualBox), and install the Linux version of Matlab in it.
EDIT: Once you have installed the compiler on your system (I trust you can find tutorials for that with Google), you could try this command for compiling the program:
g++ hist_lebesgue.cpp tools.cpp do_it.cpp -o hist
I can't promise it will work though, since I don't know the source code and can only guess how to compile it. You should ask the person who gave you the source code for instructions how to compile it.

Related

How to compile C++11 for MacOS and Windows on a Linux machine?

I'm using Fedora 29, and I've been happily using sublime text to compile/build and run C++ code that runs on this machine.
I now realize that the compiled program is not portable. It will only run on Linux. It won't run on Mac or Windows.
After some research, I found out that Mac uses a different format than Linux does. This info was backed up after repeating the experiment as well as compiling the same source code on Mac (which worked fine).
Question
Is there a way to use sublime text on Linux to compile code (C++ or other) that will run on other operating systems (i.e MacOS and Windows). I do not mind compiling the code 3 times, one for Windows, one for Mac, and one for Linux.
Notes
Note1: I want the code to be compiled in C++11!
Note2: I have already added the C++11 build, and have been using it.
Edit
My post is different from this question here, because I already know why I need to compile in different formats, therefore that is not my question. My question is "how can I do this in sublime text?" or, if that is not possible, "is there an app that will let me do this without leaving my OS?" Thanks in advance! PS: I do not mind compiling the code 3 times, one for Windows, one for Mac, and one for Linux.
Why do we need to compile for different platforms (e.g. Windows/Linux)?

How can use BSDS500 benchmark?

I want to use the Berkeley Segmentation Data Set and Benchmarks 500 (BSDS500) for my segmentation algorithm.
When I run build.m in the source files, I get an error about "sys/times.h doesn't exist in MSVC". There is also another header file that needs ieee754.h.
I googled a lot and find that running the code on Linux may could help, But I doubt. Now I have some questions:
Is there a way to use sys/times.h and ieee754.h in Windows? Does MinGW have these header files?
Has someone run BSDS500 benchmark on windows? How?
The code that comes with BSDS500 is written for MATLAB on Linux or MacOS (these are the POSIX-compatible systems that MATLAB runs on).
If you are on Windows, you can try to use Cygwin to build these binaries. Cygwin adds a POSIX layer in Windows. MinGW by itself doesn't do this, it only provides the GNU tools on Windows. The file sys/times.h is defined in the POSIX standard.
But, IMO, you're better off switching to Linux. Not just for BSDS500, but for everything else too... :)

Mac - c++ - create file.exe [duplicate]

This question already has answers here:
Clang C++ Cross Compiler - Generating Windows Executable from Mac OS X
(3 answers)
Closed 5 years ago.
I've write a c++ project using xcode on a mac.
What I need is to create a .exe file to run the project on windows in anothre pc (no virtualization).
I've read that xcode doesn't provide this service and so I've tried to compile it also in Eclipse (on mac) but I'm not able to get the .exe file.
Is it possible, on mac, to generate a .exe of a c++ project runnable on windows?
Thank you
Yes, it is possible and it's known as cross-compilation. Besides building your own toolchain for doing this, you can use MinGW: Cross compiling with MinGW

Run cygwin-compiled c++ programs on linux

I would like to compile a c++ program in cygwin (on windows) and then run it on a Linux machine.. The reason I don't want to just compile it on Linux is missing libraries, and a huge mess (including restricted access) to install these.
I was hoping I could just compile it, then copy the programname.exe-file to my linux folder and then run ./programname. But that doesn't work. Is there any way to do this?
Short answer is: You can't.
Longer answer: You can, but then you have to set up a cross-compiler that generates native Linux binaries. Or use an environment such as WINE in Linux.
The reason you can't just copy an executable file from Windows, even when compiled with GCC, is that the file have a specific format that is not seen as executable on Linux.

How to compile a .cpp file into a Windows executable (.exe) file in Linux

I make this program in C++ using Code::Blocks on Ubuntu. I need to turn it into a Windows executable binary (.exe file), but I don't know how to do this. Is it possible?
If you meant, compiling an executable for Windows on Linux you might find some pointers on how to do that here.
Both the MinGW32 distribution of GCC and Wine should be available for your distribution.
MinGW has instructions and winegcc wraps a similar compiler that comes with the Wine distribution.
I've used both to compile both applications and libraries for Windows.
You could read here on how to compile wxWidget applications on Linux for Windows using Code::Blocks.
This is a fairly unusual question. What you're asking is that you want to develop on Ubuntu, but the target platform is Windows?
My guess is that you have an assignment to turn in. My belief is that you should go to a lab and compile it and make sure it's working.
However, doing some research, you should try mingw at http://www.mingw.org/