Tag Archives: g++

Compiling a Matlab C code with GCC/G++

In this post, I am sharing how to compile a C code generated by Matlab C coder with GCC compiler. Let me explain with an example.

1. Generating a C code with Matlab C coder.

I will use a very simple Matlab code, and the below is the code

function y = add_coder(a,b)
y=a+b

With the Matlab C coder, let’s auto-generate the C code. You have to specify the types of variables and some other options. If you just read the dialog box, it might not be difficult.

As a result, you can see this kind of result. If your Matlab version is not 2015, it might be little different, but its big flow is almost same.

directory_matlab_coder

 

2. Let’s compile the code generated by Matlab C coder

This is my main.cpp file that is modified from the auto-generated main.cpp by Matlab C coder

#include "rt_nonfinite.h"
#include "add_coder.h"
#include "add_coder_terminate.h"
#include "add_coder_initialize.h"
#include "stdio.h"

int main()
{
  /* Initialize the application.
     You do not need to do this more than one time. */
  add_coder_initialize();

  /* Invoke the entry-point functions.
     You can call entry-point functions multiple times. */
  double a=10;
  double b=20.0;
  double y;
  y = add_coder(a, b);
  printf("y: %lf\n",y);

  /* Terminate the application.
     You do not need to do this more than one time. */
  add_coder_terminate();
  return 0;
}

I located this main.cpp file with other all codes.

Now let’s compile all codes. Just compile main.cpp with all other cpp files. like this.

compilation_example

 

I am attaching all related files as a zip file. <Download>

 

Isn’t it easy??!!!

Have a good day~~!

libstdc++.so.6 error when using cross compiler in debian (e.g. ubuntu)

When I compile a source code for Beaglebone black (arm processor) in my ubuntu 12.04 local computer, I met the following problem.

error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

The solution is !!

Copy the below text

” deb http://www.emdebian.org/debian unstable main ”

and, go to the package source folder.  /etc/apt/sources.list.d

Then, paste the text in a source list file (e.g, lubuntu-desktop-ppa-precise.list)

Then update or install all necessary files like this.

# apt-get install build-essential
# apt-get install libc6-armhf-cross
# apt-get install libc6-dev-armhf-cross
# apt-get install binutils-arm-linux-gnueabihf
# apt-get install linux-libc-dev-armhf-cross
# apt-get install libstdc++6-armhf-cross
# apt-get install gcc-4.7-arm-linux-gnueabihf
# apt-get install g++-4.7-arm-linux-gnueabihf

 

I got this solution from a reply of this website.

http://derekmolloy.ie/beaglebone/setting-up-eclipse-on-the-beaglebone-for-c-development/

I really appreciate.

I hope this can help your project.

 

-Mok-