grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.53k stars 319 forks source link

Windows: Building Faust static library with LLVM JIT support #196

Closed christoph-hart closed 6 years ago

christoph-hart commented 6 years ago

Hi,

I would like to build a static library with the Faust JIT compiler using LLVM in order to embed it into my app but I am struggling to get a minimal project working on Windows x64 (macOS already works).

I've sucessfully compiled LLVM 5.0 from the sources and generated the staticlib VS solution files in the faust/build directory. They build correctly, however I can't call any of the functions defined in faust/dsp/llvm-c-dsp.h (gives me linker 2019 errors, however a dump of the included symbols show that they are in the exported library).

Also, I can't find any place where the static library links with LLVM. Is this step deferred until you link the final executable?

Interestingly, if I build the dynamic library version of Faust using the dynamic-library target, the getCFaustLibVersion() function is exported and works, but not the more interesting createCDSPFactoryFromString() etc.

I tried to follow the instructions as close as possible, but I am certainly missing something obvious.

sletz commented 6 years ago

I've just fixed symbol export in https://github.com/grame-cncm/faust/commit/18733bf72072a6ab0c1feeef6307dfad21828e0d. So at least the " if I build the dynamic library version of Faust using the dynamic-library" case should now work. Can you test and report?

sletz commented 6 years ago

Note that:

pierreguillot commented 6 years ago

I think you have to link with the microsoft static runtime library. So when you compile LLVM you must ensure that the the library is linked with MT or Mtd. Here what I do:

cd llvm-version.src && mkdir build && cd build
cmake .. -G "Visual Studio 14 2015 Win64" -DLLVM_USE_CRT_DEBUG=MTd -DLLVM_USE_CRT_RELEASE=MT -DLLVM_BUILD_TESTS=Off -Thost=x64
cmake --build . --target ALL_BUILD (--config Debug/Release)
cmake --build . --target INSTALL (optional)

Then, you must compile faustlib with MT or MTd:

-DCMAKE_C_FLAGS_DEBUG=MTd -DCMAKE_C_FLAGS_RELEASE=MT -DCMAKE_CXX_FLAGS_DEBUG=MTd -DCMAKE_CXX_FLAGS_RELEASE=MT

I guess this should be done directly in the CMakeList of the FAUST repository.

And you application with MT or MTd.

christoph-hart commented 6 years ago

@sletz yes, I can confirm that the symbols are exported correctly when applying the fix.

I also noticed that the CMake generator failed to generate the LLVM backend. Hardcoding this in the CMakeFile instead of using the Backend files fixed this (I am sure there's a better solution, but it got the job done).

@pierreguillot I already build everything with MT when possible, but thanks for the hint. I can use both the static and dynamic library in Release mode, I am currently building LLVM with MTd so I can debug the things.

Thanks for the help!