OceanParcels / Parcels

Main code for Parcels (Probably A Really Computationally Efficient Lagrangian Simulator)
https://www.oceanparcels.org
MIT License
295 stars 136 forks source link

Fatal compilation MacOS: 'stdio.h' file not found #include <stdio.h> #796

Closed daanreijnders closed 4 years ago

daanreijnders commented 4 years ago

I'm experiencing issues with using the RNG (which I want to use for JIT mode).

Here's a minimal example:

# standard imports
from parcels import Field, FieldSet, ErrorCode, ParticleSet, Variable, JITParticle, ScipyParticle, AdvectionRK4, plotTrajectoriesFile, rng
rng.seed(1636)

Traceback:

-------------------------------------------------------------------------
CalledProcessError                      Traceback (most recent call last)
/opt/anaconda3/lib/python3.7/site-packages/parcels/compiler.py in compile(self, src, obj, log)
     54             try:
---> 55                 subprocess.check_call(cc, stdout=logfile, stderr=logfile)
     56             except OSError:

/opt/anaconda3/lib/python3.7/subprocess.py in check_call(*popenargs, **kwargs)
    362             cmd = popenargs[0]
--> 363         raise CalledProcessError(retcode, cmd)
    364     return 0

CalledProcessError: Command '['mpicc', '-Wall', '-fPIC', '-I/opt/anaconda3/lib/python3.7/site-packages/parcels/include', '-g', '-O3', '-m64', '-o', '/var/folders/_k/jcmdplbn0yj79g4k3g9f4nxr0000gn/T/parcels-501/parcels_random_a2c47c1d-dbfc-4768-94cf-28d2ead6a190.so', '/var/folders/_k/jcmdplbn0yj79g4k3g9f4nxr0000gn/T/parcels-501/parcels_random_a2c47c1d-dbfc-4768-94cf-28d2ead6a190.c', '-shared', '-m64']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

RuntimeError                            Traceback (most recent call last)
<ipython-input-2-f0b9b41bbb02> in <module>
----> 1 rng.seed(1636)

/opt/anaconda3/lib/python3.7/site-packages/parcels/rng.py in seed(seed)
     77 def seed(seed):
     78     """Sets the seed for parcels internal RNG"""
---> 79     parcels_random.lib.pcls_seed(c_int(seed))
     80 
     81 

/opt/anaconda3/lib/python3.7/site-packages/parcels/rng.py in lib(self, compiler)
     66             with open(self.src_file, 'w') as f:
     67                 f.write(self.ccode)
---> 68             compiler.compile(self.src_file, self.lib_file, self.log_file)
     69             logger.info("Compiled %s ==> %s" % ("random", self.lib_file))
     70             self._lib = npct.load_library(self.lib_file, '.')

/opt/anaconda3/lib/python3.7/site-packages/parcels/compiler.py in compile(self, src, obj, log)
     66 
     67 Log output: %s""" % (" ".join(cc), src, logfile.name, logfile2.read())
---> 68                 raise RuntimeError(err)
     69 
     70 

RuntimeError: Error during compilation:
Compilation command: mpicc -Wall -fPIC -I/opt/anaconda3/lib/python3.7/site-packages/parcels/include -g -O3 -m64 -o /var/folders/_k/jcmdplbn0yj79g4k3g9f4nxr0000gn/T/parcels-501/parcels_random_a2c47c1d-dbfc-4768-94cf-28d2ead6a190.so /var/folders/_k/jcmdplbn0yj79g4k3g9f4nxr0000gn/T/parcels-501/parcels_random_a2c47c1d-dbfc-4768-94cf-28d2ead6a190.c -shared -m64
Source file: /var/folders/_k/jcmdplbn0yj79g4k3g9f4nxr0000gn/T/parcels-501/parcels_random_a2c47c1d-dbfc-4768-94cf-28d2ead6a190.c
Log file: /var/folders/_k/jcmdplbn0yj79g4k3g9f4nxr0000gn/T/parcels-501/parcels_random_a2c47c1d-dbfc-4768-94cf-28d2ead6a190.log

Log output: In file included from /var/folders/_k/jcmdplbn0yj79g4k3g9f4nxr0000gn/T/parcels-501/parcels_random_a2c47c1d-dbfc-4768-94cf-28d2ead6a190.c:1:
/opt/anaconda3/lib/python3.7/site-packages/parcels/include/parcels.h:7:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.

I'm on Parcels version 2.1.4 (Conda installed) on MacOS

daanreijnders commented 4 years ago

Turned out to be (semi-)unrelated to Parcels. Instead it had to do with Xcode Command Line Tools now installing system headers in a different location than it used to in the past. See this Apple forum thread. I'm leaving this open for now. While there's a workaround for the user, perhaps Parcels can be updated to look for the macOS system headers inside the macOS SDK.

erikvansebille commented 4 years ago

Thanks for reporting, @daanreijnders. There's indeed been a bit of problems with libraries on macOS. But I don't think this is really related to Parcels, as the gcc compiler and all the libraries are managed by conda.

We do have this statement after step 5 of http://oceanparcels.org/#installing: "Note that if you are on macOS and get a compilation error, you may need to accept the Apple xcode license (xcode-select --install). If this does not solve the compilation error, you may want to try running export CC=gcc . If the compilation error remains, you may want to check this solution."

Does that work for your system? Any idea how we can improve this message?

daanreijnders commented 4 years ago

I think the message is good as is; the stack overflow link contains the same workaround as the one I used from the Apple forum. If people run into the same issue as me and don't know it's related to this, hopefully this thread will lead them to the solution.