Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vishalsubbiah opened this issue Aug 24, 2021 · 5 comments · Fixed by #755
Closed

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

vishalsubbiah opened this issue Aug 24, 2021 · 5 comments · Fixed by #755
Assignees
Milestone

Comments

@vishalsubbiah
Copy link

vishalsubbiah commented Aug 24, 2021

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.

@vgvassilev
Copy link
Owner

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

Can you setting this env variable DYLD_FORCE_FLAT_NAMESPACE=1?

@vishalsubbiah
Copy link
Author

@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.

@vgvassilev
Copy link
Owner

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.

@vishalsubbiah
Copy link
Author

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.

@vgvassilev
Copy link
Owner

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 vgvassilev self-assigned this Feb 7, 2024
@vgvassilev vgvassilev added this to the v1.4 milestone Feb 7, 2024
vgvassilev added a commit that referenced this issue Feb 12, 2024
This patch removes the flat_namespace option that we pass to the linker on osx.
Instead we will make a dynamic lookup when a symbol is missing which is more
consistent with the default behavior for osx.

Fixes #300.
vgvassilev added a commit that referenced this issue Feb 12, 2024
This patch removes the flat_namespace option that we pass to the linker on osx.
Instead we will make a dynamic lookup when a symbol is missing which is more
consistent with the default behavior for osx.

Fixes #300.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants