smmills / Phodymm

Photodynamics Code v1
2 stars 2 forks source link

Trouble compiling #16

Closed sealauren closed 4 years ago

sealauren commented 5 years ago

Hey Sean,

I just downloaded and installed gsl and celerite. However, when I tried to compile your code, I got the following errors: g++ -w -O3 -o lcout -I/$HOME/celerite/cpp/include -I/$HOME/celerite/cpp/lib/eigen_3.3.3 -lm -lgsl -lgslcblas -fpermissive phodymm.cpp

phodymm.cpp:354:11: error: cannot initialize a variable of type 'double *' with an rvalue of type 'void *'
  double* evector = malloc(npl*sofd);
          ^         ~~~~~~~~~~~~~~~~
phodymm.cpp:400:15: error: assigning to 'double *' from incompatible type 'void *'
    evector = malloc(npl*sofd);
              ^~~~~~~~~~~~~~~~
phodymm.cpp:468:11: error: cannot initialize a variable of type 'double *' with an rvalue of type 'void *'
  double *diffys = malloc(sofd*maxil);
          ^        ~~~~~~~~~~~~~~~~~~
phodymm.cpp:473:11: error: cannot initialize a variable of type 'double *' with an rvalue of type 'void *'
  double *yvarp = malloc(sofd*maxil);
          ^       ~~~~~~~~~~~~~~~~~~
phodymm.cpp:630:33: error: cannot initialize a member subobject of type 'int (*)(double, const double *, double
      *, double *, void *)' with an lvalue of type 'void *'
  gsl_odeiv_system sys = {func, jac, 6*npl, npl_mu};
                                ^~~
phodymm.cpp:637:11: error: cannot initialize a variable of type 'double *' with an rvalue of type 'void *'
  double *rad = malloc(npl*sofd);
          ^     ~~~~~~~~~~~~~~~~
phodymm.cpp:699:11: error: cannot initialize a variable of type 'double *' with an rvalue of type 'void *'
  double *transitarr = malloc((maxtransits+1)*ntarrelem*sofd);
          ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
phodymm.cpp:717:13: error: assigning to 'double *' from incompatible type 'void *'
    rvarr = calloc(vv+1, sofd);
            ^~~~~~~~~~~~~~~~~~
phodymm.cpp:719:14: error: assigning to 'double *' from incompatible type 'void *'
    rvtarr = malloc((vv+2)*sofd);
             ^~~~~~~~~~~~~~~~~~~
phodymm.cpp:731:15: error: assigning to 'double **' from incompatible type 'void *'
    ttvarr2 = malloc(npl*sofds);
              ^~~~~~~~~~~~~~~~~
phodymm.cpp:733:20: error: assigning to 'double *' from incompatible type 'void *'
      ttvarr2[i] = malloc(NTTV[i][0]*sofd);
                   ^~~~~~~~~~~~~~~~~~~~~~~
phodymm.cpp:736:14: error: assigning to 'double *' from incompatible type 'void *'
    ttvarr = malloc((vvt+1)*sofd);
             ^~~~~~~~~~~~~~~~~~~~
phodymm.cpp:776:10: error: cannot initialize a variable of type 'FILE **' (aka '__sFILE **') with an rvalue of
      type 'void *'
  FILE **directory = malloc(npl*sizeof(FILE*));
         ^           ~~~~~~~~~~~~~~~~~~~~~~~~~
phodymm.cpp:808:12: error: assigning to 'int *' from incompatible type 'void *'
    ttvi = calloc(npl, sofi);
           ^~~~~~~~~~~~~~~~~
phodymm.cpp:809:16: error: assigning to 'int *' from incompatible type 'void *'
    ttviinit = malloc(npl*sofi);
               ^~~~~~~~~~~~~~~~
phodymm.cpp:1276:10: error: assigning to 'double **' from incompatible type 'void *'
  tmte = malloc(4*sofds);
         ^~~~~~~~~~~~~~~
phodymm.cpp:1277:13: error: assigning to 'double *' from incompatible type 'void *'
  tmte[2] = malloc((kk+1)*sofd);
            ^~~~~~~~~~~~~~~~~~~
phodymm.cpp:1290:14: error: assigning to 'double *' from incompatible type 'void *'
  rvoffset = malloc(maxteles*sofd);
             ^~~~~~~~~~~~~~~~~~~~~
phodymm.cpp:1321:12: error: assigning to 'double **' from incompatible type 'void *'
  rvtmte = malloc(4*sofds);
           ^~~~~~~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
smmills commented 5 years ago

These errors arise because the code was written in C initially, where assigning voids from memory allocations to other types is allowed without casting them first. The -fpermissive flag should cause these to go away (in lieu of rewriting each allocation in a C++ friendly manner, which will happen eventually).

If you are compiling on your Mac using Apple's gcc/LLVM, sometimes strange things can happen when you also have updated std libraries potentially from homebrew/macports.

The code compiles fine for me on my Mac if I use a g++ version which is entirely installed via macports, e.g.: $ g++-mp-7 -w -O3 -o lcout -I/opt/local/include -I/opt/local/lib -I/Users/seanmills/celerite/cpp/include -I/Users/seanmills/celerite/cpp/lib/eigen_3.3.3 -lm -L/opt/local/lib -lgsl -lgslcblas -fpermissive phodymm.cpp where

$ g++-mp-7 --version
g++-mp-7 (MacPorts gcc7 7.3.0_5) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

as opposed to using the default g++:

$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

If you know what you're doing with Mac compiler libraries (or I fix the code), you can avoid having to do this, but this is a simple workaround until then. Let me know if you find any other problems--I have never tried to compile it on a Mac until now, so didn't know to expect this.

sealauren commented 5 years ago

Hi Sean,

I don't have macports installed, and I cannot find g++ on homebrew.

Can you please fix your code?

Thanks,

Lauren

On Fri, Dec 21, 2018 at 6:32 AM smmills notifications@github.com wrote:

These errors arise because the code was written in C initially, where assigning voids from memory allocations to other types is allowed without casting them first. The -fpermissive flag should cause these to go away (in lieu of rewriting each allocation in a C++ friendly manner, which will happen eventually).

If you are compiling on your Mac using Apple's gcc/LLVM, sometimes strange things can happen when you also have updated std libraries potentially from homebrew/macports.

The code compiles fine for me on my Mac if I use a g++ version which is entirely installed via macports, e.g.: $ g++-mp-7 -w -O3 -o lcout -I/opt/local/include -I/opt/local/lib -I/Users/seanmills/celerite/cpp/include -I/Users/seanmills/celerite/cpp/lib/eigen_3.3.3 -lm -L/opt/local/lib -lgsl -lgslcblas -fpermissive phodymm.cpp where

$ g++-mp-7 --version g++-mp-7 (MacPorts gcc7 7.3.0_5) 7.3.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

as opposed to using the default g++:

$ g++ --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 9.0.0 (clang-900.0.38) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

If you know what you're doing with Mac compiler libraries (or I fix the code), you can avoid having to do this, but this is a simple workaround until then. Let me know if you find any other problems--I have never tried to compile it on a Mac until now, so didn't know to expect this.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/smmills/Phodymm/issues/16#issuecomment-449434861, or mute the thread https://github.com/notifications/unsubscribe-auth/ABRTfgAPc8gjbja8zySlM8RH1pMvqHV8ks5u7Q0bgaJpZM4ZdKyM .

smmills commented 5 years ago

Homebrew has many versions of gcc, including gcc4, 5, 6, 7, and gcc8; see, e.g., https://formulae.brew.sh/formula/ for a list of packages available.

You will probably want to use the code on a cluster anyway, so it may not be worth pursuing it on your laptop if it's a hassle for you. You might instead go directly to compiling on Cadence or wherever. Otherwise, the code will be updated in a few weeks probably.

sealauren commented 5 years ago

I'll try installing it on cadence. How do I install gsl on cadence?

On Fri, Dec 21, 2018 at 3:20 PM smmills notifications@github.com wrote:

Homebrew has many versions of gcc, including gcc4, 5, 6, 7, and gcc8; see, e.g., https://formulae.brew.sh/formula/ for a list of packages available.

You will probably want to use the code on a cluster anyway, so it may not be worth pursuing it on your laptop if it's a hassle for you. You might instead go directly to compiling on Cadence or wherever. Otherwise, the code will be updated in a few weeks probably.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/smmills/Phodymm/issues/16#issuecomment-449534361, or mute the thread https://github.com/notifications/unsubscribe-auth/ABRTflNSReIB3m5JTCNjKtAbV08X7pHyks5u7YjegaJpZM4ZdKyM .

smmills commented 5 years ago

I think gcc and gsl are installed on Cadence systemwide already.