You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue was found when building OpenCV-4.0.1-foss-2018b-Python-3.6.6.eb with EB 4.1.1. The build has multiple errors undefined reference to main. This is caused by the rpath wrappers adding -Wl,-rpath=... options to the g++ call, which turns otherwise compile-only commands to generate precompiled headers (-x c++-header) into commands that link.
paulm@tcn180 14:43 ~$ m list
Currently Loaded Modulefiles:
1) surfsara 2) 2019 3) EasyBuild/4.1.1 4) compilerwrappers 5) eb/4.1.1(default) 6) GCCcore/8.2.0 7) zlib/1.2.11-GCCcore-8.2.0 8) binutils/2.31.1-GCCcore-8.2.0 9) GCC/8.2.0-2.31.1
paulm@tcn180:~$ cat t.cc
#include <cstdio>
# Straight g++ call, no wrappers, succeeds
paulm@tcn180 14:45 ~$ /sw/arch/RedHatEnterpriseServer7/EB_production/2019/software/GCCcore/8.2.0/bin/g++ -x c++-header t.cc
paulm@tcn180 14:45 ~$
# Wrapped call, fails
paulm@tcn180 14:45 ~$ /scratch-shared/paulm/eb-3OiLzK/tmpvR7vdm/rpath_wrappers/gxx_wrapper/g++ -x c++-header t.cc
/lib/../lib64/crt1.o(.text+0x20): error: undefined reference to 'main'
collect2: error: ld returned 1 exit status
# Straight g++ call with -Wl,-rpath addition, no wrappers, fails
paulm@tcn180 14:46 ~$ /sw/arch/RedHatEnterpriseServer7/EB_production/2019/software/GCCcore/8.2.0/bin/g++ -x c++-header -Wl,-rpath=/tmp/doh t.cc
/lib/../lib64/crt1.o(.text+0x20): error: undefined reference to 'main'
collect2: error: ld returned 1 exit status
We (me and @casparvl) suggest that the rpath wrappers check for the -x c++-header (and similar) options to make sure an otherwise correct call of g++ is not turned into one that fails. Note that there is a bit of a mist as to the expected behaviour of GCC with various options, as the docs aren't entirely clear:
For example, calling g++ t.cc fails if t.cc does not contain a main function as it does linking of the generated object code. But calling g++ -x c++-header t.cc apparently turns on compile-only mode and succeeds (but the gcc docs only say: "To create a precompiled header file, simply compile it as you would any other file, if necessary using the -x option to make the driver treat it as a C or C++ header file")
Adding -Wl,-rpath=... makes GCC link (although the docs do not specify this), unless -c is used, in which case linking is never done.
The examples in the GCC docs of using precompiled headers do not use -c when using -x c++-header. But upstream package could be more explicit by using -c -x c++-header, which would still work when the RPATH wrappers would add -Wl,-rpath=..., but it can't really be expected of those packages to handle that case of downstream building.
The text was updated successfully, but these errors were encountered:
This issue was found when building OpenCV-4.0.1-foss-2018b-Python-3.6.6.eb with EB 4.1.1. The build has multiple errors
undefined reference to main
. This is caused by the rpath wrappers adding-Wl,-rpath=...
options to the g++ call, which turns otherwise compile-only commands to generate precompiled headers (-x c++-header
) into commands that link.See easybuild-OpenCV-4.0.1-20200623.143513.mcEaZ.log.gz for the full logs. But it can also be shown using only the generated rpath wrapper to compile a simple file:
We (me and @casparvl) suggest that the rpath wrappers check for the
-x c++-header
(and similar) options to make sure an otherwise correct call of g++ is not turned into one that fails. Note that there is a bit of a mist as to the expected behaviour of GCC with various options, as the docs aren't entirely clear:g++ t.cc
fails ift.cc
does not contain a main function as it does linking of the generated object code. But callingg++ -x c++-header t.cc
apparently turns on compile-only mode and succeeds (but the gcc docs only say: "To create a precompiled header file, simply compile it as you would any other file, if necessary using the -x option to make the driver treat it as a C or C++ header file")-Wl,-rpath=...
makes GCC link (although the docs do not specify this), unless-c
is used, in which case linking is never done.-c
when using-x c++-header
. But upstream package could be more explicit by using-c -x c++-header
, which would still work when the RPATH wrappers would add-Wl,-rpath=...
, but it can't really be expected of those packages to handle that case of downstream building.The text was updated successfully, but these errors were encountered: