compiling Lua source with host C++ application - c++

I'll be quick:
I have a C++ application that embeds Lua. Until now I have just used a pre-compiled lib that I link to the app. I would like to make a new approach by including the Lua source code and compile from scratch. What all would I need to do?
I'm running gcc v 4.4.3 in ubuntu 11.4
Thanks!

Include the lua source code as included in the library - leave out the .c files which contain a main()
Make the proper #define for your operating system (see the Lua makefile for which ones to use)
Compile.

You need to look into Binding Code to Lua.

Related

Modern CMake (3.8+) - FindCUDA deprecated, what about non .cu files?

I have a C++/CUDA project based on CMake. Currently I'm using CMake 3.11 and CUDA 9.0 and I'm reading that now CUDA is a first-class language in CMake, so I can simply add .cu files and it will automatically call the NVCC compiler to take care of them. Before this, we had to use find_package(CUDA) and so on, but now this is a deprecated feature.
Now the question: how do we compile normal .cpp files that still make use of the CUDA host libraries? cudaMalloc, cudaFree, etc. My solution so far is to set_source_files_properties(file.cpp PROPERTIES LANGUAGE CUDA) but I don't feel this is the right thing to do. Since this file doesn't contain device code, it should be compiled with the GCC compiler including and linking to the CUDA libraries.
Another issue with this approach is that it propagates very quickly to the rest of the project. Say a header file that defines a struct containing a dims3 variable, then every .cpp file that #includes this header will need to be considered as a CUDA file.
how do we compile normal .cpp files that still make use of the CUDA host libraries?
With your regular C++ compiler. There is no need to treat them as LANGUAGE CUDA.
I recently made the switch to CMake's native CUDA support in this repository of mine. I now have:
add_executable(device_management
EXCLUDE_FROM_ALL examples/by_runtime_api_module/device_management.cpp)
add_executable(execution_control
EXCLUDE_FROM_ALL examples/by_runtime_api_module/execution_control.cu)
Both of these use the runtime API (actually, they use my C++'ified wrappers, which use the runtime API - but most of the wrappers is header-only), but the second one has a kernel in it, so I made it a .cu and it gets compiled by CUDA. The .cpp builds and runs fine by plain old GCC.

How to include OpenCV source code in C++ project to make it portable?

In my C++ project I use (3.1) OpenCV Mat for (only) storing and operating matrices (thus only the core module is used).
Now I would like to make the code portable: if a user (running Linux or Windows or OS X) takes my code then he can compile and run it, without installing the whole OpenCV pack.
Moreover, I would like the user to run the fastest version of the code (i.e. compiled in Release mode, Optimizations, etc...).
Could you please suggest a way to do that?
I copied the source code from modules/cores to the project directory but not sure how to proceed.
Thank you in advance for any suggestions!
You could do this by including the static library (a .a file) along with your package and linking to it during compile-time. Building OpenCV with -D BUILD_SHARED_LIBS=OFF as an argument to cmake should create the static files.

VS2012 C++ to XCode

I have written a DLL in VS2012 C++ and did not use anything fancy.
I think I have stayed cross-platform, at least I hope so.
Can somebody tell me how to most easily get it to compile to OSX code?
I think I will have to do some manual work, but I would like to find a pipeline that would allow me to easily upgrade my application both in VS2012 and in XCode without having to write down what I changed and then do the same changes in XCode.
Perhaps I can write one interface for Windows and one for XCode and simply leave the rest of the files as they are???
Thank you very much for the help.
You could:
Create a XCode project with the template: Cocoa Touch Static Library and add the code of the VS12 inside a folder Source.
Create an ObjC class to wrap your C++ code.
Compile the project like a static lib.
Add your static library with the correspond .h to your Xcode Project that will use the library.
Link the library with the dlyb used in your C++ code.
So you will have a VS solution and a XCode project for compile the library.
Here is a template with a UnitTest with simple C++ class and a ObjC Wrapper.

GtkD (the Gtk+bindings for the D language) why compile it?

I've recently been using GtkD with the D programming language to create native applications. I've downloaded all the necessary files and got everything running so i can now compile and produce sample apps.
My question is that in some of the guides it tells you to compile GtkD on the platform you are using but what is the point? Once compiled you end up with a single lib file on Windows (GtkD.lib) and three lib files on Linux (ending in *.a). What are these files for and how are they used? Like i said everything seems to be working without doing anything with these files.
I'm guessing you can statically link these? but what's that for? To avoid compiling the GtkD source each time? I did actually try that using the pragma('lib', 'GtkD.lib') statement but it didn't seem to do anything.
Can anyone shine any light on this or explain why these files are needed?
Yes it's to avoid compiling the GtkD source each time.
Try to use pragma(lib, "GtkD"); rather than pragma('lib', 'GtkD.lib');
It works for me.
source files that are imported aren't compiled, they are only parsed for the symbol names and function signatures (and the templates)
creating libs is to avoid needing to recompile the entire library each time you need to rebuild and the compiler can then only use the .di files for the imports
this stems from the olden days where compiling took ages, and now it can be used to keep a library closed source

C++ Lib/Headers in Emacs

Where could I find C++ libraries in my emacs? I have already installed emacs on my computer and already using it lately. I just want to add boost libraries in emacs so I could use them.
Emacs is a text editor, it doesn't compile your code.
It doesn't know (or need to know) anything about your libraries.
However, there are commands for running the compiler from inside emacs, I've never done it myself, I use command line compiling and makefiles for bigger projects.
I would write the program using the boost libraries (or any libraries) just like normal.
I'm guessing you'd use GCC to compile as you're using emacs to edit.
When compiling you need to tell the compiler (GCC) where to look for the header files and the libraries.
For example,
in your program you will have a line like
#include <library.h>
then compile it using
g++ myprogram.cpp -I/path/to/header/files -L/path/to/library
If your program is more than a couple of files, I would recommend writing a makefile for it and including all the required compiler flags and search paths in the makefile.
You need to supply them in your make script, or you can set an environment value for GCC. Take a look at this question.
You could use CEDET to setup parsing of header files. Please look to my CEDET config for example