Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

building cppcoro failed (undefined reference to __cxa_end_catch/__cxa_begin_catch) #21

Closed
whoisdavidvu opened this issue Nov 15, 2020 · 11 comments

Comments

@whoisdavidvu
Copy link

whoisdavidvu commented Nov 15, 2020

Hi Andreas, i just tried to build cppcoro but the build failed for me with a lot of "undefinded reference" errors and i was wondering if you can help me build it successfully.

Example:

/usr/bin/ld: /home/davidvu/C++/projects/firstarray_randomgen/cppcoro/test/single_consumer_async_auto_reset_event_tests.cpp:40: undefined reference to '__cxa_begin_catch'
/usr/bin/ld: /home/davidvu/C++/projects/firstarray_randomgen/cppcoro/test/single_consumer_async_auto_reset_event_tests.cpp:40: undefined reference to '__cxa_end_catch'
The following targets failed to build:
- build/linux_x64_clang11.0.0_debug/test/run
- build/linux_x64_clang11.0.0_optimised/test/run
@andreasbuhr
Copy link
Owner

Hi, how did you configure it? I see you are using Clang 11. Could you please try the following:

  cmake \
    -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_CXX_STANDARD=20 \
    -DBUILD_TESTING=ON \
    -DCMAKE_CXX_FLAGS=-stdlib=libc++ \
    -DCMAKE_EXE_LINKER_FLAGS=-lc++ \
    -DCMAKE_VERBOSE_MAKEFILE=ON \
    ../path/to/cppcoro

Does it help?

@whoisdavidvu
Copy link
Author

whoisdavidvu commented Nov 15, 2020

Hi, i didn't configure anything, i just used cake without any parameters.

I tried the cmake you posted and it wouldn't compile either, i uploaded the log files down below.

CMakeError.log
CMakeOutput.log

@andreasbuhr
Copy link
Owner

Thanks for your feedback.
The options I suggested above are the right options for using clang, but from your output I see CMake selected the system compiler, which is gcc probably.
Could you please try exporting which C++ compiler should be used first? Could you try the following?

export CXX=clang-11
cmake \
    -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_CXX_STANDARD=20 \
    -DBUILD_TESTING=ON \
    -DCMAKE_CXX_FLAGS=-stdlib=libc++ \
    -DCMAKE_EXE_LINKER_FLAGS=-lc++ \
    -DCMAKE_VERBOSE_MAKEFILE=ON \
    ../path/to/cppcoro

Or, alternatively, to use it with gcc, do not export anything, but also do not specify the flags:

cmake \
    -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_CXX_STANDARD=20 \
    -DBUILD_TESTING=ON \
    -DCMAKE_VERBOSE_MAKEFILE=ON \
    ../path/to/cppcoro

Does any of these work?

@whoisdavidvu
Copy link
Author

I just tried the first code that you sent, but it didn't work aswell. I will upload the created logs down below.

CMakeError.log
CMakeOutput.log

Then i tried
export CXX=gcc-10
before trying the second block of code, and it also did not work.

CMakeError.log
CMakeOutput.log

If it helps, the terminal outputs this:

-- The CXX compiler identification is GNU 10.2.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:53 (message):
  The C++ compiler

    "/usr/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/davidvu/C++/projects/firstarray_randomgen/cppcoro/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/gmake cmTC_dcd90/fast && /usr/bin/gmake -f CMakeFiles/cmTC_dcd90.dir/build.make CMakeFiles/cmTC_dcd90.dir/build
    gmake[1]: Entering directory '/home/davidvu/C++/projects/firstarray_randomgen/cppcoro/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_dcd90.dir/testCXXCompiler.cxx.o
    /usr/bin/c++    -stdlib=libc++    -std=gnu++2a -o CMakeFiles/cmTC_dcd90.dir/testCXXCompiler.cxx.o -c /home/davidvu/C++/projects/firstarray_randomgen/cppcoro/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    c++: error: unrecognized command-line option ‘-stdlib=libc++’
    gmake[1]: *** [CMakeFiles/cmTC_dcd90.dir/build.make:66: CMakeFiles/cmTC_dcd90.dir/testCXXCompiler.cxx.o] Error 1
    gmake[1]: Leaving directory '/home/davidvu/C++/projects/firstarray_randomgen/cppcoro/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:121: cmTC_dcd90/fast] Error 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "/home/davidvu/C++/projects/firstarray_randomgen/cppcoro/CMakeFiles/CMakeOutput.log".
See also "/home/davidvu/C++/projects/firstarray_randomgen/cppcoro/CMakeFiles/CMakeError.log".

@andreasbuhr
Copy link
Owner

You need to clean your build directory before you change the configuration, otherwise CMake will cache settings.

