Embedding LuaJIT - creating include folder - c++

I have no problems with LuaJIT, it great and easy to switch from good old Lua.
But for now i use folder src from LuaJIT distribution as include for lib.
It is kinda messy because there are makefile, batch scripts, c files, dasc files, src/jit folder with scripts which i know used with luajit.exe e.t.c.
I want to create clean include folder with only h files (and other if needed) for using LuaJIT in c++ windows application as shared lib, but quite don't know what to exclude.
My current exclude list
host folder
jit folder
c files
dasc files
c files
luajit.lib - goes to lib folder
luajit.exp
luajit.exe
luajit.dll - goes to bin folder
makefile
makefile.dep
bat files

http://luajit.org/install.html
It's strongly suggested to build LuaJIT separately using the supplied build system. Please do not attempt to integrate the individual source files into your build tree. You'll most likely get the internal build dependencies wrong or mess up the compiler flags. Treat LuaJIT like any other external library and link your application with either the dynamic or static library, depending on your needs.
Build as usual and then copy into your project the files:
lua.h, lauxlib.h, lualib.h, luajit.h, luaconf.h;
libluajit-5.1.a, or luajit-5.1.dll, or libluajit-5.1.x.x.x.dylib or whatever your platform static/shared library file looks like;
#include headers in project sources and link executables to the library file;

LuaJIT is ABI compatible with Lua, so the regular Lua headers will also work with LuaJIT. The only headers you need are lua.h, luaconf.h, lauxlib.h, and lualib.h. LuaJIT also comes with luajit.h, but it's not required, and doesn't contain anything that isn't accessible via the jit library.

Related

How to use C++ libraries?

