Compile cpp source to run in c support only - c++

I want to ask about a problem about c/c++ compile
I have project need to reuse a library wrote base on Cpp language.
But I need to reuse the library in a project which work on a platform only support c language (UEFI)
I want to ask :
-Is it possible to write a wrap API in C code to call all function in the Cpp library ?
-And After compiled All of these (Wrap API, CppLibrary,My Source project) by C compiler =>Will the build application is working in my platform (UEFI)? "
( Assumption than both Cpp library and My project source in compile in the same compile like (visual c 2013) )
Thank you

You can write a C API to wrap the C++ library, but if the C++ library can't compile and run in a UEFI environment, this won't do you any good.

Related

What's the relationship between Objective-C source code and after clang -rewrite-objc C++ code?

When I write some Objective-C source code, I can use clang -rewrite-objc FILENAME.m to translate this code to C++ source code. What is the relationship between the C++ source code and the original Objective-C source code?
Objective-C is a superset of C (but not C++) so why can Objective-C be translated to C++, not C? When Objective-C code is compiled, linked and run on iOS or macOS, is it precompiled to C++, then linked and so on?
Objective-C can be translated to straight C still. There isn't anything in the ObjC runtime API that requires C++, though the innards are implemented in C++ here and there. I don't think this has changed. The rewriter, however, may be generating C++ simply because that is the most convenient/efficient target to generate.
There is no translation step in Xcode's build process. It compiles native Objective-C code; that is, the ObjC is converted straight to the interim format that the compiler uses to then generate executables, just like C++, C and any other language the compiler natively supports.
The translator exists explicitly because there is no Objective-C compiler in Visual Studio. Prior to the rewriter, a different compiler was used to compile ObjC code into libraries on Windows and then combine those libraries with code compiled in Visual Studio to yield the final applications.
It worked, but debugging was really really complicated because any call stack that walked between the two code generation styles could not be debugged from a single debugger!

Mix C and C++ with CMake

I have a project written in C (on Linux) and now want to use a third-party C ++ library that provides .h and .c source files.
I renamed the .c file to .cpp and then include this library in the C project. However, the following error appears when compiled:
unknown type name ‘class’
Added: The third-party library is here https://github.com/0xmalloc/c-log
The author say it's friendly to both C and C++
There are two options here:
you make your whole project a C++ one - this doesn't mean you need to convert your C code to C++ but rather that you will probably have to touch this and that part of it and also go for a C++ and not C-only compiler
provide wrappers - usually if you write C++ code in C style (no classes etc.) you will only have to do that extern "C" void foo() routine for your C++ functions. However the moment you start working with features that C doesn't support you will have to provide wrappers for your C++ functionality so that it can be exposed to the C part of your application. Such procedure can be from very easy to incredibly complex. For example many modern C/C++ API also provide Python API. In order to do that without having to rewrite everything in Python the authors create wrappers that translate the C/C++ functionality to Python. Depending on how well this is done features of the target language (Python in case we go from C/C++ to Python) can be used to allow better error handling, type checking, readability, native (to the target language) data containers etc.
I do believe that the author of the library misled you since the library is clearly for C++ (the classes in the header are definitely the most obvious thing that just screams C++).

How to use C++ compiler by Matlab Mex compilation tool

I am trying to build a source code bundle containing m files and c++ (cpp) source files in Matlab.
The source folder has a simple Matlab Script to compile all cpp files in one folder:
function compileDir_simple(Cdir)
if nargin<1
Cdir=pwd;
end
files = dir(fullfile(Cdir,'*.cpp'));
oldDir=pwd;
cd(Cdir);
for j=1:length(files)
try
cm = sprintf('mex -largeArrayDims %s',files(j).name);
disp(cm);
eval(cm);
catch
disp(lasterr);
disp('IGNORE if the file is a C++ file which is not a mex file (ie without a mexFunction inside)');
end
end
cd(oldDir);
Inside, it uses "mex -largeArrayDims". However, my problem is, when I evaluate that statement Matlab tries to build the selected files by a C compiler which is contained in MATLAB itself. When I call mex -setup I see:
mex -setup
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
[1] Lcc-win32 C 2.4.1 in D:\MATLAB\R2010a\sys\lcc
[0] None
Compiler:
I installed Bloodshed C++ compiler and added its bin folder ( to the Windows Environment variables, but still I cannot see my C++ compiler in the list of installed compilers. Only Lcc-win32 appears. It will be appropriate to state that it is my first experience on compiling mex files.
A mex file on Windows is just a DLL that exports a function named mexFunction. In principle you can compile mex files with any compiler that can create Windows DLLs.
However, to do so using the mex function in MATLAB requires that MATLAB knows about your compiler. And by default MATLAB only has knowledge of a limited number of compilers. Your chosen compiler is not one of them.
Bloodshed is based on mingw. Which means that you should be able to use the Gnumex project to create a mexopts.bat file for use with your compiler.
However, I would be a little sceptical of using Bloodshed here. It is a C++ IDE and I'm not sure you particular need that. I suspect that all you are looking for is a compiler. In which case you would likely be best served by installing plain mingw.
Bloodshed C++ is not a supported compiler. Check http://www.mathworks.co.uk/support/compilers/R2014a/index.html for a list of supported compilers. Older releases are available from the same page.

compiling Lua source with host C++ application

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.

vcl.h: No such file or directory

I'm looking to compile some old source code in Visual C++. However, the first of many errors I am receiving is:
vcl.h: No such file or directory
This appears to be in reference to the Visual Component Library, native to Borland compilers it seems. I downloaded the free Borland C++ 5.5 command line compiler, but it doesn't seem to contain a vlc.h in its include directory.
How can I resolve my issue? Many thanks.
This old code must have come from C++Builder. If it actually uses the VCL, you won't be able to build it with any other compiler. If there are other VCL includes like classes.hpp, system.hpp, controls.hpp, etc. it is using the VCL.
If it is a console application and doesn't actually use any VCL classes, then you can probably just remove the include, but the chances are slim.
Borland C++ 5.5 and C++ Builder are two different products.
The VCL components are in the C++ Builder product and can't be compiled with Borland C++ 5.5 which is a pure C/C++ compiler (I think OWL is included there).
So you have to get your hands on C++ Builder to be able to compile it.