You are not logged in.

#1 2021-07-29 15:58:01

flan
Member
Registered: 2021-07-29
Posts: 5

gcc10 compile c++ project using libraries of gcc11

Hi,
I am using gcc10 to compile my c++ project. I have a problem when I use the libraries installed by pacman recently.
Archlinux updated the official compiler to gcc11. All of the official libraries are also compiled by gcc11.
When I use gcc10 to compile my code, and it links to the libraries compiled by gcc11, it shows the following errors:
```
/usr/bin/ld: /usr/lib/libQt5Core.so.5.15.2: undefined reference to `std::__exception_ptr::exception_ptr::_M_release()@CXXABI_1.3.13'
/usr/bin/ld: /usr/lib/libQt5Widgets.so.5.15.2: undefined reference to `std::__throw_bad_array_new_length()@GLIBCXX_3.4.29'
/usr/bin/ld: /usr/lib/libQt5Core.so.5.15.2: undefined reference to `std::__exception_ptr::exception_ptr::_M_addref()@CXXABI_1.3.13'
collect2: error: ld returned 1 exit status
```
It seems that something wrong with the stdc++ lib.

I am wondering how to solve this problem? Should I downgrade my Qt5 lib?

Offline

#2 2021-07-29 16:33:46

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: gcc10 compile c++ project using libraries of gcc11

Why are you using an outdated compiler?  Especially if you are (trying to) use current libs?

Sometimes there may be value in using slightly older libs to target binaries to other distros - but I don't see the value in using an outdated compiler.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2021-07-29 17:33:56

flan
Member
Registered: 2021-07-29
Posts: 5

Re: gcc10 compile c++ project using libraries of gcc11

I changed my compiler to gcc11 now. I also updated the libraries I need (I compiled these libraries with gcc11 by myself).

After doing that, I compile my code but it shows the following error message:
```
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<double*>::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<ceres::Grid2D<double, 1, true, true> >::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<ceres::BiCubicInterpolator<ceres::Grid2D<double, 1, true, true> > >::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<std::shared_ptr<Keyframe> >::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o: in function `__gnu_cxx::new_allocator<unsigned long>::allocate(unsigned long, void const*)':
/usr/include/c++/11.1.0/ext/new_allocator.h:110: undefined reference to `std::__throw_bad_array_new_length()'
/usr/bin/ld: CMakeFiles/depth_camera_slam.dir/main.cpp.o:/usr/include/c++/11.1.0/ext/new_allocator.h:110: more undefined references to `std::__throw_bad_array_new_length()' follow
/usr/bin/ld: /usr/local/lib/libopencv_core.so.3.4.15: undefined reference to `std::__exception_ptr::exception_ptr::_M_release()@CXXABI_1.3.13'
/usr/bin/ld: /usr/lib/libvtkRenderingCore.so.1: undefined reference to `std::__istream_extract(std::istream&, char*, long)@GLIBCXX_3.4.29'
/usr/bin/ld: ../lib/libdataset_inputstream.so: undefined reference to `std::__throw_bad_array_new_length()@GLIBCXX_3.4.29'
/usr/bin/ld: /usr/local/lib/libopencv_core.so.3.4.15: undefined reference to `std::__exception_ptr::exception_ptr::_M_addref()@CXXABI_1.3.13'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/depth_camera_slam.dir/build.make:351: ../bin/depth_camera_slam] Error 1
make[1]: *** [CMakeFiles/Makefile2:804: CMakeFiles/depth_camera_slam.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

```
It seems that gcc11 cannot find the implementation of stdc++ lib?
I have no idea whether it is related to the stdc++ lib.

Offline

#4 2021-07-29 18:24:29

flan
Member
Registered: 2021-07-29
Posts: 5

Re: gcc10 compile c++ project using libraries of gcc11

UPDATE:
I am using c++ with CUDA.
My CUDA version is CUDA-11 which requires gcc10.
Archlinux updated its official compiler to GCC11, so all of the official libraries are compiled by gcc11.

Now I suspect this problem is that I am using gcc-11 but CUDA will affect the stdc++ lib, somehow gcc11 was trying to link to gcc10 stdc++ libs?
Am I correct?
How to solve this problem?

Offline

#5 2021-07-29 18:54:54

loqs
Member
Registered: 2014-03-06
Posts: 17,192

Re: gcc10 compile c++ project using libraries of gcc11

Offline

#6 2021-07-29 20:03:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: gcc10 compile c++ project using libraries of gcc11

First see the first response there from Scimmia.  As there is, apparently, no reason to use outdated or self-compiled major components, just update your system properly.  At that point if there are remaining errors *those* should be dealt with and might lead to a useful bug report for an arch package (if there is a real problem).