I am a Python developer and I have not used C++ since university. I am doing scientific programming with python, mainly. I wanted to try C++ to see if it is better performance-wise.
I am quite new in C++. I have found dlib library, which seemed a good library as it had many interesting features. But when I downloaded it, I found several folder full of .h and .cpp files.
In Python, I would have installed a wanted library using pip or something, then use it in my project using import.
Is there a similar installation for c++ libraries? Or do I have to look among all those .h and .cpp files and decide which ones I need in my project then copy them? Or how do I use the dlib library?
I have searched a lot on google but I could not find any indication on how to use a c++ library or install a new package to be used.
I use Visual Studio Community 2017 and Windows 10 if that matters.
To integrate a library, you need two kinds of things:
header files (usually *.h) with the declarations required to let the compiler know about the features in the library (a little similar to an import statement);
compiled library files (usually *.lib) containing the precompiled executable code itself, to let the linker assemble the final executable file.
In some cases (especially for templated code), a library can be made of header files only. In other cases, the package doesn't contain a ready-made library file and you have to build it yourself or manually include the source files (*.c/cpp) in your project.
Not speaking of the innumerable optional settings that you may have to adjust to comply with the specifics of the generated code, such as function calling convention, struct alignment...
Last but not least, some libraries are connected to at run-time only. They are called Dynamic Link Libraries and involve yet different procedures.
All of this is relatively complex and close to black magic for beginners. If you are very lucky, you will find some library documentation telling you which options to use for your compiler. If you can, start from an existing sample project that works!
For dlib, check http://dlib.net/compile.html.
Be ready for a cultural shock when you will compare to the ease of use of the Python modules.
It is quite a broad question, but I'll do my best.
First of all, in C++ libraries consist of header files and precompiled part (.lib,.dll on Windows, .a, .so on Linux). To use them in your project you have to inform your program (and compiler) about features that library has (by #including their header file) and linker to include that library binaries.
pip is package manager, which automatically downloads, builds and installs library that you want in your system. In C++ there is no such single tool at the moment and there steps must be done more or less manually.
For dowloading you usually end up with git or downloading the zip archive with source (do it here). Once you have sources you have to build it.
In order to achieve multiplatformity libraries usually does not get shipped with concrete build system description (Visual Studio Project on Windows or makefile on Linux etc.), but are created in more general tool CMake, which abstracts them. E.g. dlib does that. With use of CMake (For start I recommend CMake-GUI, which is installed with CMake on Windows) you can generate Visual Studio Project, which later you can open and compile to generate .lib file. How exactly to do it follow dlib compilation description.
Once you have you lib and headers files on your disk you can add headers and .lib to your Visual Project and use as any other C++ library. (Seems old, but should work)
As far as I know, there are no tools similar to pip for C++. What you have to do depends on your working environment and the respective library.
In case of dlib there are instructions on the project homepage for Visual Studio. Basically, it involves compiling the whole library alongside your own project by copying a single source file to it and setting up include pathes.
From http://dlib.net/compile.html:
Compiling on Windows Using Visual Studio 2015 or Newer
All you need to do is create an empty console project. Then add dlib/all/source.cpp to it and add the folder containing the dlib folder to the #include search path. Then you can compile any example program by adding it to your project.
Again, note that dlib will only be able to work with jpeg and png files if you link in libjpeg and libpng. In Visual Studio, the easiest way to do this is to add all the libjpeg, libpng, and zlib source files in the dlib/external folder into your project and also define the DLIB_PNG_SUPPORT and DLIB_JPEG_SUPPORT preprocessor directives. If you don't know how to configure Visual Studio then you should use CMake as shown above since it will take care of everything automatically.
You have to download them, put them in your project directory, and then include them almost the same way you would do in python. You need to include only the .h files.
Example for test.h:
#include "test.h"
Hope this helps!

Xcode 3 ctime declaration issues

I am in the process of porting my c++ engine to mac, and so I used premake to generate an xcode project, which it does fine.
Box2D is built into the engine and one of its files "b2Broadphase.h" is including algorithm from the c++ standard library.
This is giving these errors: ::clock_t has not been declared and so on for all the using commands in the ctime file.
I cannot figure this out because when using premake to build a make file it runs fine and build a perfect library on OSX. Its only Xcode giving these errors.
My guess is that Xcode has not been configured to include the implementation files (.m or .cpp) or it has not been configured to link against a library which you are using. In general, you need to do two things: 1. include the headers 2. link against the libraries with the actual executable objects.
In Xcode, you do this by selecting the project (top-most item) in the file-browser panel on the left, and there is a section in the main area to choose which libraries to link to. You must specifically tell it to link against whichever libs you are using, even if you have imported their headers.
For .cpp or .m implementation files, you need to tell it to include that file in the target for compilation. This can be done either in the build settings (similar place to the lib inclusion) or else when you have a file selected, the inspector panel on the right has a little area for you to choose which targets to include the file in. (you only need to "include" implementation files like this, not .h files)

Where do I place the MySQL C++ Connector files on Mac?

I am trying to install the MySQL C++ Connector on my Mac. I downloaded the tar.gz file from mysql.com, and when I unzip it, I have three text files, one of which is a Readme that doesn't provide much help. Then there is the /include folder which has two C++ header files and then a sub-folder called /cppconn that has another 14 C++ header file. Then there is also the other folder call /lib that contains a Dynamic Library file and two symbolic links to that Dynamic Library file, as well a a .a file. I was wondering where I place these files or folders on my Mac so that I can write a C++ application that can connect to a database? Or if there is a way for gcc or g++ to be able see these files in a location I specify when compiling? Any help would be much appreciated.
I don't know mac specifics, but usually (in linux / unix / windows - I dont expect mac to be any different) you either
put the header files into some place that is in your compilers header path(such as /usr/include), library files in your compilers lib path (such as /usr/lib),
or
you put them anywhere you like (perhaps /usr/local/my_cpp_connector) and then add that path to your compilers search path, both for headers and libraries.
You could also do like
/usr/local/my_cpp_connector/include
/usr/local/my_cpp_connector/lib
but I guess you got the idea at this point.

How to compile openssl for only two functions

I am trying to use openssl to encode a simple string, no need of decrypting it.
I am using the functions
AES_set_encrypt_key()
AES_cfb128_encrypt()
I need I think only the include:
#include <openssl/aes.h>
I couldn't find instructions in the web or in the openssl website about how to compile the source code for a visual studio project. Does anyone know how this should be done?
Can I compile only the code relevant for these two functions?
Thanks a lot
I understand you want to use these functions in your code. You don't need to compile OpenSSL for that.
Install the package on your development machine (if developing for Windows, you can get the latest installer here). It will contain header files you need to include in your code (they will be in c:\OpenSSL-Win32\include\openssl), static libraries you need to link your application against (in c:\OpenSSL-Win32\lib\VC) and DLL your application needs to run (in c:\OpenSSL-Win32\bin).
So, in your code you'll have:
#include <openssl/aes.h>
...
AES_set_encrypt_key(...);
...
AES_cfb128_encrypt(...);
...
Your compiler needs to know the path to header you included (path to openssl directory) so you need to provide it. If you are using Visual Studio, open project settings and add c:\OpenSSL-Win32\include to Additional Include Directories.
In the Linker section, add ssleay32MDd.lib;libeay32MDd.lib; to Additional Dependencies so your linker know which OpenSSL libraries to look for. Path to these libraries - c:\OpenSSL-Win32\lib\VC - add to Additional Library Directories.
Be careful with these libraries: they need to be linked against the same runtime library as your application. Their suffix tells you which runtime library they are linked against: libraries I mention above have suffix MDd which means they use Multi-threaded Debug DLL (/MDd) - so you will include them if your application use the same runtime (check this in Code Generation->Runtime Library setting).
Your application will build now but to run it, your binary will need to have access to OpenSSL DLL libeay32.dll as depends on it. Copy that DLL to system directory or to the directory you're running your app or add path c:\OpenSSL-Win32\bin to Path environment variable.

How to include a C/C++ lib (e.g. libcurl) in a C++ project (IDE: Eclipse)?

I have a problem, I'm working on a C++ project (I'm using Eclipse as my IDE).
Now I want to make use of a C/C++ library, for example libcurl, so I download curl and don't know what to do next.
Must I only include the .h and .c files I need or must I compile it before?
A typical way to use a library (this, of course might differ from library to library) is to include all of the header files from the library, include them as needed, use functions that they provide. Then, when building the application, link the objects with the library object (.a, .lib, whatever the extension). If you don't have the .a or .lib file, then you should build that independently
You must compile it before, then include the h files in your include path (in the Eclipse project). You will also need to find out how to import the library that you compile into your Eclipse project.
Once all that is done, you can make calls to the library after #include'ing the appropriate headers.
Both ways are possible. Compiling to a library is probably easier.