You also should use out-of-source builds, see below.

Please try the following:

mkdir cppcoro
cd cppcoro
git clone https://github.com/andreasbuhr/cppcoro.git
mkdir cppcoro_gccbuild
cd cppcoro_gccbuild
export CXX=g++-10
cmake  -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=20  -DBUILD_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=ON ../cppcoro
cmake --build .

cd ..
mkdir cppcoro_clangbuild
cd cppcoro_clangbuild
export CXX=clang++-11
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=20 -DBUILD_TESTING=ON -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_EXE_LINKER_FLAGS=-lc++ -DCMAKE_VERBOSE_MAKEFILE=ON ../cppcoro

@whoisdavidvu
Copy link
Author

I just tried the upper cmake building the cppcoro in cppcoro_gccbuild and it seemed to build without any errors, whereas building the content for the clangbuild folder threw errors again. Is the build by the gcc compiler seen as a success? Or does it need to be built by clang?

-- The CXX compiler identification is Clang 11.0.0
-- Check for working CXX compiler: /usr/bin/clang++-11
-- Check for working CXX compiler: /usr/bin/clang++-11 -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCXXCompiler.cmake:53 (message):
  The C++ compiler

    "/usr/bin/clang++-11"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/davidvu/C++/projects/firstarray_randomgen/cppcoro/cppcoro_clangbuild/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/gmake cmTC_27289/fast && /usr/bin/gmake -f CMakeFiles/cmTC_27289.dir/build.make CMakeFiles/cmTC_27289.dir/build
    gmake[1]: Entering directory '/home/davidvu/C++/projects/firstarray_randomgen/cppcoro/cppcoro_clangbuild/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_27289.dir/testCXXCompiler.cxx.o
    /usr/bin/clang++-11    -stdlib=libc++    -std=gnu++2a -o CMakeFiles/cmTC_27289.dir/testCXXCompiler.cxx.o -c /home/davidvu/C++/projects/firstarray_randomgen/cppcoro/cppcoro_clangbuild/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    Linking CXX executable cmTC_27289
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_27289.dir/link.txt --verbose=1
    /usr/bin/clang++-11  -stdlib=libc++   -lc++  CMakeFiles/cmTC_27289.dir/testCXXCompiler.cxx.o  -o cmTC_27289 
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_free_exception'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_begin_catch'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_guard_release'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_pure_virtual'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_allocate_exception'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__gxx_personality_v0'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_throw'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_guard_abort'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_end_catch'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_guard_acquire'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `__cxa_rethrow'
    /usr/bin/ld: /usr/local/lib/libc++.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[1]: *** [CMakeFiles/cmTC_27289.dir/build.make:87: cmTC_27289] Error 1
    gmake[1]: Leaving directory '/home/davidvu/C++/projects/firstarray_randomgen/cppcoro/cppcoro_clangbuild/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:121: cmTC_27289/fast] Error 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "/home/davidvu/C++/projects/firstarray_randomgen/cppcoro/cppcoro_clangbuild/CMakeFiles/CMakeOutput.log".
See also "/home/davidvu/C++/projects/firstarray_randomgen/cppcoro/cppcoro_clangbuild/CMakeFiles/CMakeError.log".

@erikzenker
Copy link

erikzenker commented Nov 18, 2020

I also do net get clang 11 working. Same error as above.
When I just try configure with clang 11. I get the following error:

CMake Error at cmake/FindCoroutines.cmake:272 (message):
  Cannot compile simple program using std::coroutines.  Is C++17 or later
  activated?
Call Stack (most recent call first):
  lib/CMakeLists.txt:172 (find_package)

When I try to add the cxx flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -stdlib=libc++ -fcoroutines") then -fcoroutines is an unknown argument. When I drop -fcoroutines the compiler complains Cppcoro requires a C++20 compiler with coroutine support.

So maybe we need to wait for clang12? Not sure if it works with clang8,9,10

@andreasbuhr
Copy link
Owner

-DCMAKE_CXX_STANDARD=20 should be all you need.

It works fine with both clang-10 and clang-11 in the CI.

@andreasbuhr
Copy link
Owner

Ah, just had an idea:
Maybe you do not have the clang standard library installed?
For clang 11 on debian-based:
sudo apt-get install libc++-11-dev libc++abi-11-dev

Does this help?

@whoisdavidvu
Copy link
Author

Ah, just had an idea:
Maybe you do not have the clang standard library installed?
For clang 11 on debian-based:
sudo apt-get install libc++-11-dev libc++abi-11-dev

Does this help?

Thanks, this made it work for the clang build aswell.

@andreasbuhr
Copy link
Owner

Cool. I will add that step to the build documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants