Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Compiling Cython with C header files error

So I'm trying to wrap some C code with Cython. I read read applied Cython's tutorials on doing this (1, 2), but these tutorials do not say much on how to compile the code once you have wrapped it with Cython, and so I have an error saying it can't find my C code.

First, my cython script ("calcRMSD.pyx"):

import numpy as np
cimport numpy as np

cdef extern from "rsmd.h":
    double rmsd(int n, double* x, double* y)

#rest of the code ommited

The C code I am trying to wrap ("rmsd.h"):

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

extern "C" {
  // svd from lapack
  void dgesvd_(char*,char*,int*,int*,double*,int*,double*,double*,int*,double*,
           int*,double*,int*,int*);
}

double rmsd(int n, double* x, double* y)
{
   //code omitted
}

Setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
from Cython.Build import cythonize
import numpy as np


setup(
    ext_modules = cythonize([Extension("calcRMSD", 
                            sources = ["calcRMSD.pyx"],
                            include_dirs = [np.get_include()],
                            libraries = ["dgesvd"]
                            #extra_compile_args = ["-I."],
                            #extra_link_args = ["-L./usr/lib/liblapack.dylib"]
                            )])

) 

My error:

calcRMSD.c:269:10: fatal error: 'rsmd.h' file not found
#include "rsmd.h"

I read this stack overflow thread Using Cython To Link Python To A Shared Library

but following it gives me different errors. If I try to put rmsd.h in sources, it says it doesnt recognize the file type.

How to link custom C (which itself needs special linking options to compile) with Cython?

This looks somewhat promising but im not sure how to use it.

Please help!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

First of all it has to find the include file, rsmd.h. You need to add the path where this header can be found to the include_dirs parameter. The error about the missing file should disappear.

Then you will additionally need to include the library you get from compiling that C code. If that's librsmd.a you would add 'rsmd' to the libraries parameter. Additionally you might need a library_dirs parameter that contains the path where that library can be found.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!