how to integrate matlab compiled code into c++ in Debian system - c++

I have been trying to use Matlab compiler SDK to packaging my Matlab program as C++ shared library in Debian system. I have got the folder including test.c, test.h, test.so (test is my Matlab program name), and I have installed the Matlab_runtime in the Debian system. I have set the variables LD_LIBRARY_PATH_ and _ XAPPLRESDIR_ as required in the readme.txt _ *( _ replace MCR_ROOT by the directory where the MATLAB Runtime is installed on the target machine.
(1) Set the environment variable XAPPLRESDIR to this value:
MCR_ROOT/v91/X11/app-defaults
(2) If the environment variable LD_LIBRARY_PATH is undefined, set it to the concatenation of the following strings:
MCR_ROOT/v91/runtime/glnxa64:
MCR_ROOT/v91/bin/glnxa64:
MCR_ROOT/v91/sys/os/glnxa64:
MCR_ROOT/v91/sys/opengl/lib/glnxa64_)*
.
I edit my main.cpp include test.h. when I try to compile the main.cpp use _ gcc main.cpp -o main_, I got the error as follows:
In file included from main.cpp:2:0:
test.h:15:22: fetal error: mclmcrrt.h: No such file or directory
#include "mclmcrrt.h"
I know that mclmcrrt.h is in the package of Matlab_runtime, it means I failed to link to the library of Matlab_runtime. Anybody knows what should I do to make my main.cpp compile successfully? I tried two days to work on how to connect to the Matlab_runtime library, but still failed. I am a beginner to linux. Great thanks if anyone can help.

This is a compilation problem, not linkage. Your compiler does not know where mclmcrrt.h is. Please help it find it by telling it where it is:
gcc -I<the_folder_where_mclmcrrt.h_lives_in> ...

Related

How to compile a cpp file with the alglib library?

I'm working on a C++ code on linux that needs some special functions which can be provided by alglib: https://www.alglib.net/download.php. The thing is, i'm new to Ubuntu so I don't know how to install the library or execute the files I need for my program.
The library's manual (https://www.alglib.net/translator/man/manual.cpp.html#gs_attaching) explain that you should just pick the packages you need and add them to your project, so I downloaded the tgz file and added specialfunctions.h, and executed it like this:
#include<math.h>
#include<stdio.h>
#include<specialfunctions.h>
But when I run the compiler through terminal I get this error:
analitica.cpp:3:9: fatal error: specialfunctions.h: No such file or directory
3 | #include<specialfunctions.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
Someone has a hint of what i'm doing wrong?

Mosquitto.h not such file or directory

I am working on a c++ project using mosquitto library on github. I am trying to compile the C++ on a windows computer on the command line; however I keep getting error
Fatal error: mosquitto.h: no such file or directory
include "mosquitto.h"
I have installed the mosquitto library in the windows system, underneath:
C:\Program Files\mosquitto\devel\mosquitto.h
Is there something else that I have to do as well in order to compile the cpp from the command line. How do I tell g++ the whereabout of the mosquitto.h file. So I can compile on the command line
Thank for your help I am new to C++.
I managed to solve this question, I had o copy the mosquitto.h into
C:\cygwin64\usr\include
Then when I type g++ nameOfFile it compiled

How to install nan.h on cygwin for g++?

I can't build this simple program on cygwin:
#include <nan.h>
int main(){}
I get this error message:
$ g++ a.cpp
a.cpp:1:17: fatal error: nan.h: No such file or directory
compilation terminated.
Is it possible to install something on cygwin to get correct nan.h?
nan.h is an obsolete include of old gcc. On Cygwin NAN is defined on math.h
You can not use a software written in 2008
https://boutell.com/fracster-src/doubledouble/doubledouble.html
for such specific issue and just hope than it works out of the box.
You need to figure out where nan.h is located and than Add this path to the includes.
How to make g++ search for header files in a specific directory?

Compilation error: "stddef.h: No such file or directory"

Whenever I try to compile this code it always ends up with this error:
In file included from /usr/include/wchar.h:6:0,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/cwchar:44,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/bits/postypes.h:40,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/iosfwd:40,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/ios:38,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/iostream:39,
from test.cpp:1:
/usr/include/sys/reent.h:14:20: fatal error: stddef.h: No such file or directory
#include <stddef.h>
^
compilation terminated.
The code I was trying to compile is:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World! :D";
return 0;
}
The error is because your gcc-core package and gcc-g++ are not of the same version. Either downgrade one of them to solve the problem or update both the libraries. Updating both the libraries is the recommended way.
I had this error on a fresh MinGW install, it had nothing to do with the installed packages mentioned in the current accepted answer by "Prasanth Karri". In my case the issue was caused by -nostdinc in my Makefile. I actually only needed that compiler flag when building for a different target platform (not when using MinGW) so I fixed the issue by removing that flag from MinGW builds.
When I was incorporating a software library written in C into an existing demo project(used a C++ mbed library) I encountered this problem. The demo project would compile just fine, but after I replaced the existing main file by my own, this error occurred.
At this point I hadn't yet thought about the fact that the mbed library that I needed was written in C++. My own main file was a .c file that #include the mbed header file. As a result I used my normal C source as if it was a C++ source. Therefore the compiler that was used to compile my main file was the C compiler.
This C compiler then encountered a #include of a module that actually does not exist (within its scope), as it's not a C++ compiler.
Only after I inspected the output of the build log I realised the various source C and C++ files were compiled by more that 1 compiler(the c++ compiler). The project used used compilers arm-none-eabi-c++ and arm-none-eabi-gcc (for embedded systems) as seen below.
Compile log:
Building file: ../anyfile.cpp
Invoking: MCU C++ Compiler
arm-none-eabi-c++ <A lot of arguments> "../anyfile.cpp"
Finished building: ../anyfile.cpp
Building file: ../main.c
Invoking: MCU C Compiler
arm-none-eabi-gcc <A lot of arguments> "../main.c"
In file included from <Project directory>\mbed/mbed.h:21:0,
from ../main.c:16:
<Project directory>\mbed/platform.h:25:19: fatal error: cstddef: No such file or directory
compilation terminated.
Of course in a C++ environment cstddef exists, but in a C environment cstddef doesn't exist, in stead it's just C's implementation of stddef.
In other words, cstddef does not exist in the C compiler.
I resolved this problem by renaming my main.c file to main.cpp and the rest of the code compiled smoothly too.
TLDR/Conclusion: When building a C++ project, avoid mixing C files with C++ files(sources and headers). If possible rename .c files to .cpp files to use the C++ compiler in stead of the C compiler where required.
In order to update it, follow below.
If you are on Windows, just run these on command prompt or powershell
Update the package list: mingw-get update
After updating the package list, run: mingw-get upgrade
Source: How to update GCC in MinGW on Windows?
This problem was solved for me as I installed codeblocks with mingw compiler then I copied the mingw folder from codeblocks to C drive and added
C\mingw\bin to the environment variables.
If you try to compile and see a message like, "fatal error: stddef.h: No such file or directory", the error is because your gcc-core and gcc-g++ packages are not of the same version. Rerun the Cygwin install and make sure that you select the highest numbered versions of gcc-core and gcc-g++.
After installing the C++ compiler with MinGW I encountered this problem as well. Apparently, you have to also install mingw32-base. Go to C:/MinGW/bin/mingw-get.exe (my path) and check it for installation at the Basic Setup tab.

Unable to compile program with twitcurl

I want to compile a C++ program with a twitter library, on Linux.
I'm current using twitcurl as the twitter API library and installed g++ and all the necessary files and packages that are listed on the official website: http://code.google.com/p/twitcurl/wiki/WikiHowToUseTwitcurlLibrary
However, when I compile my program using this command g++ twitterClient.cpp -ltwitcurl, I get this error: cannot find -ltwitcurl
I also used CodeBlocks IDE to compile it but got this error: undefined reference to twitCurl::~twitCurl()
`
My code only contains a few lines:
#include <iostream>
#include "Twitter/Twitter.hpp"
using namespace std ;
int main ()
{
Twitter t ;
return 0 ;
}
I've already spent a lot of time on this but am unable to solve the problem. What should I do in order to compile the program on the command-line and CodeBlocks?
$ g++ twitterClient.cpp -ltwitcurl
cannot find -ltwitcurl
This means your compiler doesn't find the libtwitcurl.so.1. in its library directories.
First, make sure you correctly build the twitcurl library and obtained the libtwitcurl.so.1. file with something like this :
svn co http://twitcurl.googlecode.com/svn/trunk/libtwitcurl
cd libtwitcurl/
make
Secondly, make sure you put the file (or a symlink) in one of your compiler's library path :
cp libtwitcurl.so.1.0 /usr/lib/
You can check g++ library paths using the following command :
g++ --print-search-dirs | grep libraries
(/usr/lib/ is usually at the end.)
If you don't want/can't put the file in your compiler's library path, you can also tell it where to find libtwitcurl.so.1. by adding -L/path/to/twitcurl/ in the g++ options, but it is not needed if the file is already in one of the compiler's library path.
You need to specify path to twitter lib:
g++ twitterClient.cpp -L/path/to/lib/dir -ltwitcurl