Converting MATLAB model code to C++ and using in Linux - windows

I have matlab installed in windows based system. I have generated a model for the application.
I want to convert this code to C++ code and use it in a linux based system. I converted this code using auto coder to C code but I am not understanding how to use it in a linux based system.
Please let me know what are the steps to be followed?
Thank You

You have to build a project (or a makefile for linux) around the generated C files. With a decent compiler, you should be able to compile these under Linux as well as under windows.

Related

Go binary file for all platform

I have a .go file and produced the binary file using go build command from Mac. Is there a way to build a binary file which runs in windows,linux,IOS ?
I am aware we can build binary file for each of them by changing the GOOS,GOARCH params but i would like to have a single go binary file which should run in all the platforms . Please help me out of this.
Thanks in advance
No, it is not at all possible in Go or any other programming language (the executable is necessarily tailored to individual platforms and architectures).
However, to cross-compile, some tools do exist which do the cross compiling for you.
This post helps explain how to cross compile with Golang (which is pretty easy at this point).
There's also a Unix StackExchange question, https://unix.stackexchange.com/a/298283/177527, which explains why different architectures require different binaries:
The reason is because the code is compiled to machine code for a specific architecture, and machine code is very different between most processor families (ARM and x86 for instance are very different).
The binary also depends on the OS, as explained here https://softwareengineering.stackexchange.com/a/251255:
Binary Format: The executable has to conform to a certain binary format, which allows the operating system to correctly load, initialize, and start the program. Windows mainly uses the Portable Executable format, while Linux uses ELF.
System APIs: The program may be using libraries, which have to be present on the executing system. If a program uses functions from Windows APIs, it can't be run on Linux. In the Unix world, the central operating system APIs have been standardized to POSIX: a program using only the POSIX functions will be able to run on any conformant Unix system, such as Mac OS X and Solaris.
For Mac (not Windows), you can associate cross-compilation with a tool like randall77/makefat to generate a "universal binary", which will run on any architecture supported by one of the input executables.
This is currently implemented in goreleaser/goreleaser PR 2572, which means the process would be completely automated.

How to extend a com-file into an exe-file in Windows?

I am working on a compiler for a small (toy) language that produces 16-bit com-files, which are executable in Windows XP. However, in more modern releases of Windows com-files are executable only with the help of tools such as DosBox. I would like my compiler to produce exe-files that can be executed directly in Windows 10.
As I understand it, the exe-file needs a header that instructs the system of how to execute it. My idea is to simply add the header at the beginning of the com-file to extend it into an exe-file. I wonder if anyone can recommend an appropriate tutorial that describes how exe-files works. More specifically, I am looking for a tutorial of how to build the smallest possible working exe-file.
I also wonder if there is a difference between exe-files for 32-bit or 64-bit Windows?
Best Regards,
Stefan
You can download description exe format here. You need pecoff.docx file.
Also you may look on this old but detailed doc here.

Microblaze Cross Compile

Does anyone know how to use gcc to compile a bare-metal program for xilinx's microblaze processor?
It is very easy to do this with xilinx sdk, but now I am trying to integrate the microblaze build into a larger build workflow. In other words, I need to be able to do everything command line -- not using the sdk gui.
Most of xilinx support and examples are centered around their sdk. There seems to be limited support on their site for gnu tools but they seem to be focused on users who want to compile a linux kernel for microblaze. I just want to compile a simple bare metal application.
Ideally, I would be able to do something like
$ gcc microblaze_program.c
and end up with a microblaze executable.
Has anyone done this before? Does anyone know of any examples?
SDK creates a makefile - you can just make use of this from the command line.
If you don't open the command-line from Xilinx's provided icon, you need to call $XILINX/settings[32|64].[bat|sh] to set up the environment correctly first.

How to build examples using libspotify on windows

I have downloaded spotify API and am trying to build the example code using libspotify on Windows. The build environment seems to apply only for Mac/Linux world (atleast the Makefile seems to suggest that and there are no Visual Studio project files). Any one has any luck in building the sample code on Windows ?
Even the basic stub example uses pthreads which is not available on windows. Since all their examples assume a POSIX compliant OS (which windows is not) I'm afraid you will not be able to build them on windows (natively). If you want try then take a look at Cygwin.
However, you can still use the include header file and the provided dll/lib to link against and develop applications. The library calls made in the examples are still valid - just not the examples themselves.

Compiling Visual C++ code in linux

I have written a code in visual c++ , which is a sort of GUI used in virtual com PORT connection. However , i need to run that code in linux so that i can make it an open source. Since , visual c++ doesn't work in linux, I need to find out some alternatives.
So, please me what all alternatives I have
Thanks for your valuable time..!!
i need to run that code in linux so that i can make it an open source.
No, you can license code as open source without it running on linux.
If you simply want your code to run under linux you need to learn how to port from VC++ to Linux/GNU. It's not simply a matter of re compiling it.
See the following URL for advice and google search for more if required: http://www.johndcook.com/blog/2008/05/29/porting-visual-c-code-to-linuxgcc/
In my experience you can get a looooong way with
http://www.winehq.org/docs/winelib-guide/winelib-toolkit
winemaker (doing things as making all your includes case-sensitive correct on Linux)
winegcc (linking to the winelib runtime libs so you can have _WinMain and stuff like that just work)
Of course there are libraries that simply don't exist. Also, installing an SDK can be daunting; winetricks.sh is very helpful in that department. Also, you can consider 'XCOPY' deploying the SDK into your linux build tree and working with that;
This has successfully let me cross compile MSVC projects linked with 3rd party windows libraries in the past. Note minor incompatibilities due to having slightly different linkage semantics with gcc/GNU ld by default; expect this to affect areas like RTTI and exceptions thrown across DLL boundaries).
YMMV
Edit I want to confirm the fact that you can have perfectly valid opensource code for windows only, and you can build it using Visual Studio too. If you want to be nice to your (prospective) contributors, make sure you only depend on Visual Studio Express C++ (not MFC, e.g.) but hey, that's really up to you!
which is a sort of GUI used in virtual com PORT connection
This will be probably hardly portable (because of the BIG differences how virtual ports and GUI are handled in linux and windows - unless you used some cross-platform library already in Windows).
You can release your code as OpenSource for Windows only.

Resources