Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29250 ディスカッション

Ipo with shared library

ChrisC2
初心者
3,674件の閲覧回数

I've been trying on an off for some time now to get Ipo compilation and linking to work with a shared library I am building.   Thought I would try again with 2024.1, and still no luck.    Project is build with CMake (3.28) in VS2022.   

 

Long story short, I get the message 'llvm-nm returned an error : /usr/bin/nm: unrecognized option '--no-weak'

 

I assume Cmake is trying to turn off weak linking, which is causing a failure.   I've both tried manually specifying the ipo commands, and also using setting INTERPROCEDURAL_OPTIMIZTION to True to let Cmake handle the flags.  Both get the same message above.   

0 件の賞賛
12 返答(返信)
Barbara_P_Intel
従業員
3,617件の閲覧回数

Please post a small reproducer. There's not enough information here to offer any advice.

 

ChrisC2
初心者
3,590件の閲覧回数

I've attached a simple CMake project that replicates the error for me.  I'm using VS2022 to run this, but should be able to run it in a standalone CLI as well.   If the library type is changed from SHARED to STATIC, it compiles with no issues.  

Barbara_P_Intel
従業員
3,475件の閲覧回数

@ChrisC2, have you had any success in resolving this?

Are you using ifort or ifx? For me your .sln is using ifort.

I'm a little confused about what OS you are using. You mention VS 2022, but the path in the error message is a Linux path.

Does the .sln you uploaded compile successfully for you or is this the failing version?

I'm using Windows 11, VS2022 17.8.1, cmake version 3.27.2-msvc1, ifort 2021.12.0.

ChrisC2
初心者
3,438件の閲覧回数

I have not resolved it.  

 

The compiler is ifx.   (Line 3 of the top level CMakeLists.txt sets compiler to ifx)

 

I've tried to build in both Linux and Windows and both show a similar error.   I must have grabbed the error message from linux.  (Though Windows I have OneAPI 2024.1, Linux is 2023.2)

 

This being a CMake project, there is no sln file.  But you can open it in Visual Studio via File > Open > Folder.  And yes, the uploaded project shows the behavior for me.   

 

I've copied in the build output file for a Windows build in Visual Studio.   Perhaps this provides some more details.   

 

>------ Build All started: Project: dynamic_link_error, Configuration: x64-release ------
[1/6] Building Fortran preprocessed src\CMakeFiles\test_module.dir\test_module.f90-pp.f90
[2/6] Generating Fortran dyndep file src\CMakeFiles\test_module.dir\Fortran.dd
[3/6] Generating Fortran dyndep file app\CMakeFiles\test_exe.dir\Fortran.dd
[4/7] Building Fortran object src\CMakeFiles\test_module.dir\test_module.f90.obj
[5/7] Building Fortran object app\CMakeFiles\test_exe.dir\test_exe.f90.obj
[6/7] Linking Fortran shared library src\test_module.dll
FAILED: src/test_module.dll src/test_module.lib
C:\WINDOWS\system32\cmd.exe /C "C:\WINDOWS\system32\cmd.exe /C ""C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E __create_def C:\Work\Fortran\dynamic_link_error\out\build\x64-release\src\CMakeFiles\test_module.dir\.\exports.def C:\Work\Fortran\dynamic_link_error\out\build\x64-release\src\CMakeFiles\test_module.dir\.\exports.def.objs && cd C:\Work\Fortran\dynamic_link_error\out\build\x64-release" && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_dll --intdir=src\CMakeFiles\test_module.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe /nologo src\CMakeFiles\test_module.dir\test_module.f90.obj -LD /Qoption,link,/machine:x64 /debug /INCREMENTAL -Qipo /Qoption,link,/DEF:src\CMakeFiles\test_module.dir\.\exports.def user32.lib -link /out:src\test_module.dll /implib:src\test_module.lib /pdb:test_module.dll.dbg /version:0.0 && cd ."
C:\Work\Fortran\dynamic_link_error\out\build\x64-release\EXEC : llvm-nm returned an error : nm: unrecognized option `--no-weak'
Usage: nm [option(s)] [file(s)]
List symbols in [file(s)] (a.out by default).
The options are:
-a, --debug-syms Display debugger-only symbols
-A, --print-file-name Print name of the input file before every symbol
-B Same as --format=bsd
-C, --demangle[=STYLE] Decode low-level symbol names into user-level names
The STYLE, if specified, can be `auto' (the default),
`gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'
or `gnat'
--no-demangle Do not demangle low-level symbol names
-D, --dynamic Display dynamic symbols instead of normal symbols
--defined-only Display only defined symbols
-e (ignored)
-f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd',
`sysv' or `posix'. The default is `bsd'
-g, --extern-only Display only external symbols
-l, --line-numbers Use debugging information to find a filename and
line number for each symbol
-n, --numeric-sort Sort symbols numerically by address
-o Same as -A
-p, --no-sort Do not sort the symbols
-P, --portability Same as --format=posix
-r, --reverse-sort Reverse the sense of the sort
--plugin NAME Load the specified plugin
-S, --print-size Print size of defined symbols
-s, --print-armap Include index for symbols from archive members
--size-sort Sort symbols by size
--special-syms Include special symbols in the output
--synthetic Display synthetic symbols as well
-t, --radix=RADIX Use RADIX for printing symbol values
--target=BFDNAME Specify the target object format as BFDNAME
-u, --undefined-only Display only undefined symbols

