mctools / mcpl

Monte Carlo Particle Lists
https://mctools.github.io/mcpl/
Other
29 stars 13 forks source link

McStas+NCrystal -> unknown option: --rpath=NCrystalLink/lib #36

Closed MilanKlausz closed 6 years ago

MilanKlausz commented 6 years ago

I get the following error message when I try to run a McStas simulation with an NCrystal_sample component in the instrument file:

ld: unknown option: --rpath=NCrystalLink/lib
collect2: error: ld returned 1 exit status

I've installed NCrystal 0.9.2 using the Source code (tar.gz) without any trouble, following the instructions in the INSTALL file (cmake, make install, setup.sh). It passes the test ("Tests completed succesfully"), and I can visualize data using the command-line. The problem comes when I want to use it with McStas. I've made the links using the _ncrystalpreparemcstasdir command in the folder where I'm calling mcstas, and after that I can even compile an instrument file using the mcstas command without any error. I get the error only when I launch a simulation with the mcrun or mcdisplay-webgl commands. I get the same result with NCrystal 0.9.1 too.

Other environment info: macOS High Sierra (Version 10.13) McStas version 2.4.1 (Jun. 26, 2017) cmake version 3.9.4 gcc (GCC) 6.0.0 20151213 (experimental)

The full text that I get:

[milanklausz@CI0011996 BIFROST]$ mcrun Primary_Instrument_ChopsAndJaws_withTarget.instr -c -n100
loading user configuration from /Users/milanklausz/.mcstas/2.4.1/mccode_config.json
INFO: No output directory specified (--dir)
INFO: Using directory: "Primary_Instrument_ChopsAndJaws_withTarget_20180130_120944"
INFO: Recompiling: ./Primary_Instrument_ChopsAndJaws_withTarget.out
INFO: Regenerating c-file: Primary_Instrument_ChopsAndJaws_withTarget.c
Info:    'Elliptic_guide_gravity' is a contributed component.
CFLAGS= -Wl,--rpath=NCrystalLink/lib -LNCrystalLink/lib -lNCrystal -INCrystalLink/include
NCrystal_sample.comp: In function ‘mcraytrace’:
NCrystal_sample.comp:229:5: warning: passing argument 3 of ‘ncrystal_crosssection’ from incompatible pointer type [enabled by default]
     ncrystal_crosssection(params.proc_scat,ekin,&dir,&xsect_scat);
     ^
In file included from NCrystal_sample.comp:71:0:
NCrystalLink/include/NCrystal/ncrystal.h:102:8: note: expected ‘const double (*)[3]’ but argument is of type ‘double (*)[3]’
   void ncrystal_crosssection( ncrystal_process_t,
        ^
NCrystal_sample.comp:269:7: warning: passing argument 3 of ‘ncrystal_genscatter’ from incompatible pointer type [enabled by default]
       ncrystal_genscatter( params.scat,ekin, &dir, &dirout, &delta_ekin);
       ^
In file included from NCrystal_sample.comp:71:0:
NCrystalLink/include/NCrystal/ncrystal.h:115:8: note: expected ‘const double (*)[3]’ but argument is of type ‘double (*)[3]’
   void ncrystal_genscatter( ncrystal_scatter_t,
        ^
NCrystal_sample.comp:295:9: warning: passing argument 3 of ‘ncrystal_crosssection’ from incompatible pointer type [enabled by default]
         ncrystal_crosssection(params.proc_scat,ekin,&dir,&xsect_scat);
         ^
In file included from NCrystal_sample.comp:71:0:
NCrystalLink/include/NCrystal/ncrystal.h:102:8: note: expected ‘const double (*)[3]’ but argument is of type ‘double (*)[3]’
   void ncrystal_crosssection( ncrystal_process_t,
        ^
./Primary_Instrument_ChopsAndJaws_withTarget.c:41113:6: note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without

      ^
./Primary_Instrument_ChopsAndJaws_withTarget.c: In function ‘mcinit’:
./Primary_Instrument_ChopsAndJaws_withTarget.c:18792:6: note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without

      ^
ld: unknown option: --rpath=NCrystalLink/lib
collect2: error: ld returned 1 exit status
Traceback (most recent call last):
  File "/Applications/McStas-2.4.1.app/Contents/Resources/mcstas/2.4.1/bin/../tools/Python/mcrun/mcrun.py", line 372, in <module>
    main()
  File "/Applications/McStas-2.4.1.app/Contents/Resources/mcstas/2.4.1/bin/../tools/Python/mcrun/mcrun.py", line 289, in main
    mcstas.prepare(options)
  File "/Applications/McStas-2.4.1.app/Contents/Resources/mcstas/2.4.1/tools/Python/mcrun/mccode.py", line 173, in prepare
    Process(options.cc).run(args)
  File "/Applications/McStas-2.4.1.app/Contents/Resources/mcstas/2.4.1/tools/Python/mcrun/mccode.py", line 80, in run
    raise ProcessException(self.executable, args, retval)
mccode.ProcessException: Got exit status 1 from "gcc -o ./Primary_Instrument_ChopsAndJaws_withTarget.out ./Primary_Instrument_ChopsAndJaws_withTarget.c -lm -UUSE_MPI -g -O2 -lm -headerpad_max_install_names  -Wl,--rpath=NCrystalLink/lib -LNCrystalLink/lib -lNCrystal -INCrystalLink/include"
willend commented 6 years ago

Hi @MilanKlausz,

It looks to me like the macOS linker doesn't like the --rpath= in the CFLAGS. (According to https://stackoverflow.com/questions/26472590/ld-unknown-option-rpath-libs-linking-error-while-building-openframework it looks like it needs -rpath, instead)

The extra

CFLAGS= -Wl,--rpath=NCrystalLink/lib -LNCrystalLink/lib -lNCrystal -INCrystalLink/include

looks like they are being picked up from the NCrystal_sample.comp code.

So without having access to your instrumentfile etc., I would guess you can edit NCrystal_sample.comp and change the

DEPENDENCY
line to read
CFLAGS= -Wl,-rpath,NCrystalLink/lib -LNCrystalLink/lib -lNCrystal -INCrystalLink/include

Hope this helps - otherwise please include a zip file with your instr code etc. and I shall have a closer look.

Peter

tkittel commented 6 years ago

Oups, this should have been in the https://github.com/mctools/ncrystal/issues tracker (my bad, I sent Milan the wrong link). Milan can you open it there instead with the same text?

And thanks Peter for the suggestion, I'll see if the suggestion works across platforms and possibly release a new NCrystal version.

willend commented 6 years ago

I have defined a McStas issue (https://github.com/McStasMcXtrace/McCode/issues/589) so that we remember to try out NCrystal "from our side" as well, plus consider if we should include a snapshot with our next release(s)

willend commented 6 years ago

Just made a quick test here, things work for me with

DEPENDENCY "-Wl,-rpath,NCrystalLink/lib -LNCrystalLink/lib -lNCrystal -INCrystalLink/include"
in the component code.
willend commented 6 years ago

Suggestion:

Could ncrystal_preparemcstasdir put an os-tailored copy of NCrystal_sample.comp in . rather than a link?

tkittel commented 6 years ago

Hi Peter,

Of course, as a last resort it can do something like that. My gut feeling though is that figuring out a more "universal" line working ~everywhere would end up giving us less hassle. To be investigated.

MilanKlausz commented 6 years ago

-rpath,NCrystalLink/lib solved the problem. Thank you! From now this is officially the best supported software(combination) I've ever used :)

tkittel commented 6 years ago

Great Milan :-)

The official fix is in NCrystal 0.9.4, let me know if works for you.