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
libnest3.so not compiling on Mac OSX 10.6.8 #10
Comments
Macs are distributed with LLVM/clang, not gcc. That's why the ld options don't work. Either install and use gcc/gfortran, or run |
Thanks so much for getting back to me so quickly. Still having problems. #FC = mpif90 LAPACKLIB = -llapack NESTLIBDIR = ./ export FC CC CXX FFLAGS CFLAGS LAPACKLIB AR = ar r i.e. I'm using gfortran/gcc already. Here's what I get at the moment: make make libest3.so Thanks again. |
Can this be resolved by passing -llapack? It can be problematic to combine gfortran/gcc compiled binaries with a clang linker. Either compile with LLVM (which would be interesting), or use the gnu linker. |
Pass -llapack to which? So: which gcc which ld Here's the gcc info: gcc -v |
To ld |
Huh, shared libraries are quite difficult in MacOS, judging from leto/math--gsl#4 and http://sourceforge.net/p/math-atlas/support-requests/536/ Sorry I can't test this, I don't have a Mac. Try these: $ ld -llapack -dynamic -dylib -single_module -dead_strip -x -all_load -dylib_install_name -o libnest3.so utils.o utils1.o priors.o kmeans_clstr.o xmeans_clstr.o posterior.o nested.o |
Making progress - I stuck with ld and libnest3.so was successfully generated with: ld -o libnest3.so -llapack -lpthread -L. -lnest3 -dynamic -dylib -single_module -dead_strip -x -arch x86_64 (I've been doing 64 bit compilation. Haven't yet seen whether the line above can be trimmed down a bit.) My modified makefile is at the bottom of this post. And the next problem is (I think you know how to solve this though?): make -C multinest_bridge libcnest.so WITHOUT_MPI=1 MULTINEST set to /Users/jtlz2/src/MultiNest_v2.18.If you didn't set this to the directory where MultiNestis compiled, you will receive see this error later:OSError: libcnest.so: undefined symbol: __nested_MOD_nestrunChecking if libnest3.so is in $MULTINESTFound.gfortran -m64 -shared -I. -O3 -std=c99 -fPIC -DMULTINEST_CALL=__nested_MOD_nestrun cnest.c -o libcnest.so -L/Users/jtlz2/src/MultiNest_v2.18 -lnest3 -llapack -lpthread Thanks! Here's the modified multinest makefile (most of the changes are, I suspect, redundant - again will prune at some point): #FC = mpif90 LAPACKLIB = -llapack NESTLIBDIR = ./ export FC CC CXX FFLAGS CFLAGS LAPACKLIB AR = ar r NSOBJECTS = utils.o utils1.o priors.o kmeans_clstr.o xmeans_clstr.o posterior.o nested.o %.o: %.f90 %.o: %.F90 default: libnest3.a all: libnest3.a obj_detect eggboxC eggboxC++ gaussian gauss_shell libnest3.so: $(NSOBJECTS) libnest3.a: $(NSOBJECTS) |
Great! |
Hmm, readelf is a tool for linux binaries. |
Hmm. I get nothing for: gobjdump -plibnest3.so | grep nestrun whereas -plibnest3.a does give some output (but not containing 'nestrun'). Also: nm libnest3.a | grep nestrun But for the .so, nm (not that I know what that does(!)) just gives: nm libnest3.so So I wonder if something's wrong with the .so file, which I compiled with: ld -o libnest3.so -llapack -lpthread -L. -lnest3 -dynamic -dylib -single_module -dead_strip -x -arch x86_64 I tried adding -L/Users/jtlz2/src/MultiNest_v2.18 but it made no difference. Any ideas? :-S |
That's not good. Try without the -dylib -single_module -dead_strip -x options. I think what you have now is a stripped dylib file, not actually a .so. file will tell you. If you get really frustrated with the MacOS compilation, you could set up a ubuntu virtual machine using Virtualbox. However figuring this native compilation out will be useful for others. |
So file gives: file libnest3.so I think you're right about the stripped dylib.. Here's the ld output now localhost:MultiNest_v2.18 jtlz2$ ld -llapack -dynamic -all_load I do quite want to get this working on my mac.... |
what does |
ld -llapack -dynamic -dylib -all_load -dylib_install_name -L. -lnest3 -arch file libnest3.dylib nm libnest3.dylib What do you get for your search paths (or is that a non-issue?)? |
For me it is: and nm libnest3.so prints a lot of gfortran, _xmeans, _nested_MOD, etc. lines. Try this: Yes, could try what you linked to, but then you have to know and specify each symbol. $ g++ -dynamiclib -undefined suppress -flat_namespace utils.o utils1.o priors.o kmeans_clstr.o xmeans_clstr.o posterior.o nested.o -o libnest3.dylib |
Good news! g++ -dynamiclib -undefined suppress -flat_namespace utils.o utils1.o works. nm is also happy now: nm libnest3.so | grep nestrun once I had renamed libnest3.dylib -> libnest3.so make -C multinest_bridge libcnest.so WITHOUT_MPI=1 also works without complaining :) Now I have but a humble image issue: getinetlaptop:PyMultiNest-master jtlz2$ python -c 'import pymultinest' Do you know what could be up there? Thanks! |
This also fails in the same way if I delete libnest.dylib (it then picks up |
It is better to not use .so extensions, and stick to .dylib, because this is what you are using now and tools might get confused. |
OK. I'm still getting: python -c 'import pymultinest'dlopen(libcnest.dylib, 6): Library not having done a search and replace .so -> .dylib in the Makefile in
->
Getting there... |
You can be lazy and just put a |
Yes I was just setting export which did the trick - massive thanks for all your help today, and for Do you want to update the documentation/makefiles or shall I? ;) Thanks again! |
If you can update it it would be greatly appreciated, perhaps in form of a Makefile.MacOS that is minimally different from the Makefile. |
OK I'll try and prepare a makefile since I have to explain how to compile Thanks again! |
I put a if clause into https://github.com/JohannesBuchner/MultiNest/blob/master/Makefile |
Dear Johannes and Jonathan: Wow, that was quite an effort, congratulations on getting it working. For completeness, I will describe how I got PyMultiNest to work on OS X 10.6-10.8. First of all, I found homebrew (http://mxcl.github.com/homebrew/) very reliable to get tools that integrate with Apple's (i.e., XCode's gcc). With homebrew, getting a functional Fortran and MPI with fortran is a matter of doing $ brew install gfortran Then, in the multinest Makefile (I am using 2.18 currently), I replace the lines LAPACKLIB = -framework vecLib and I make libnest.a ONLY (not libnest.so). [So maybe the -bundle -undefined dynamic_lookup flags, which equate to -shared, are not even needed... oh well.] Then I export MULTINEST={my multinest source directory), and proceed to PyMultiNest/multinest_bridge. That Makefile is modified thus (without bothering to show you where each line goes): MULTINEST_CALL := __nested_MOD_nestrun The MULTINEST_CALL may depend on the exact version of the compiler, and the mangled name can be found with "nm libnest3.a | grep nestrun". The resulting libcnest.so contains a full compiled version of the multinest library, but that's not a big price to pay IMHO. I was not able to make this work with both libnest3 and libcnest as shared libraries. To work correctly, libcnest.so must be moved to your Python's site-packages, or to the directory where you run code. |
Grand! If you can, please also provide the output of make so everyone is clear on how the compiler is actually called. Unless you modified the Makefile in other places, LAPACKLIB and LINKLIB will not used at all. |
Partly for my own benefit, I just wanted to record my steps for compiling with MultiNEST v3.2 on a Mac running 10.6.8 in 64-bit mode with MPI:
So, proceeding with the main version:
FC = mpif90 -ffree-line-length-none -lmpi -m64 -lpthread
Note that 'make all' fails with the current settings because the C and C++ versions of eggbox cannot be compiled, but the fortran versions do compile.
.so is actually a dynamic library, but I use the .so extension to avoid having to hack pymultinest (see discussion above).
nm libnest3.so | grep nestrun
MNESTLIBNAME := nest3
export MULTINEST=
Success! Is there any chance you could add a pymultinest.version or add this to the help command so one can keep track? I wonder if you can add any of the above to the makefile? I'm not sure how to replace the g++ line in step (3) without asking Farhan to intervene. @vallis? |
Thanks for documenting. I use Linux exclusively, and I always use the CMake version, so I am not sure how I can help. What is your error compiling with cmake? Ultimately, you will have to communicate with Farhan if MultiNest does not compile for you on MacOS. I am not sure why you need to specify -arch and -m64. By default, the compiler should build for your architecture automatically, so 64 bit binaries should come out. What information would pymultinest.version hold? What would you use it for? |
Hey. In fact the cmake version is now working for me which is great: export MULTINEST='~/src/MultiNest_v3.2_CMake/multinest/lib/' Then the bridge installation proceeds fine with your new linklib commit - thanks. Ah don't worry about version - it just would've helped to check I was picking up the right version at my end. Since you use commits rather than specific versions numbers you could label using that. Thanks! |
Hi Johannes,
I'm trying to compile libnest3.so from multinest 2.18 so I can install the multinest bridge, but
make libnest3.so WITHOUT_MPI=1
fails thus:
localhost:MultiNest_v2.18 jtlz2$ make libnest3.so
ld -shared -o libnest3.so utils.o utils1.o priors.o kmeans_clstr.o xmeans_clstr.o posterior.o nested.o
ld: unknown option: -shared
make: *** [libnest3.so] Error 1
If I remove -shared I get:
[snip]
___nested_MOD_gen_initial_live in nested.o
___nested_MOD_nestsample in nested.o
___nested_MOD_nestsample in nested.o
___nested_MOD_nestsample in nested.o
___nested_MOD_nestsample in nested.o
___nested_MOD_nestrun in nested.o
___nested_MOD_nestrun in nested.o
___nested_MOD_nestrun in nested.o
___nested_MOD_nestrun in nested.o
___nested_MOD_nestrun in nested.o
"dsyevr", referenced from:
___utils1_MOD_diagonalize in utils1.o
___utils1_MOD_diagonalize in utils1.o
"_tan", referenced from:
___priors_MOD_cauchyprior in priors.o
ld: symbol(s) not found for inferred architecture i386
If I remove -m64 from my FC (see below) I still get:
localhost:MultiNest_v2.18 jtlz2$ make libnest3.so
gfortran -ffree-line-length-none -O3 -c -o utils.o utils.f90
gfortran -ffree-line-length-none -O3 -c -o utils1.o utils1.f90
gfortran -ffree-line-length-none -O3 -c -o priors.o priors.f90
gfortran -ffree-line-length-none -O3 -c -o kmeans_clstr.o kmeans_clstr.f90
gfortran -ffree-line-length-none -O3 -c -o xmeans_clstr.o xmeans_clstr.f90
gfortran -ffree-line-length-none -O3 -c -o posterior.o posterior.F90
gfortran -ffree-line-length-none -O3 -c -o nested.o nested.F90
ld -shared -o libnest3.so utils.o utils1.o priors.o kmeans_clstr.o xmeans_clstr.o posterior.o nested.o
ld: unknown option: -shared
make: *** [libnest3.so] Error 1
My makefile is modified from the supplied version:
< #FC = mpif90
< FC = gfortran -ffree-line-length-none -m64
< #CC = mpicc
< CC = gcc
< #CXX = mpiCC
< CXX = gcc
< FFLAGS += -O3 #-DMPI
< CFLAGS += -O3 #-DMPI
and multinest itself compiles and the examples (and indeed my own lhoods) have been running fine.
Any ideas? Thanks in advance for a speedy reply.
The text was updated successfully, but these errors were encountered: