CMake + Intel Compilers Help

57 views
Skip to first unread message

Deven Phillips

unread,
Jun 28, 2023, 1:56:25 PM6/28/23
to kyoss-...@kyoss.dev
Hoping someone here might have a hint at why I am getting this linker error:

I have installed the Intel DPC++/C++ and FORTRAN compilers and I am trying to use them to compile and statically link the following example project:

https://github.com/InfoSec812/mixed-c-fortran-cmake-project

But even after following their instructions to source the environment variables I am getting:

[100%] Linking Fortran executable c_fortran_example.x
ifx: command line warning #10157: ignoring option '-W'; argument is of wrong type
ld: cannot find -lm: No such file or directory
ld: cannot find -lc: No such file or directory
ld: cannot find -lc: No such file or directory
make[2]: *** [CMakeFiles/c_fortran_example.x.dir/build.make:112: c_fortran_example.x] Error 1
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/c_fortran_example.x.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Any suggestions?

Thanks in advance!

Deven

Jeff Squyres

unread,
Jun 28, 2023, 2:36:40 PM6/28/23
to KYOSS Discuss List
What is the exact command line that cmake is launching to invoke the link?


--
You received this message because you are subscribed to the Google Groups "KYOSS general discussion list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kyoss-discus...@kyoss.dev.


-- 
{+} Jeff Squyres

Jeff Squyres

unread,
Jun 28, 2023, 2:49:15 PM6/28/23
to KYOSS Discuss List
I see the following in that cmake example project:

https://github.com/InfoSec812/mixed-c-fortran-cmake-project/blob/main/CMakeLists.txt#L30C1-L30C26

link_libraries("-static")

That seems dubious to me.  Do you *need* to link statically?  Static linking is not for the meek.


-- 
{+} Jeff Squyres

Deven Phillips

unread,
Jun 28, 2023, 3:32:23 PM6/28/23
to kyoss-...@kyoss.dev
Yeah, that's the issue I am trying to help my customer solve. They would like to compile to a static binary. I can get it to compile without static linking just fine.

Deven


Jeff Squyres

unread,
Jun 28, 2023, 4:50:31 PM6/28/23
to KYOSS Discuss List
Do you have the static libc and libm installed?  It may be in a different RPM than the usual compiler- or OS-provided libc and libm shared libraries.


On Jun 28, 2023, at 3:32 PM, Deven Phillips <deven.p...@gmail.com> wrote:

Yeah, that's the issue I am trying to help my customer solve. They would like to compile to a static binary. I can get it to compile without static linking just fine.

Deven



--
You received this message because you are subscribed to the Google Groups "KYOSS general discussion list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kyoss-discus...@kyoss.dev.


-- 
{+} Jeff Squyres

Michael Speer

unread,
Jun 28, 2023, 5:11:23 PM6/28/23
to kyoss-...@kyoss.dev
no errors compiling that example repo with gfortran, except the flag

looking at the log you posted

    set(CMAKE_Fortran_FLAGS         "${CMAKE_Fortran_FLAGS} -nofor-main -Wall")


    ifx: command line warning #10157: ignoring option '-W'; argument is of wrong type

ifx is the intel fortran compiler.

I don't see a -W flag for ifx. there is -Wa, but that is for passing arguments through to the linker


this won't be the compile error though, since it just ignores it

