0

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.

Nam Vu
  • 3
  • 1
  • I suspect macros involved. Can you do a compilation attempt with `-E` added to the commandline for the compiler? That should result (with almost all compilers) in a preprocessed output file. If you then have trouble finding the line in question in that first insert a `typdef int MyOwnBookmarkTypeBlaBla;`. You can probably tell that this line only serves to be easily searchable. The strange name only needs to be unique... You can search for it and will find the preprocessed version of your line 184 afterwards. If you then do not see `I` but do see e.g. `__extension__` we have a macro. – Yunnosch Jul 12 '23 at 08:34
  • I am aware that defining a macro as short as `I` is not a good idea (but only slightly worse than defining a type `I`...). If it is a widely used lib neither should be in there. But I propose to rule that out. – Yunnosch Jul 12 '23 at 08:37
  • [\[SO\]: Welcome to Stack Overflow](https://stackoverflow.com/tour). Check [\[SO\]: How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) or **[\[SO\]: How to create a Minimal, Reproducible Example (reprex (mcve))](https://stackoverflow.com/help/minimal-reproducible-example)** for more asking related details. – CristiFati Jul 12 '23 at 13:51

1 Answers1

0

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.

BoP
  • 2,310
  • 1
  • 15
  • 24