-X 32_64 (ignored)

@FILE Read options from FILE

-h, --help Display this information

-V, --version Display this program's version number



nm: supported targets: pe-i386 pei-i386 elf32-i386 elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex



ninja: build stopped: subcommand failed.

Build All failed.

Barbara_P_Intel
従業員
3,432件の閲覧回数

@ChrisC2, you wrote that you have the same issue on Linux. Can you please upload a .zip for the Linux version?

I ask because I see the .json file is all about Windows and ninja.

Or does that even matter? My skills are better with Linux.

 

Barbara_P_Intel
従業員
3,389件の閲覧回数

One more thing... When I use the .zip file you uploaded on Windows, it builds with ifort, not ifx. Please upload a reproducer for Windows that uses ifx.

I've been in touch with Intel's CMake engineer; he uploads Intel updates for CMake. He wrote that the MSVC generator ignores CMAKE_Fortran_COMPILER, you need to set the platform toolset.  For CMake 3.29, to use ifx you can use 

    cmake  -T "Intel C++ Compiler 2024,fortran=ifx" ..

Please share the exact CMake commands you are using.

 

ChrisC2
初心者
3,374件の閲覧回数

Barbara, thanks for your persistence on this.   First off, I was wrong about LInux.  I thought it showed similar behavior there, but I tried my simple reproducer on LInux and it worked fine.   Should note while it was using CMake the build system on Linux is Make.

 

To reproduce the error, in a IntelOneAPI command prompt for VS2022, in the directory the project is in:

cmake -B out --preset x64-release

cmake --build out

 

