Search code examples
cgccshared-librariesctypescblas

error when compiling c flie with cblas.h, getting error error: expected identifier or ‘(’ before ‘__extension__’


I'm trying to create a shared library for python using ctypes. The following command works fine for my purpose:

gcc -g -fPIC -Wall -Wextra -pedantic *.c -shared -o cfunctions.so

However, when I use #include <cblas.h>, I get the following errors:

cfunctions.c:184:12: error: expected identifier or ‘(’ before ‘__extension__’
  184 |        int I=0;
      |            ^
cfunctions.c:192:15: error: invalid operands to binary <= (have ‘complex float’ and ‘int’)
  192 |        while(I<=index && e <= o) {
      |               ^~

I just have a vague understanding of programing, so I guess the letter I is used by cblas to define some data type. Does anyone know what is the problem here? I guess I need to change all of the variables named "I" to something else, but I'm not sure if it fix my problem.


Solution

  • The complex float type in the message hints at I coming from the <complex.h> header.

    https://en.cppreference.com/w/c/numeric/complex/I

    Yet another reason for not using all uppercase in identifiers - they could be macros defined somewhere else.