How to give lots of header files to MATLAB loadlibrary? - c++

I have a program in C++ and compiled the program into a static library .a file. Now I want to use this library in MATLAB. Seemingly all remaining steps to use it in MATLAB is to give to MATLAB this .a library and the header files using loadlibrary(libname,hfile) command.
The problem is that my program consists of about 200 .h files located in different folders under the main source folder. How can I give all of these header files to MATLAB loadlibrary? I just started to integrating all of the headers into one header file; but is there a better, easier way to this?

This will require some work on your part.
First option is to add additional header files in the loadlibrary command
loadlibrary('mylib','mylib.h','addheader','header2')
You'll need to have a list of all your additional header files.
Alternatively, you can explore the prototype file option instead of ehader file.
See this link for more information.

Related

How do I add user downloaded header files to the list of header files that is present by default in the system?

I have some header files (.h and .cpp files) which I downloaded from the internet. Want to add them to the list of header files that is already there in the system by default.
I know that I can add them to the directory in which my code is present, which uses these header files. I've been doing that for most of my projects. But it is taking up a lot of unnecessary space.
I want to know if there's any way in which I can make these header files, which I downloaded from the internet as standard header files like stdlib.h, iostream etc.
EDIT: What I want to exactly do is this: I have downloaded the stanford cpp library, which has some very useful functions. I want to use them. But I don't want to copy and paste the include files in my project directory every time. Is there a way to make them as standard header files like stdlib.h or iostream? I use a Macbook. For code-editing, I use Atom. For running and compiling the program, I use the command-line -- g++ is my compiler. I am familiar with Makefiles (GNU Make).
Makefiles wrap other compilers; Xcode uses clang; so I'm going to assume you're using that for now.
You want to locate your rule for generating .o objects; and add (from https://clang.llvm.org/docs/CommandGuide/clang.html) the argument
-I<dir> as many times as required to add all your paths.
gcc is basically the same args https://linux.die.net/man/1/g++ ...-Idir to impact <> and "" lookups -iquotedir to impact "" lookups only; and then -Ldir to impact link paths

Main purpose of a Precompiled header file

My dll project is generating, not only DLL and LIB files but, also a Precompiled file header file. What is the main purpose of a PFH file in my project? Can I get rid of it?
Yes you can get rid of it, but it makes compilation notably faster by allowing the compiler to not recompile a ton (there's really a lot of code in there) of Windows SDK headers. MSDN has more details.
It's simply a way of speeding up compilation, by creating a single file containing all declarations and definitions from multiple header files. Often this file is in a post-parsed format, so the compiler don't have to parse it again.

Can you get information out of C++ Lib Files like How you can Get Info out of Jar files?

Are C++ Lib Files binary, or just some sort of container, like a zip file, which contains all of the binary files?
I ask, because I'm curious if I can open a library file (.lib) to get more information about what files are inside of it, similar to how you can open a jar file and look through it in a human readable way.
I ask, because I'm adding some libraries to my lib path and would prefer to know if the lib files contain the classes I'm trying to reference.
As far as I know, a library file is pure binary. So it's impossible to actually 'see' it's contents like a zip file.
If you got hold of some .lib files then it's probable it also came with documentation that explains it's functionality. That would be a good place to check if your classes are present in the library.
EDIT: This question describes a lib file inspector called dumpbin, might be what you need.
A lib file contains the compiled binary of all of the compilation units that are provided by the library. Since you have tagged C++Builder, I assume you have OMF-libraries. You can easily get quite a lot of information out of these, for example all function signatures in the library.
C++Builder ships with a tool called TDump that prints contents of the library in human-readable form. It's located in the bin-directory under the C++Builder installation directory.
The example below shows you how to use TDump to dump contents of a library from the command line:
"C:\Program Files\Embarcadero\RAD Studio\10.0\bin\tdump.exe" library.lib > library-dump.txt
You can find each object module in the library by searching the output for "THEADR". After the THEADR-line you will have a list of all of the dependency files (basically includes) used when the object was compiled. After the dependencies there are the symbols, including demangled function signatures.

Is there a way to programmatically traverse header files?

I have a situation where I am using a library (collection of C++ header files only) that is 80MB in size in my project.
Now, I am only including 3 header files from that library in one of my source codes, but unfortunately each one of those header files include other header files and so on.
I would like to find a way to somehow traverse the header files starting from the 3 header files that I initially include to list all the header files that are being used.
I am trying to do so, so I can only include the necessary header files from that huge library in hope of reducing its size.
GCC has the -M flag (and similar) to generate lists of dependencies. I imagine other compilers have something similar.

why can't i include a static library into a cpp file?

Is there a way to #include "library.a" or it's .so or it's .o inside a cpp or cc file?
I would like to do this because I am using this file inside another file.
#include is for C++ code.
.a, .so and .o files are not C++ code.
It's more likely that you want to #include a C++ header file (typically ending in .h or .hpp), and link an object file.
You can do this in the Visual C++ compiler, using #pragma comment(lib, "libname")- and the similarity is somewhat dubious. However you will have to discover any alternatives for your own favourite compiler.
#include is used for telling the compiler about the functions from a library which you will call in your code, that is to say it includes C++ code. Generally this takes the form of header files which have the function declarations in them.
.a and .so and .o files are compliled code which can be linked into your compiled code using the linker.
Edit: there's an introduction about compiling and linking here
The #include statement basically just includes other source code into the current file. That being said, a static library is not source code and cannot be included in this manner. Static (and shared) libraries are instead linked into the project after all the compiling is done.
What you have to do is to include a file containing prototypes to the functions you are going to be using. This way the compiler knows it is there and the linker will sort out the rest.
For more information on how to create and link static/shared libraries, check out this page.
It simply doesn't make sense.
You include the library's code at compile time by linking it.
Normally there's a header file for the library you can include.