c++cmakeintel-oneapi

Linker issue with oneAPI if I use the -ipo flag


I'm using oneAPI (intel's compiler) and ran into issues using the -ipo flag when compiling. The setup:

Files: my_lib:

my_test:

Folder structure looks like this:

I'd run cmake on my_test's CMakeLists.txt, then run make. Thee error I get is:

...
...
[100%] Linking CXX executable my_test
/usr/bin/ld: my_lib/my_lib.a: error adding symbols: archive has no index; run ranlib to add one
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/my_test.dir/build.make:98: my_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/my_test.dir/all] Error 2

Any ideas why I can't link this simple code?


Solution

  • I read somewhere that the default GNU linker wouldn't be able to make sense of binaries built using the Intel compiler with the -ipo flag on. I switched to using the LLVM linker and it worked.

    To turn that on, I added this to the CMakeLists file

    add_link_options("-fuse-ld=lld")