(If you don't specify the preset I also get iFort instead of ifx).  Just as a test, I downloaded the latest release version of CMake (3.29.2) and Ninja (v1.12) and tried to build using that version and get the same error.   

Next, I went and pulled the link commands the are being specified to link the exe, ran those commands manually, and the link process worked fine.   So as best I can tell the issue is in either CMake or Ninja in the way it packages the link commands?   

 

   

Barbara_P_Intel
従業員
3,243件の閲覧回数

Can you please do `cmake –build out -v` and share the output? 

ninja will print out all the commands it uses and we can see what is missing or incorrect.

 

ChrisC2
初心者
3,218件の閲覧回数

Sure.  I've run those commands, output below.   I've posted the first command output first.   Then I tried running the build command again, and showed a different error that may be more specific regarding undefined symbol. 

 

First run: 

C:\Work\Fortran\dynamic_link_error>cmake --build out -v
Change Dir: 'C:/Work/Fortran/dynamic_link_error/out'

Run Build Command(s): C:/PROGRA~1/MICROS~4/2022/PROFES~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe -v
[1/8] C:\WINDOWS\system32\cmd.exe /C "C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe -fpp -Dtest_module_EXPORTS /W1 /nologo /fpp /libs:dll /threads /O3 /debug /arch:AVX2 /fp:fast=2 /Qprec-div- /Qopenmp /Qopt-report -Qipo -module:Modules -P C:\Work\Fortran\dynamic_link_error\src\test_module.f90 -Fisrc\CMakeFiles\test_module.dir\test_module.f90-pp.f90 && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E cmake_ninja_depends --tdi=src\CMakeFiles\test_module.dir\FortranDependInfo.json --lang=Fortran --src=src\CMakeFiles\test_module.dir\test_module.f90-pp.f90 --out=src\CMakeFiles\test_module.dir\test_module.f90-pp.f90 --dep=src\CMakeFiles\test_module.dir\test_module.f90-pp.f90.d --obj=src\CMakeFiles\test_module.dir\test_module.f90.obj --ddi=src\CMakeFiles\test_module.dir\test_module.f90.obj.ddi"
[2/8] C:\WINDOWS\system32\cmd.exe /C "C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe -fpp /W1 /nologo /fpp /libs:dll /threads /O3 /debug /arch:AVX2 /fp:fast=2 /Qprec-div- /Qopenmp /Qopt-report -Qipo -module:Modules -P C:\Work\Fortran\dynamic_link_error\app\test_exe.f90 -Fiapp\CMakeFiles\test_exe.dir\test_exe.f90-pp.f90 && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E cmake_ninja_depends --tdi=app\CMakeFiles\test_exe.dir\FortranDependInfo.json --lang=Fortran --src=app\CMakeFiles\test_exe.dir\test_exe.f90-pp.f90 --out=app\CMakeFiles\test_exe.dir\test_exe.f90-pp.f90 --dep=app\CMakeFiles\test_exe.dir\test_exe.f90-pp.f90.d --obj=app\CMakeFiles\test_exe.dir\test_exe.f90.obj --ddi=app\CMakeFiles\test_exe.dir\test_exe.f90.obj.ddi"
[3/8] "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E cmake_ninja_dyndep --tdi=src\CMakeFiles\test_module.dir\FortranDependInfo.json --lang=Fortran --dd=src\CMakeFiles\test_module.dir\Fortran.dd @SRC\CMakeFiles\test_module.dir\Fortran.dd.rsp
[4/8] "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E cmake_ninja_dyndep --tdi=app\CMakeFiles\test_exe.dir\FortranDependInfo.json --lang=Fortran --dd=app\CMakeFiles\test_exe.dir\Fortran.dd @app\CMakeFiles\test_exe.dir\Fortran.dd.rsp
[5/8] C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe /nologo /fpp -Dtest_module_EXPORTS -IC:\Work\Fortran\dynamic_link_error\src /W1 /nologo /fpp /libs:dll /threads /O3 /debug /arch:AVX2 /fp:fast=2 /Qprec-div- /Qopenmp /Qopt-report -Qipo -module:Modules /Fosrc\CMakeFiles\test_module.dir\test_module.f90.obj /Fd -c src\CMakeFiles\test_module.dir\test_module.f90-pp.f90
[6/8] C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe /nologo /fpp -IC:\Work\Fortran\dynamic_link_error\app /W1 /nologo /fpp /libs:dll /threads /O3 /debug /arch:AVX2 /fp:fast=2 /Qprec-div- /Qopenmp /Qopt-report -Qipo -module:Modules /Foapp\CMakeFiles\test_exe.dir\test_exe.f90.obj /Fd -c app\CMakeFiles\test_exe.dir\test_exe.f90-pp.f90
[7/8] C:\WINDOWS\system32\cmd.exe /C "C:\WINDOWS\system32\cmd.exe /C ""C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E __create_def C:\Work\Fortran\dynamic_link_error\out\src\CMakeFiles\test_module.dir\.\exports.def C:\Work\Fortran\dynamic_link_error\out\src\CMakeFiles\test_module.dir\.\exports.def.objs && cd C:\Work\Fortran\dynamic_link_error\out" && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_dll --intdir=src\CMakeFiles\test_module.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe /nologo src\CMakeFiles\test_module.dir\test_module.f90.obj -LD /Qoption,link,/machine:x64 /debug /INCREMENTAL -Qipo /Qoption,link,/DEF:src\CMakeFiles\test_module.dir\.\exports.def user32.lib -link /out:src\test_module.dll /implib:src\test_module.lib /pdb:test_module.dll.dbg /version:0.0 && cd ."
FAILED: src/test_module.dll src/test_module.lib
C:\WINDOWS\system32\cmd.exe /C "C:\WINDOWS\system32\cmd.exe /C ""C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E __create_def C:\Work\Fortran\dynamic_link_error\out\src\CMakeFiles\test_module.dir\.\exports.def C:\Work\Fortran\dynamic_link_error\out\src\CMakeFiles\test_module.dir\.\exports.def.objs && cd C:\Work\Fortran\dynamic_link_error\out" && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_dll --intdir=src\CMakeFiles\test_module.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe /nologo src\CMakeFiles\test_module.dir\test_module.f90.obj -LD /Qoption,link,/machine:x64 /debug /INCREMENTAL -Qipo /Qoption,link,/DEF:src\CMakeFiles\test_module.dir\.\exports.def user32.lib -link /out:src\test_module.dll /implib:src\test_module.lib /pdb:test_module.dll.dbg /version:0.0 && cd ."
llvm-nm returned an error: nm: unrecognized option `--no-weak'
Usage: nm [option(s)] [file(s)]
List symbols in [file(s)] (a.out by default).
The options are:
-a, --debug-syms Display debugger-only symbols
-A, --print-file-name Print name of the input file before every symbol
-B Same as --format=bsd
-C, --demangle[=STYLE] Decode low-level symbol names into user-level names
The STYLE, if specified, can be `auto' (the default),
`gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'
or `gnat'
--no-demangle Do not demangle low-level symbol names
-D, --dynamic Display dynamic symbols instead of normal symbols
--defined-only Display only defined symbols
-e (ignored)
-f, --format=FORMAT Use the output format FORMAT. FORMAT can be `bsd',
`sysv' or `posix'. The default is `bsd'
-g, --extern-only Display only external symbols
-l, --line-numbers Use debugging information to find a filename and
line number for each symbol
-n, --numeric-sort Sort symbols numerically by address
-o Same as -A
-p, --no-sort Do not sort the symbols
-P, --portability Same as --format=posix
-r, --reverse-sort Reverse the sense of the sort
--plugin NAME Load the specified plugin
-S, --print-size Print size of defined symbols
-s, --print-armap Include index for symbols from archive members
--size-sort Sort symbols by size
--special-syms Include special symbols in the output
--synthetic Display synthetic symbols as well
-t, --radix=RADIX Use RADIX for printing symbol values
--target=BFDNAME Specify the target object format as BFDNAME
-u, --undefined-only Display only undefined symbols
-X 32_64 (ignored)
@FILE Read options from FILE
-h, --help Display this information
-V, --version Display this program's version number

nm: supported targets: pe-i386 pei-i386 elf32-i386 elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex

ninja: build stopped: subcommand failed.

 

 

Second run:

C:\Work\Fortran\dynamic_link_error>cmake --build out -v
Change Dir: 'C:/Work/Fortran/dynamic_link_error/out'

Run Build Command(s): C:/PROGRA~1/MICROS~4/2022/PROFES~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe -v
[1/2] C:\WINDOWS\system32\cmd.exe /C "C:\WINDOWS\system32\cmd.exe /C ""C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E __create_def C:\Work\Fortran\dynamic_link_error\out\src\CMakeFiles\test_module.dir\.\exports.def C:\Work\Fortran\dynamic_link_error\out\src\CMakeFiles\test_module.dir\.\exports.def.objs && cd C:\Work\Fortran\dynamic_link_error\out" && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_dll --intdir=src\CMakeFiles\test_module.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe /nologo src\CMakeFiles\test_module.dir\test_module.f90.obj -LD /Qoption,link,/machine:x64 /debug /INCREMENTAL -Qipo /Qoption,link,/DEF:src\CMakeFiles\test_module.dir\.\exports.def user32.lib -link /out:src\test_module.dll /implib:src\test_module.lib /pdb:test_module.dll.dbg /version:0.0 && cd ."
[2/2] C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=app\CMakeFiles\test_exe.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe /nologo app\CMakeFiles\test_exe.dir\test_exe.f90.obj /Qoption,link,/machine:x64 /debug /INCREMENTAL /Qoption,link,/subsystem:console -Qipo src\test_module.lib user32.lib /link /out:app\test_exe.exe /implib:app\test_exe.lib /pdb:test_exe.exe.dbg /version:0.0 && cd ."
FAILED: app/test_exe.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=app\CMakeFiles\test_exe.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe /nologo app\CMakeFiles\test_exe.dir\test_exe.f90.obj /Qoption,link,/machine:x64 /debug /INCREMENTAL /Qoption,link,/subsystem:console -Qipo src\test_module.lib user32.lib /link /out:app\test_exe.exe /implib:app\test_exe.lib /pdb:test_exe.exe.dbg /version:0.0 && cd ."
LINK Pass 1: command "C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\ifx.exe /nologo app\CMakeFiles\test_exe.dir\test_exe.f90.obj /Qoption,link,/machine:x64 /debug /INCREMENTAL /Qoption,link,/subsystem:console -Qipo src\test_module.lib user32.lib /link /out:app\test_exe.exe /implib:app\test_exe.lib /pdb:test_exe.exe.dbg /version:0.0 /MANIFEST /MANIFESTFILE:app\CMakeFiles\test_exe.dir/intermediate.manifest app\CMakeFiles\test_exe.dir/manifest.res" failed (exit code 1) with the following output:
lld-link: error: undefined symbol: TEST_MODULE_mp_TEST_FUNC
>>> referenced by 4024446.i90
>>> app\CMakeFiles\test_exe.dir\test_exe.f90.obj
ninja: build stopped: subcommand failed.

 

    

ChrisC2
初心者
3,218件の閲覧回数

C:\Work\Fortran\dynamic_link_error\out\src\CMakeFiles\test_module.dir\.\exports.def

 

The path to the exports files looks suspect.   The actual path is:

C:\Work\Fortran\dynamic_link_error\out\src\CMakeFiles\test_module.dir\exports.def

Barbara_P_Intel
従業員
2,981件の閲覧回数

Thanks for the additional info, @ChrisC2. This issue may be related to your environment. Maybe the PATH? Do you have CLANG products installed?

The version of llvm-nm distributed by Intel is in C:\Program Files (x86)\Intel\oneAPI\compiler\latest\bin\compiler\llvm-nm.exe.

We noticed that the -help output is a bit different between what you posted and what we get from the Intel distribution

.

 

 

ChrisC2
初心者
2,131件の閲覧回数

Quick follow-up to this topic to document what I've found.  I do have an install of Cygwin installed with the bin directory in my Path, which Barbara noted above.   This was confusing, but once this was removed, the errors changed to a consistent lack of export symbols for the linker.   Doing some more digging, I believe the github issue below describes in detail the issue that caused this.  

 

https://github.com/luxonis/depthai-core/issues/334

 

In short, CMake has a flag, CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS which is very handy when building shared libraries on Windows.   CMake scans the obj files to generate a def list.  However that doesn't work with ipo enabled, and Cmake generates emtpy def files.  As a result, I"ve gone back to using !DIR$ ATTRIBUTES DLLEXPORT for this particular project, which seems to have corrected this.  

返信