it also works with the ifx compiler on my system. I was running it in an empty docker overlaying a readonly copy of everything except the directory it was compiling in and a writable overlay for my home dir, so nothing of mine should have affected it. ( intel provides it as an sh script that downloads stuff. I didn't know what it would be doing so I jailed it )

     FC=/home/knome/intel/oneapi/compiler/2023.1.0/linux/bin/ifx CMAKE_Fortran_COMPILER=/home/knome/intel/oneapi/compiler/2023.1.0/linux/bin/ifx CMAKE_FC_COMPILER=/home/knome/intel/oneapi/compiler/2023.1.0/linux/bin/ifx strace -f -v -s 2048 -e execve -o ../STRACE.LOG cmake ./
    ....[snip]....
    time strace -f -v -s 2048 -e execve -o ../MAKE.LOG make
    [ 20%] Building Fortran object CMakeFiles/hello.dir/test.f90.o

    ifx: command line warning #10157: ignoring option '-W'; argument is of wrong type
    /home/knome/programs/deven/mixed-c-fortran-cmake-project/test.f90(1): warning #6178: The return value of this FUNCTION has not been defined.   [HELLO]
    FUNCTION HELLO (A)
    ---------^
    [ 40%] Linking Fortran static library libhello.a
    [ 40%] Built target hello
    [ 60%] Building Fortran object CMakeFiles/c_fortran_example.x.dir/test.f90.o

    ifx: command line warning #10157: ignoring option '-W'; argument is of wrong type
    /home/knome/programs/deven/mixed-c-fortran-cmake-project/test.f90(1): warning #6178: The return value of this FUNCTION has not been defined.   [HELLO]
    FUNCTION HELLO (A)
    ---------^
    [ 80%] Building C object CMakeFiles/c_fortran_example.x.dir/main.c.o

    [100%] Linking Fortran executable c_fortran_example.x
    ifx: command line warning #10157: ignoring option '-W'; argument is of wrong type
    [100%] Built target c_fortran_example.x
    0.25user 0.62system 0:01.16elapsed 75%CPU (0avgtext+0avgdata 43764maxresident)k
    10408inputs+3776outputs (0major+24643minor)pagefaults 0swaps

...

    $ ./c_fortran_example.x
     Hello   7.5151020E-39 \n
    $ 

...

final conclusion: works on my box


On Wed, Jun 28, 2023 at 3:32 PM Deven Phillips <deven.p...@gmail.com> wrote:
Yeah, that's the issue I am trying to help my customer solve. They would like to compile to a static binary. I can get it to compile without static linking just fine.

Deven


Michael Speer

unread,
Jun 28, 2023, 5:14:08 PM6/28/23
to kyoss-...@kyoss.dev
deven: run it as `strace -e execve -v -s 2048 -o path/to/some/log make` so you can get the exact compiler invocation that's causing it to crap itself

Michael Speer

unread,
Jun 28, 2023, 5:22:59 PM6/28/23
to kyoss-...@kyoss.dev
You're probably right on that Jeff.


this mentions a glibc-static package.

it also has an entire paragraph about why you shouldn't since glibc will still need to dynamically link and the dynamic copy at runtime must be bitwise identical to the one available during linking.

I expect the requirement for dynamic linking probably comes from stuff like glibc's nsswitch.conf and its arbitrary requirements for dynamic linking.

Michael Speer

unread,
Jun 28, 2023, 5:38:03 PM6/28/23
to kyoss-...@kyoss.dev
as my final spam for the evening,

the arguments to ld include [... "-Bdynamic", "-limf", "-Bstatic", "-lsvml", "-Bdynamic", "-lm", "-Bstatic", "-lipgo", "-lirc", "-Bdynamic", ... ]

in all the calls to ld that are made to compile the project, `-lm` never appears after a `-Bstatic`, only ever after a `-Bdynamic`

so, it might actually be missing the dynamic variants of the libraries rather than the static variants of the libraries that are missing.

Jeff Squyres

unread,
Jun 28, 2023, 6:13:33 PM6/28/23
to kyoss-...@kyoss.dev
Did you really have to run strace to find out exactly what commands cmake is invoking?

😱

Sent from my phone. No type good. 

On Jun 28, 2023, at 5:14 PM, Michael Speer <knom...@gmail.com> wrote:



Jeff Squyres

unread,
Jun 28, 2023, 6:15:10 PM6/28/23
to kyoss-...@kyoss.dev
It would be pretty surprising if libm.so and lib.so are not available. 


Sent from my phone. No type good. 

On Jun 28, 2023, at 5:38 PM, Michael Speer <knom...@gmail.com> wrote:



Michael Speer

unread,
Jun 28, 2023, 6:44:38 PM6/28/23
to kyoss-...@kyoss.dev
>Did you really have to run strace to find out exactly what commands cmake is invoking?

Have to? Probably not.

I wanted to see the invocation of the call to `ld` that I figured was behind the call to `ifx`.

There's probably a switch I could have looked up to make ifx spit out its child process invocations or maybe some way to make cmake do that for me?

But strace is just, right there. And works on any wad of recursively executing programs that doesn't have a setuid sandwiched in it.

*shrug*

Deven Phillips

unread,
Jun 29, 2023, 7:35:53 AM6/29/23
to kyoss-...@kyoss.dev
Jeff's suggestion about not having installed the glibc-static package was exactly what I needed. I just didn't realize that you needed a different package to be able to statically link. All good now! Thanks everyone!

Cheers!

Deven

Deven Phillips

unread,
Jun 29, 2023, 9:18:31 AM6/29/23
to kyoss-...@kyoss.dev
Now, the next challenge! My program compiles and runs. There is just one outstanding issue... The `PRINT` inside of the FORTRAN subroutine "overruns" the null terminator from the C pointer and prints characters beyond where I expected it to:

Example:

❯ ./c_fortran_example.x
Hello World!an_example.x

So, it should stop printing after the exclamation point. Not sure why it doesn't. Thoughts?

I have pushed the updated code to GitHub.

Deven

andy fillebrown

unread,
Jun 29, 2023, 9:26:24 AM6/29/23
to kyoss-...@kyoss.dev

Deven Phillips

unread,
Jun 29, 2023, 9:31:16 AM6/29/23
to kyoss-...@kyoss.dev
Thank you, I have seen that post and found it to be an overly complex solution when the C_Fortran_Interface already has solutions (which should work) for this. I have been looking at this post:

https://www.cdslab.org/recipes/programming/fortran-c-interoperation-string/fortran-c-interoperation-string

Still looking for a better suggestion if anyone finds it.

Cheers,

Deven

Deven Phillips

unread,
Jun 29, 2023, 9:54:09 AM6/29/23
to kyoss-...@kyoss.dev
Hah! I was overcomplicating it (as is typical for me). The updated code on GitHub now works perfectly!

Cheers all!

Thanks,

Deven
Reply all
Reply to author
Forward
0 new messages