Skip to content

Set C std to C17 to avoid errors with gcc 15 #130

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nmnobre
Copy link

@nmnobre nmnobre commented Apr 30, 2025

Hi,

I think there is no harm in setting the C standard to the version the code actually conforms to at the moment.
Though I'd agree that updating the code to conform to C23 should be the long term goal.
Addresses #129.

Cheers,
Nuno

@mgates3
Copy link
Contributor

mgates3 commented Jun 12, 2025

I can confirm that this fixes the issue "error: too many arguments to function" with gcc ≥ 15 (#129).

It doesn't fix the issue "error: implicit declaration of function" with gcc ≥ 10 (#97). That requires adding a CFLAG as described below and in #97.

Using gcc 15.1.0, before this PR, there are "too many arguments to function" errors:

scalapack/build> cmake ..
...
scalapack/build> make SRC/pcrot.o VERBOSE=1
make  -f CMakeFiles/scalapack.dir/build.make CMakeFiles/scalapack.dir/SRC/pcrot.c.o
[ 67%] Building C object CMakeFiles/scalapack.dir/SRC/pcrot.c.o
/opt/homebrew/bin/gcc -DAdd_ -isystem /opt/homebrew/Cellar/open-mpi/5.0.7/include -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -MD -MT CMakeFiles/scalapack.dir/SRC/pcrot.c.o -MF CMakeFiles/scalapack.dir/SRC/pcrot.c.o.d -o CMakeFiles/scalapack.dir/SRC/pcrot.c.o -c /Users/mgates/Documents/scalapack/SRC/pcrot.c
/Users/mgates/Documents/scalapack/SRC/pcrot.c: In function 'pcrot_':
/Users/mgates/Documents/scalapack/SRC/pcrot.c:199:4: error: too many arguments to function 'blacs_gridinfo_'; expected 0, have 5
  199 |    blacs_gridinfo_( &ictxt, &nprow, &npcol, &myrow, &mycol );
      |    ^~~~~~~~~~~~~~~  ~~~~~~
/Users/mgates/Documents/scalapack/SRC/pcrot.c:184:16: note: declared here
  184 |    void        blacs_gridinfo_();
      |                ^~~~~~~~~~~~~~~
...

After this PR, it sets -std=gnu17 (not c17 as requested, because CMake is stupid), but now have "implicit declaration" errors:

scalapack/build> cmake ..
...
scalapack/build> make SRC/pcrot.o VERBOSE=1
make  -f CMakeFiles/scalapack.dir/build.make CMakeFiles/scalapack.dir/SRC/pcrot.c.o
Building C object CMakeFiles/scalapack.dir/SRC/pcrot.c.o
/opt/homebrew/bin/gcc -DAdd_ -isystem /opt/homebrew/Cellar/open-mpi/5.0.7/include -std=gnu17 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -MD -MT CMakeFiles/scalapack.dir/SRC/pcrot.c.o -MF CMakeFiles/scalapack.dir/SRC/pcrot.c.o.d -o CMakeFiles/scalapack.dir/SRC/pcrot.c.o -c /Users/mgates/Documents/scalapack/SRC/pcrot.c
/Users/mgates/Documents/scalapack/SRC/pcrot.c: In function 'pcrot_':
/Users/mgates/Documents/scalapack/SRC/pcrot.c:320:12: error: implicit declaration of function 'numroc_' [-Wimplicit-function-declaration]
  320 |       nq = numroc_( &nn, &desc_X[NB_], &mycol, &ixcol, &npcol );
      |            ^~~~~~~
make[1]: *** [CMakeFiles/scalapack.dir/build.make:19058: CMakeFiles/scalapack.dir/SRC/pcrot.c.o] Error 1
make: *** [Makefile:19709: SRC/pcrot.c.o] Error 2

Setting -DCMAKE_C_FLAGS="-Wno-error=implicit-function-declaration" turns the "implicit declaration" into a warning:

scalapack/build> cmake -DCMAKE_C_FLAGS="-Wno-error=implicit-function-declaration" ..
...
scalapack/build> make SRC/pcrot.o VERBOSE=1
make  -f CMakeFiles/scalapack.dir/build.make CMakeFiles/scalapack.dir/SRC/pcrot.c.o
Building C object CMakeFiles/scalapack.dir/SRC/pcrot.c.o
/opt/homebrew/bin/gcc -DAdd_ -isystem /opt/homebrew/Cellar/open-mpi/5.0.7/include -Wno-error=implicit-function-declaration -std=gnu17 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -MD -MT CMakeFiles/scalapack.dir/SRC/pcrot.c.o -MF CMakeFiles/scalapack.dir/SRC/pcrot.c.o.d -o CMakeFiles/scalapack.dir/SRC/pcrot.c.o -c /Users/mgates/Documents/scalapack/SRC/pcrot.c
/Users/mgates/Documents/scalapack/SRC/pcrot.c: In function 'pcrot_':
/Users/mgates/Documents/scalapack/SRC/pcrot.c:320:12: warning: implicit declaration of function 'numroc_' [-Wimplicit-function-declaration]
  320 |       nq = numroc_( &nn, &desc_X[NB_], &mycol, &ixcol, &npcol );
      |            ^~~~~~~

(That worked for me. @fsidoli reported in #97 that they had to use -fpermissive instead.)

@nmnobre
Copy link
Author

nmnobre commented Jun 12, 2025

After this PR, it sets -std=gnu17 (not c17 as requested, because CMake is stupid)

Amended to fix that.

Setting -DCMAKE_C_FLAGS="-Wno-error=implicit-function-declaration" turns the "implicit declaration" into a warning

Yes, we can also disable the error/warning with -Wno-implicit-function-declaration. I use ScaLAPACK through PETSc, and PETSc sets this flag, thus why I didn't encounter the errors you mentioned.

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

Successfully merging this pull request may close these issues.

2 participants