clad icon indicating copy to clipboard operation
clad copied to clipboard

Setting up on OSX via conda fails with Expected in: flat namespace

Open vishalsubbiah opened this issue 2 years ago • 5 comments

I am trying to setup clad via conda. I have installed clad via conda-forge. when I run clang -cc1 -x c++ -std=c++11 -load /Users/me/opt/miniconda3/envs/clad_env/lib/clad.dylib sourcfile.cpp, I see the error:

error: unable to load plugin '/Users/me/opt/miniconda3/envs/clad_env/lib/clad.dylib': 'dlopen(/Users/me/opt/miniconda3/envs/clad_env/lib/clad.dylib, 9): Symbol not found: __ZN5clang15PluginASTAction6anchorEv
  Referenced from: /Users/me/opt/miniconda3/envs/clad_env/lib/clad.dylib
  Expected in: flat namespace

c++filt on __ZN5clang15PluginASTAction6anchorEv returns clang::PluginASTAction::anchor()

This is with v0.9 ( but also saw with v0.8)

sourcefile.cpp contains:

#include "clad/Differentiator/Differentiator.h"
#include <iostream>

double f(double x, double y) { return x * y; }

int main() {
  auto f_dx = clad::differentiate(f, "x");
  std::cout << f_dx.execute(3, 4) << std::endl; // prints: 4
  f_dx.dump(); // prints:
  /* double f_darg0(double x, double y) {
       double _d_x = 1; double _d_y = 0;
       return _d_x * y + x * _d_y;
     } */
}

Any suggestion on what I'm missing here? my guess is I either need to rebuild from scratch with two level namespace or i'm missing some dependency in my environment.

vishalsubbiah avatar Aug 24 '21 06:08 vishalsubbiah

Hi @vishalsubbiah, sorry, I thought I have replied...

Can you setting this env variable DYLD_FORCE_FLAT_NAMESPACE=1?

vgvassilev avatar Oct 22 '21 16:10 vgvassilev

@vgvassilev was giving it a try, do i need to rebuild manually with this env var, or should i run DYLD_FORCE_FLAT_NAMESPACE=1 clang -cc1 -x c++ -std=c++11 -load /Users/me/opt/miniconda3/envs/clad_env/lib/clad.dylib sourcfile.cpp

because that gave the same error.

vishalsubbiah avatar Nov 13 '21 09:11 vishalsubbiah

Looks like we have two bugs here. One that I already filed and another that might be involved in system clang unable to run plugins due to security protection. I am still investigating.

brew install llvm@7
cat ../T.cpp 
#include "clad/Differentiator/Differentiator.h"

double sq(double x) {return x*x;}

extern "C" int printf(const char*,...);
int main () {
  auto dsqdx = clad::differentiate(sq,"x");
  printf("%f\n", dsqdx.execute(1));
}
/usr/local/opt/llvm\@7/bin/clang -x c++ -std=c++11 -fplugin=/Users/vvassilev/miniconda//lib/clad.dylib -I /Users/vvassilev/miniconda/include/ -lm -lc++ ../T.cpp 
./a.out 
2.000000

That would install clang that's compatible to the conda version of clad while the other bugs are resolved/investigated.

vgvassilev avatar Nov 13 '21 18:11 vgvassilev

looks like on mac, llvm7 is only supported till catalina:

llvm@7: This formula either does not compile or function as expected on macOS
versions newer than Catalina due to an upstream incompatibility.
Error: llvm@7: An unsatisfied requirement failed this build.

vishalsubbiah avatar Nov 13 '21 22:11 vishalsubbiah

In that case, you can install the version of llvm that you can (anything up to llvm12 is supported) and then you should make sure you install a compatible version of clad (conda info clad) should offer plenty of choice.

vgvassilev avatar Nov 13 '21 22:11 vgvassilev