sagemath / sage-archive-2023-02-01

This repository used to be the user-facing mirror of the Sage source tree. As Sage development migrated on 2023-02-01 from https://trac.sagemath.org/ to our new repository on GitHub, https://github.com/sagemath/sage, we have renamed and archived this repository.
https://www.sagemath.org
Other
2.01k stars 413 forks source link

Compilation of custom C code from Cython #84

Closed okazymyrov closed 6 years ago

okazymyrov commented 6 years ago

Hi,

I have code on https://github.com/okazymyrov/sbox. It works fine with sage 7.1 . However, in SageMath 8.1 I get warnings like:

/Users/okazymyrov/bin/sage8.1/local/lib/python2.7/site-packages/sage/misc/cython.py:313: DeprecationWarning: the Sage-specific Cython pragma '#clang' is deprecated;
use '# distutils: language' instead

but the code is running. When I change # cfile /Users/okazymyrov/Downloads/sbox/C/CI.c to # distutils: sources = /Users/okazymyrov/Downloads/sbox/C/CI.c in Cython/CFunc.spyx I get the error

Compiling /Users/okazymyrov/Downloads/sbox/Sage/../Cython/CFunc.spyx...
/Users/okazymyrov/bin/sage8.1/local/lib/python2.7/site-packages/sage/misc/cython.py:322: DeprecationWarning: the Sage-specific Cython pragma '#cfile' is deprecated;
use '# distutils: sources' instead
See http://trac.sagemath.org/24105 for details.
  additional_source_files, s = _parse_keywords('cfile', s)
Traceback (most recent call last):
  File "./Main.sage.py", line 27, in <module>
    load("./TestFunctions.sage")
  File "sage/structure/sage_object.pyx", line 1057, in sage.structure.sage_object.load (build/cythonized/sage/structure/sage_object.c:12915)
  File "/Users/okazymyrov/bin/sage8.1/local/lib/python2.7/site-packages/sage/repl/load.py", line 247, in load
    exec(preparse_file(open(fpath).read()) + "\n", globals)
  File "<string>", line 21, in <module>
  File "sage/structure/sage_object.pyx", line 1057, in sage.structure.sage_object.load (build/cythonized/sage/structure/sage_object.c:12915)
  File "/Users/okazymyrov/bin/sage8.1/local/lib/python2.7/site-packages/sage/repl/load.py", line 247, in load
    exec(preparse_file(open(fpath).read()) + "\n", globals)
  File "<string>", line 41, in <module>
  File "sage/structure/sage_object.pyx", line 1057, in sage.structure.sage_object.load (build/cythonized/sage/structure/sage_object.c:12915)
  File "/Users/okazymyrov/bin/sage8.1/local/lib/python2.7/site-packages/sage/repl/load.py", line 251, in load
    exec(load_cython(fpath), globals)
  File "<string>", line 1, in <module>
ImportError: dlopen(/Users/okazymyrov/.sage/temp/hamsin.local/37857/spyx/_Users_okazymyrov_Downloads_sbox_Cython_CFunc_spyx/_Users_okazymyrov_Downloads_sbox_Cython_CFunc_spyx_0.so, 2): Symbol not found: _CI
  Referenced from: /Users/okazymyrov/.sage/temp/hamsin.local/37857/spyx/_Users_okazymyrov_Downloads_sbox_Cython_CFunc_spyx/_Users_okazymyrov_Downloads_sbox_Cython_CFunc_spyx_0.so
  Expected in: flat namespace
 in /Users/okazymyrov/.sage/temp/hamsin.local/37857/spyx/_Users_okazymyrov_Downloads_sbox_Cython_CFunc_spyx/_Users_okazymyrov_Downloads_sbox_Cython_CFunc_spyx_0.so

The load sequence is the following:

  1. Main.sage loads Sbox.sage
  2. Sbox.sage loads CFunc.spyx
  3. CFunc.spyx must be compiled with other C files located in ./C

System info:

bash-3.2$ sage --version
SageMath version 8.1, Release Date: 2017-12-07
bash-3.2$ uname -a
Darwin hamsin.local 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar  5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64

Might be a bug in the Cython parse class?

Kind regards, Oleksandr

koffie commented 6 years ago

Hi Oleksandr,

Thank you for your bug report, however this github repository is only used as a mirror. If you want to get help with this issue you will most likely get more success if you post it to the sage-devel mailinglist at https://groups.google.com/forum/#!forum/sage-devel . Our bug tracking happens at https://trac.sagemath.org/ .

Thanks, Maarten

jdemeyer commented 6 years ago

And it would to have a minimal example, see http://sscce.org/

okazymyrov commented 6 years ago

The issue was fixed by adding "# distutils: sources" to the first lines of the file before any other comments.