dacase / nabc

Nonperiodic force field calculations, with a "C" language interface rather than the original interface based on the Nucleic Acid Builder (NAB) molecular manipulation language
Other
4 stars 1 forks source link

a problem with installation #4

Open liudidna opened 1 month ago

liudidna commented 1 month ago

Hi, I managed to proceed to the step cd test && make test, but got the following error message:

[NABC] CC tmask
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [tmask] Error 1

I've tried several things according to online resouces, but they do not work. (1) Reinstall gcc, xcode clt; (2) Create a conda gfortran environment; (3) add the path of libgfortran to LDFLAGS and DYLD_LIBRARY_PATH.

The error is reproducible on both intel macbook pro and M1 macbook pro. I appreciate your help!

dacase commented 1 month ago

NABC does require a gfortran installation. It's not clear how you satisfied this: usually on OSX, some package manager like macports or homebrew is used. But it's true that I have never tested NABC on OSX, and the configure script doesn't have any special rules for OSX. So maybe you can help get things working there.

Some questions on the points you tried:

(1) Apple doesn't provide this via xcode, and gcc alone is not enough. (2) I don't know exactly what you did to "create a conda gfortran environment." I use conda, but I'm no guru there. Can you compile any fortran codes in this environment? It's actually odd (to me) that you could have compiled everything (indicating the gfortran is available) but that gcc is unable to find -lgfortran. (Maybe that works in Linux but not OSX.) (3) LDFLAGS is not used in the test suite, and DYLD_LIBRARY_PATH refers to dynamic loading, so wont' help during compilation. But let us know what you set LDFLAGS to be.

Try this: edit config.h to set the VB (verbose) variable to blank. Then cd test, and type "make tmask". Here's what I see:

gcc -Wno-unused-result -o tmask tmask.o  -L/home/case/nabc/lib -lsff -lnabc -larpack -llapack -lblas -lnetcdf  -lgfortran -w   -lm  -lgfortran -w

Then try putting what you put into LDFLAGS into FLIBS_ARCH in config.h. That may be enough to find libgfortran, and allow tmask to compile.

[Aside: tmask itself doesn't actually need libgfortran, but other codes will.]

liudidna commented 1 month ago

thanks for the prompt response! make tmask returns:

[NABC] CC tmask
gcc -Wno-unused-result -o tmask tmask.o  -L/Users/diliu/AllDropbox/Dropbox_ASU/programs/nabc/lib -lsff -lnabc -larpack -llapack -lblas -lnetcdf  -lgfortran -w     -lgfortran -w
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [tmask] Error 1

To answer your questions: (2) my gfortran is installed via homebrew installation of gcc, and I also tried to use conda create -n gf gfortran to create the gfortran environment and conda activate gf to activate it. (3) I've written these lines in my .zprofile:

export LDFLAGS="-L/opt/homebrew/Cellar/gcc/14.1.0/lib/gcc/current $LDFLAGS"
export DYLD_LIBRARY_PATH="/opt/homebrew/Cellar/gcc/14.1.0/lib/gcc/current:$DYLD_LIBRARY_PATH"
export LD_LIBRARY_PATH="/opt/homebrew/Cellar/gcc/14.1.0/lib/gcc/current:$LD_LIBRARY_PATH"

Thanks!

dacase commented 1 month ago

I probably put too many things into my previous comment.

  1. What does "which gcc" return? Apple includes a /usr/bin/gcc, which (in spite of its name) is just a link to clang. Does your PATH return the homebrew gcc? 2.Try this: put the following into your config.h file
    FLIBS_ARCH="-L/opt/homebrew/Cellar/gcc/14.1.0/lib/gcc/current"

That may allow even the clang compiler to find libgfortran.

liudidna commented 1 month ago

Dear David,

Thanks a lot, it works!

To answer your question, the which gcc returns:

/usr/bin/gcc

So I changed the config.h file according to your suggestion. Then, everything PASSED with make test.

Di

liudidna commented 1 month ago

However, for the step cd test/nab && make test (by the way, I entered make nab at the main folder nabc, and so many warnings were generated during multiple stages this step), I got another error:

Running test to make dna duplex:

ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
cc failed!
./Run.duplex: Program error
make: *** [duplex_test] Error 1

I think this one is similar to the previous one, could I get through it again by editing another file?

Thanks,

Di

dacase commented 1 month ago

I think the easiest thing to do is to put the homebrew folder before /usr/bin, so that "gcc" points to the "real" gcc (from homebrew), and not to Apple's (very misleading) link that makes programs that are looking for gcc find clang instead.

liudidna commented 1 month ago

Yes, I actually already added homebrew to my PATH in the front by export PATH="/opt/homebrew/bin/:$PATH", but the same error persist. When I looked into /opt/homebrew/bin/, there was no gcc, but only gcc-14, which is a link. So I made another copy of it, and rename the new copy as gcc.

Then, I did the make nab again, and this time there is no warning!

However, when do do cd test/nab && make test, I got new error messages:

Running test to make dna duplex:

Undefined symbols for architecture arm64:
  "_nabout", referenced from:
      _main in ccWMAxbK.o
      _putxyzw in libsff.a(sff.o)
      _getxv in libsff.a(sff.o)
      _putxv in libsff.a(sff.o)
      _mme_timer in libsff.a(sff.o)
      _ipssys in libsff.a(sff.o)
      _nblist_box in libsff.a(sff.o)
      ...
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
cc failed!
./Run.duplex: Program error
make: *** [duplex_test] Error 1

The "ld: symbol(s) not found for architecture arm64" alerted me because I'm using an M1 mac. Do you think it can only work on intel mac?

Thanks, again, a lot!