Skip to content
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

fix file extension error using c++ with %cython #22113

Closed
boothby opened this issue Dec 30, 2016 · 14 comments
Closed

fix file extension error using c++ with %cython #22113

boothby opened this issue Dec 30, 2016 · 14 comments

Comments

@boothby
Copy link

boothby commented Dec 30, 2016

Running this in the notebook...

%cython
#clang c++

produces the following error:

cp: cannot stat ‘_home_boothby__sage_sage_notebook_sagenb_home_admin_90_code_sage6_spyx_0.c’: No such file or directory
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_5.py", line 10, in <module>
    exec compile(u'_support_.cython_import_all("/home/boothby/.sage/sage_notebook.sagenb/home/admin/90/code/sage6.spyx", globals())
  File "", line 1, in <module>
    
  File "/home/boothby/sage-7.4/local/lib/python2.7/site-packages/sagenb/misc/support.py", line 484, in cython_import_all
    create_local_c_file=create_local_c_file)
  File "/home/boothby/sage-7.4/local/lib/python2.7/site-packages/sagenb/misc/support.py", line 461, in cython_import
    create_local_c_file=create_local_c_file)
  File "/home/boothby/sage-7.4/local/lib/python2.7/site-packages/sage/misc/cython.py", line 473, in cython
    raise RuntimeError("Error converting {} to C:\n{}\n{}".format(filename, log, err))
RuntimeError: Error converting /home/boothby/.sage/sage_notebook.sagenb/home/admin/90/code/sage6.spyx to C:

Note that this issue has been known for six years, but wasn't fixed because it was mentioned on a related-looking ticket that got closed: #10249 comment:2

Also, the doctests in misc.cython.cython are problematic in that they look like they're testing that function, but they're actually testing misc.cython_c.cython_compile. To that end, I'm adding another doctest,

    Check that compiling c++ code works, when creating a local c file,
    first moving to a tempdir to avoid clutter::

        sage: import sage.misc.cython, sage.misc.temporary_file, os
        sage: d = sage.misc.temporary_file.tmp_dir()
        sage: os.chdir(d)
        sage: f = open(d+"src.pyx", 'w')
        sage: f.write("#clang C++\n"
        ....:       "from libcpp.vector cimport vector\n"
        ....:       "cdef vector[int] * v = new vector[int](4)\n")
        sage: f.close()
        sage: output = sage.misc.cython.cython(d+"src.pyx", create_local_c_file=True)

Component: cython

Keywords: sagenb cpp cython

Author: Kelly Boothby

Branch/Commit: 77f3c56

Reviewer: Jeroen Demeyer, Julian Rüth

Issue created by migration from https://trac.sagemath.org/ticket/22113

@boothby boothby added this to the sage-7.5 milestone Dec 30, 2016
@boothby
Copy link
Author

boothby commented Dec 30, 2016

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 30, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

c32a075fixing a newbie git-trac mistake

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 30, 2016

Commit: c32a075

@boothby
Copy link
Author

boothby commented Jan 5, 2017

Author: Kelly Boothby

@dimpase
Copy link
Member

dimpase commented Jan 16, 2017

comment:5

Is it OSX's clang, or linux clang that you test it on?

@boothby
Copy link
Author

boothby commented Jan 18, 2017

comment:6

I tested on linux. clang is just a keyword, not the llvm frontend.

@dimpase
Copy link
Member

dimpase commented Jan 18, 2017

comment:7

I find this quite confusing. I'd say that if you use #clang then by right it ought to mean that you have clang installed and all this. (It's actually not hard to install clang and clang++ on linux).

@boothby
Copy link
Author

boothby commented Jan 18, 2017

comment:8

My understanding is that this particular 5-letter string "clang" has absolutely nothing to do with the software project named CLANG (written allcaps to disambiguate).

Please refer to the documentation of sage.misc.cython_c.cython_compile:

    Given a block of Cython code (as a text string), this function compiles it using a C compiler, and includes it into the global scope of the module that called this function.

    The following pragmas are available:

        clang - may be either c or c++ (or C or C++) indicating whether a C or C++ compiler should be used.
        clib - additional libraries to be linked in, the space separated list is split and passed to distutils.
        cinclude - additional directories to search for header files. The space separated list is split and passed to distutils.
        cfile - additional C or C++ files to be compiled. Also, $SAGE_ROOT is expanded, but other environment variables are not.
        cargs - additional parameters passed to the compiler

    For example:

    #clang C++
    #clib givaro
    #cinclude /usr/local/include/
    #cargs -ggdb
    #cfile foo.c

    AUTHOR: William Stein, 2006-10-31

Note that William wrote this code a full year before CLANG was released -- the code was working back then, without CLANG. It should still work without CLANG.

@jdemeyer
Copy link

@jdemeyer
Copy link

Changed commit from c32a075 to 77f3c56

@jdemeyer
Copy link

comment:10

Rebased and simplified the tests. Needs review.


New commits:

eb37060fixed bug where a .c extension was hardcoded and needs to be .cpp sometimes
77f3c56Simplify doctest

@jdemeyer
Copy link

Reviewer: Jeroen Demeyer

@saraedum
Copy link
Member

Changed reviewer from Jeroen Demeyer to Jeroen Demeyer, Julian Rüth

@vbraun
Copy link
Member

vbraun commented Apr 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants