CMake - combine multiple libraries into one - cmake

Let's say I have executables A, B, C, and I have external libraries X, Y, Z
SET(EXTERNAL_LIB X Y Z)
TARGET_LINK_LIBRARIES(A, ${EXTERNAL_LIB})
TARGET_LINK_LIBRARIES(B, ${EXTERNAL_LIB})
TARGET_LINK_LIBRARIES(C, ${EXTERNAL_LIB})
However, if I visualize this (using cmake --graphviz option, I get a complex bipartite graph with edges from each of the executables A, B, and C to each of the libraries X, Y, and Z.
I was wondering if there's a way to combine all the libraries into one.

All of this depends a bit on your platform, compiler and the type of libraries:
In case, you can build X, Y, Z yourself: Create a new project XYZ, built from the aggregated source files of X, Y and Z. But I guess if this was possible, you would not have asked on SO.
If you can not rebuild the libs and they were built as a shared libraryy (dll/so), you are out of luck. You could try to write a wrapper library, which hides all the internals of X, Y and Z and which will be used by applications A, B and C.
If they were build as static libs, take a look at this SO question. Because a static lib is not much more than an archive of object files, you may be able to extract the object code from each lib and recombine them with ar.
But why would you? Suppose you get a fourth application D, which only depends on X. Then you would need the separate library Y anyway (unless you prefer to unnecessarily link with all libs).

Related

Attempting to make an algorithm that translates to different numerical bases

I'd like to make an algorithm, f, that takes a, x and y, and returns b in base y as opposed to a in base x. I can't seem to make sense of how to do this, and I've made multiple attempts. How does one go about that?
def f(a, x, y):
pass # should convert (a in base x) to (b in base y)

Gurobi- How to use indicator constraints in version 7.0?

The newest version of Gurobi allows for the use of indicator constraints but I can't figure out from the user manual how to implement these with the Matlab API.
Unfortunately, indicator constraints are not supported by the Gurobi MATLAB and R interfaces. These interfaces use a matrix representation. For example, for a linear program in canonical form:
max ct x
Ax = b
x ≥ 0
The interface takes the matrix A and vectors b and c, and returns the optimal solution. Unfortunately, this means that high-level representations like piecewise linear functions or indicator constraints are beyond the scope of the MATLAB and R interfaces. They are available for Python, if that helps.

Modulo operation with PBC library

I would like to know how it could be possible to compute a modulo operation over Zr elements with PBC library ?
The library does not offer a primitive to do it directly.
As this library is based on the GMP library, an idea is to use its primitives.
Especially the function mpz_powm(r, b, e, m). The user's guide says is sets r = (b^e) mod m. IMHO, if you set the e to 1, it should produce r = b mod m.
You also have converting functions in PBC for GMP :
element_t to mpz_t
void element_to_mpz(mpz_t z, element_t e)
mpz_t to element_t
void element_set_mpz(element_t e, mpz_t z)
I'm working on trying this, I'll update this answer with a MWE as soon as I can.

Convert fit(X, Y, 'smoothingspline') from Matlab to C or Objective-C

I can't run Matlab coder on this function
function FT = fitsmooth(X, Y)
FT = fit(X, Y, 'smoothingspline');
because I get this error:
??? The function 'fit' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.
I need this functionality in an iOS app I'm building that incorporates an algorithm already written in Matlab.
Any idea how I can convert fit(X, Y, 'smoothingspline') to C or Objective-C, where X and Y are one-dimensional arrays of the same length?

define / declare variable in Scilab`

I would like to ask how I can define / declare a variable in Scilab. In some PDFs that I read, it says that I can just type it in and Scilab will take care of the declaration. Not so. I want to set up a matrix equation of something like:
Ax + By + Cz = D
Mx + Ny + Pz = E
Rx + Sy + Tz = F
And then I want to get the general value of x, y, x in terms of A, B, C, D, E, F, M, N, P, R, S, T. I remember this is possible with Matlab. And later on, I want to plug in these values to get actual numbers. Please help.
Scilab is much more oriented at numerical computation than algebra solving, but you can still do it.
In your case you first should define the system in the form M1*x=M2, being M1 upper triangular.
I suggest you look at help for solve() and trianfml(), there are nice examples.
After that you can evaluate the expressions giving any value you want for A, B, C, ..., using evstr()
For symbolic algebra, I recommend Wolfram mathematica, Maple, or Maxima (this last one is open-source like Scilab)
OK, this is what I found. SciLab requires "symbolic math toolbox" in order to do symbolic math. the scimax/overload toolbox (by Calixte Denizet) can do that by integrating Maxima with SciLab. however, it is only available on Linux/Unix OS. another way to do it is the OVLD/SYM toolbox (by the deceased Jean-François Magni) which works with Windows (even Win 7). however, support for this toolbox has ceased due to its author's demise. the installation guide on spoken-tutorial.org no longer exists. thus, I am left with using Maxima by itself to solve symbolic equations and calculus problems.