But intentionally doing things in an unsupported way for no purpose and getting errors is not surprising.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2021-07-29 20:27:11

loqs
Member
Registered: 2014-03-06
Posts: 17,192

Re: gcc10 compile c++ project using libraries of gcc11

https://bugs.archlinux.org/task/71467 when building opencv with CUDA enabled and not using gcc-10 as the CUDA host compiler.
I did a rebuild for that bug report using gcc-10 as the host compiler and that succeeded.  I do not remember needing to make any other changes but I may have have forgotten some details.
Edit:
flan does https://aur.archlinux.org/packages/opencv-cuda/ build for you?

Last edited by loqs (2021-07-29 22:17:38)

Offline

#8 2021-07-29 23:16:32

flan
Member
Registered: 2021-07-29
Posts: 5

Re: gcc10 compile c++ project using libraries of gcc11

I updated the entire system, it still doesn't work.

As I see in these posts, CUDA requires gcc-10 as host compiler, but archlinux uses gcc-11 now.

What is the solution? I am still confused.

Offline

#9 2021-07-29 23:36:34

loqs
Member
Registered: 2014-03-06
Posts: 17,192

Re: gcc10 compile c++ project using libraries of gcc11

Arch provides gcc-10 for use as the CUDA host compiler,  that is how all packages using CUDA in the Arch repositories are currently built for example arrayfire.
That is why I was asking if you could build opencv-cuda,  it depends on the cuda package which depends on gcc-10 and specifies /opt/cuda/bin/gcc as the CUDA host compiler which is a symlink to /usr/bin/gcc-10.

Last edited by loqs (2021-07-29 23:37:05)

Offline

#10 2021-07-29 23:56:29

flan
Member
Registered: 2021-07-29
Posts: 5

Re: gcc10 compile c++ project using libraries of gcc11

So I need to compile opencv-cuda from source to see if this problem happens?
I tried install opencv-cuda: yay -S opencv-cuda, but it shows the following error message:

```

==> Making package: nvidia-sdk 11.0.10-1 (Fri 30 Jul 2021 00:47:30 BST)
==> Retrieving sources...
==> ERROR: Video_Codec_SDK_11.0.10.zip was not found in the build directory and is not a URL.
error downloading sources: nvidia-sdk
```

What should I do?

Offline

#11 2021-07-30 00:10:14

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,783
Website

Re: gcc10 compile c++ project using libraries of gcc11


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Online

#12 2021-07-30 00:19:33

loqs
Member
Registered: 2014-03-06
Posts: 17,192

Re: gcc10 compile c++ project using libraries of gcc11

You can remove nvidia-sdk from the PKGBUILD

diff --git a/PKGBUILD b/PKGBUILD
index a9acf3d..7b50077 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -13,7 +13,7 @@ license=(BSD)
 url="http://opencv.org/"
 options=(staticlibs)
 depends=(intel-tbb openexr gst-plugins-base libdc1394 cblas lapack libgphoto2 jasper cuda)
-makedepends=(cmake python-numpy python2-numpy mesa ninja eigen hdf5 lapacke gtk3 nvidia-sdk)
+makedepends=(cmake python-numpy python2-numpy mesa ninja eigen hdf5 lapacke gtk3)
 optdepends=('opencv-samples: samples'
             'gtk3: for the HighGUI module'
             'hdf5: support for HDF5 format'
@@ -28,9 +28,6 @@ sha256sums=('be976b9ef14f1deaa282fb6e30d75aa8016a2d5c1f08e85795c235148940d753'
             'f83c64f2731a39910d0d4a48898dd04e4aca5c22f746b7b0ead003992ae11199')
 
 prepare() {
-  msg2 "Patching sources for CUDA v10"
-  sed -i 's|nvcuvid.h|nvidia-sdk/nvcuvid.h|' opencv_contrib-$pkgver/modules/cud*/src/*.hpp
-
   # See https://github.com/opencv/opencv/issues/19846
   msg2 "Patching sources for lapack 3.10.0"
   patch -d opencv-$pkgver -p1 < opencv-lapack-3.10.patch
@@ -59,7 +56,6 @@ build() {
     -DCMAKE_INSTALL_LIBDIR=lib \
     -DCPU_BASELINE_DISABLE=SSE3 \
     -DCPU_BASELINE_REQUIRE=SSE2 \
-    -DWITH_NVCUVID=ON \
     -DWITH_CUDA=ON \
     -DCUDA_FAST_MATH=ON \
     -DWITH_CUBLAS=ON \

Offline

Board footer

Powered by FluxBB