I have a LibraryLink project, which became more and more larger(about 50 LibraryLink wrapper functions, 8000 lines ANCI C code). Curently, I just use a simple *.c file to organize it as follows:
#include " WolframLibrary.h"
/*Part 0 including head files*/
#include <math.h>
#include <stdlib.h>
#include <xxx.h>
/*Part 1: functions declaration*/
int func1(int a, int b);
xxx();
/*Part 2: LibraryLink wraper functions*/
DLLEXPORT int func1(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res){}
DLLEXPORT int func2(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res){}
/*Part 3: auxiliary function for LibraryLink functions*/
int func1(int a, int b){}
void func2(int a, int b){}
when I need to compile it, I used the following method:
Copy the total code to Mathematica notebook with src = all_code_of_C_file, and compile it with CreateLibrary[src, "lib_link"]
Obviously, it is not easy to maintain and organize this project via the above method.
CreateLibrary[{"file.c"}, ...]. Writing code into a string is just for quick and dirty experimentation and doesn't support all features, e.g. doesn't allow C++. In fact you don't even needCreateLibrary. Use the option"ShellCommandFunction" -> PrintinCreateLibraryto see the compilation command line it uses. If you want you can now put it in a makefile, or use any build system. – Szabolcs Oct 27 '16 at 06:33MImageyet and requires fixing the underlying datatype of tensors: i.e.{Real, _, "Constant"}is allowed for arbitrary rank real tensors, but{_, _, "Constant"}isn't for arbitrary rank arbitrary type tensors. – Szabolcs Oct 27 '16 at 06:50CreateLibrary[{file1, ...}, name]compiles a number of C source files into a library." Why don't you try this first? Personally I don't find makefiles convenient with LibraryLink because I have to deal with differences between operating systems and compilers myself. But if you really want a makefile, useCreateLibrary[..., "ShellCommandFunction" -> Print]to see the command Mathematica uses to compile your library. You can run this command yourself without Mathematica. – Szabolcs Oct 27 '16 at 06:53MTensordata structure with the help of the built-inArrarPad. For instenace, I have some ragged vectors{1,2,3,4}, {11,22,33},{111,222,333,444,555}to pass, I would usetensor = {{1,2,3,4,0}, {11,22,33,0,0},{111,222,333,444,555}}and corresponding lengthlen = {4,3,5}. – user123 Oct 27 '16 at 06:57*.fileto some independent filesaa.c bb.c ee.c,..., then applyingCreateLibrary[{aa.c,bb.c,ee, ...}, name]to generate a library. – user123 Oct 27 '16 at 07:03