Skip to content

Fix pch generation when linker flags used with GCC#16109

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
pixelb:gcc-9-pch
Dec 10, 2019
Merged

Fix pch generation when linker flags used with GCC#16109
opencv-pushbot merged 1 commit intoopencv:3.4from
pixelb:gcc-9-pch

Conversation

@pixelb
Copy link
Copy Markdown
Contributor

@pixelb pixelb commented Dec 9, 2019

-c is required to avoid linking (and the associated missing "main" message)

@alalek
Copy link
Copy Markdown
Member

alalek commented Dec 10, 2019

Can't reproduce with GCC 9.2.1 (Fedora 31).

Please add more information about your build environment, dump exact compiler message and related compiler's build options (through make VERBOSE or ninja -v).

@pixelb
Copy link
Copy Markdown
Contributor Author

pixelb commented Dec 10, 2019

With: GCC 9.2.0, cmake 3.15.2
```
cmake opencv
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=/usr/local
-DCMAKE_SKIP_INSTALL_RPATH:BOOL=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DOPENCV_ENABLE_NONFREE=ON -DWITH_JASPER=OFF -DWITH_TBB=ON -DWITH_IPP=ON -DWITH_ITT=OFF -DWITH_CUDA=OFF -DWITH_OPENCL=OFF -DWITH_OPENCL_SVM=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_LAPACK=OFF -DWITH_FFMPEG=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_xfeatures2d=ON -DPYTHON2_CVPY_SUFFIX=.so -DPYTHON3_CVPY_SUFFIX=.so -DOPENCV_EXTRA_MODULES_PATH=opencv_contrib-3.4.5/modules -DWITH_PROTOBUF=ON -DBUILD_PROTOBUF=OFF -DPROTOBUF_UPDATE_FILES=ON -DENABLE_CXX11=ON -DBUILD_SHARED_LIBS=OFF
-DENABLE_PIC=ON
-DBUILD_FAT_JAVA_LIB=ON

[ 11%] Generating precomp.hpp.gch/opencv_core_Release.gch
cd opencv/modules/core && cmake -E make_directory opencv/modules/core/precomp.hpp.gch
cd opencv/modules/core &&
g++ -O3 -DNDEBUG "-D__OPENCV_BUILD=1" "-D_USE_MATH_DEFINES" "-D__STDC_CONSTANT_MACROS" "-D__STDC_LIMIT_MACROS" "-D__STDC_FORMAT_MACROS" "-DCVAPI_EXPORTS" -std=c++11
-I"opencv/3rdparty/ippicv/ippicv_lnx/icv/include" -I"opencv/3rdparty/ippicv/ippicv_lnx/iw/include" -I"opencv/3.4.5/modules/core/src" -I"opencv/modules/core/include" -I"opencv/modules/core"
-O3 -g -pipe -Wall -Wno-error -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -fno-omit-frame-pointer -momit-leaf-frame-pointer
-fno-reorder-blocks-and-partition -Wl,-z,relro -march=corei7 -mtune=skylake -nostdinc -grecord-gcc-switches
-fPIC -fpermissive -fno-omit-frame-pointer -fsigned-char
-W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations
-Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment
-Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long
-pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -fPIC
-x c++-header -o opencv/modules/core/precomp.hpp.gch/opencv_core_Release.gch opencv/modules/core/precomp.hpp
ld: undefined reference to `main'
collect2: error: ld returned 1 exit status

@alalek
Copy link
Copy Markdown
Member

alalek commented Dec 10, 2019

Thank you for update!

Looks like, linker flag "-Wl,-z,relro" confuses GCC. It is not GCC 9 specific, there is output of GCC 8.3.1:

/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status

"-c" fixes problem again.

As a bugfix this patch should go into 3.4 branch first. We will merge changes from 3.4 into master regularly (weekly/bi-weekly).

So, please:

  • change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
  • rebase your commits from master onto 3.4 branch. For example:
    git rebase -i --onto upstream/3.4 upstream/master
    (check list of your commits, save and quit (Esc + "wq" + Enter)
    where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
  • push rebased commits into source branch of your fork (with --force option)

Note: no needs to re-open PR, apply changes "inplace".

@pixelb pixelb changed the base branch from master to 3.4 December 10, 2019 14:36
-c is required to avoid linking (and the associated missing "main" message)
when linker flags like "-Wl,-z,relro" are passed to GCC
@pixelb pixelb changed the title Fix pch generation with GCC >= 9 Fix pch generation when linker flags used with GCC Dec 10, 2019
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution 👍

opencv-pushbot pushed a commit that referenced this pull request Dec 10, 2019
@opencv-pushbot opencv-pushbot merged commit 7b298b0 into opencv:3.4 Dec 10, 2019
@alalek alalek mentioned this pull request Dec 11, 2019
@pixelb pixelb deleted the gcc-9-pch branch December 11, 2019 20:26
Undefined-User added a commit to Undefined-User/opencv that referenced this pull request Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants