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

gtest/[0.13.0, 0.14.0]: Undefined references to "basic_string" on clang-17 with "compiler.libcxx=libstdc++11" #22547

Closed
matheusgomes28 opened this issue Jan 25, 2024 · 11 comments
Assignees
Labels
question Further information is requested

Comments

@matheusgomes28
Copy link
Contributor

matheusgomes28 commented Jan 25, 2024

Description

Linking Google Test with Clang 17 does not seem to be working, we get the errors shown in the logs.

Obviously, I am well aware of the many issues reported regarding the std::basic_string ABI differences between building with libstd++ and libstdc++11. But even after setting compiler.libcxx=libstdc++11 it does NOT work when linking the lib to a binary.

I've also tried to manually tweek the _GLIBCXX_USE_CXX11_ABI, but no fixes so far.

Is this a bug, or am I missing something?

Package and Environment Details

General Info

  • Package Name/Version: gtest/1.13.0
  • Operating System+version: Ubuntu 22.04
  • Compiler+version: Clang 17
  • Conan version: conan 2.0.17
  • Python version: Python 3.10.13

Environment Variables Defined

  • CC="clang"
  • CXX="clang++"

Conan profile

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Debug
compiler=clang
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=17
os=Linux

Profile build:
[settings]
arch=x86_64
build_type=Debug
compiler=clang
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=17
os=Linux

Steps to reproduce

helper script used (called conan-install.sh):

#!/usr/bin/env bash

set -euo pipefail

: ' This file will install all the conan dependencies for the
    x86_64 architecture. In the future, this should use the
    Conan profiles.
'
PROJECT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
BUILD_TYPE=${BUILD_TYPE-Debug}
COMPILER=${COMPILER-"gcc"}
COMPILER_STD=${COMPILER_STD-"17"}
COMPILER_LIBCXX=${COMPILER_LIBCXX-"libstdc++11"}
COMPILER_VERSION=${COMPILER_VERSION-"11"}

conan profile detect --force
sed -i "s/build_type=Release/build_type=${BUILD_TYPE}/g" "$(conan profile path default)"
sed -i "s/compiler=.*/compiler=${COMPILER}/g" "$(conan profile path default)"
sed -i "s/compiler.cppstd=.*/compiler.cppstd=${COMPILER_STD}/g" "$(conan profile path default)"
sed -i "s/compiler.libcxx=.*/compiler.libcxx=${COMPILER_LIBCXX}/g" "$(conan profile path default)"
sed -i "s/compiler.version=.*/compiler.version=${COMPILER_VERSION}/g" "$(conan profile path default)"


CONAN_DIR="${PROJECT_DIR}/conan/deb"
if [ "${BUILD_TYPE}" = "Release" ]; then
  CONAN_DIR="${PROJECT_DIR}/conan/rel"
fi

# Install all dependencies
CXX="${COMPILER}" CC="${COMPILER}" conan install \
  --output-folder="${CONAN_DIR}" \
  --build=missing \
  "${PROJECT_DIR}"

So I'm calling the script above with COMPILER="clang" COMPILER_VERSION="17" COMPILER_CPPSTD="20" COMPILER_LIBCXX="libstdc++11" ./scripts/helpers/conan-install.sh

Logs

...
/usr/bin/ld: gtest-all.cc:(.text+0x2aff7): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char, unsigned long) const'
/usr/bin/ld: gtest-all.cc:(.text+0x2b020): undefined reference to `operator new(unsigned long)'
/usr/bin/ld: gtest-all.cc:(.text+0x2b040): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::substr(unsigned long, unsigned long) const'
/usr/bin/ld: gtest-all.cc:(.text+0x2b063): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::substr(unsigned long, unsigned long) const'
/usr/bin/ld: gtest-all.cc:(.text+0x2b0a0): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/bin/ld: gtest-all.cc:(.text+0x2b0a9): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/bin/ld: gtest-all.cc:(.text+0x2b0e5): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/bin/ld: gtest-all.cc:(.text+0x2b0ee): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
...
@matheusgomes28 matheusgomes28 added the bug Something isn't working label Jan 25, 2024
@uilianries
Copy link
Member

Hello @matheusgomes28 ! It's not totally clear how you are consuming the Conan package. Your profile looks okay, but how do you consume that library? Please, make sure you are using CMakeToolchain and CMakeDeps generator. Also, there is a good tutorial explaining how to consume Conan packages here: https://docs.conan.io/2/tutorial/consuming_packages/build_simple_cmake_project.html

@uilianries uilianries self-assigned this Jan 26, 2024
@uilianries uilianries added Feedback please! Waiting for user response question Further information is requested and removed bug Something isn't working labels Jan 26, 2024
@matheusgomes28
Copy link
Contributor Author

@uilianries sorry if it wasn't clear. I am using CMakeToolchain and CMakeDeps. The library is found and linked correctly, but linking fails with the errors mentioned.

I've used Conan before and am familiar with the ABI issue, but can't seem to fix here 😕 For context, I am building this on a CI in this branch of my project

@uilianries
Copy link
Member

@matheusgomes28 Could you please point the exact link to the build that's failing? So I can have a better view.

Plus, you should prefer test_requires instead of requires here: https://github.com/matheusgomes28/base64pp/blob/main/conanfile.txt#L1

https://docs.conan.io/2/reference/conanfile_txt.html#test-requires

@matheusgomes28
Copy link
Contributor Author

matheusgomes28 commented Jan 26, 2024

@uilianries I can, its the "Ubuntu Debug" build that builds unit tests. However, don't worry about that, I think it's counter productive trying to understand my CI pipeline.

I've made a minimal reproducible project that also fails. Firstly, install the clang-17 toolchain from this link (run the sudo ./llvm.sh 17 script to get access to clang-17) - Assuming you're using Ubuntu

Project File Setup (all same dir)

CMakeLists.txt:

cmake_minimum_required(VERSION 3.25)
project(ConanGtest LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(GTest REQUIRED)

add_executable(tests main.cpp)
target_link_libraries(tests PRIVATE GTest::gtest)

main.cpp:

#include <gtest/gtest.h>
#include <string>

// NOLINTNEXTLINE
TEST(MyTestCase, MyTestName)
{
    std::string const expected{"Hello World!"};
    ASSERT_EQ(expected, "Hello World!");
}

int main(int argc, char** argv)
{
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

conanfile.txt

[requires]
gtest/1.13.0

[generators]
CMakeDeps
CMakeToolchain

Commands Used to Build

Conan dependency install

CC="clang-17" CXX="clang-17" conan install . -of "conan/deb" -sbuild_type=Debug --build=missing

CMake configure

cmake -DCMAKE_TOOLCHAIN_FILE="conan/deb/conan_toolchain.cmake" -DCMAKE_CXX_COMPILER="clang-17" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_CXX_COMPILER="clang-17" . -Bbuild

CMake build

cmake --build ./build

And you should get the linking errors on the build stage. Note that I have used the same profile as mentioned before.

@uilianries
Copy link
Member

uilianries commented Jan 26, 2024

@matheusgomes28 It's working fine for me:

# conan install . -of "conan/deb" -s build_type=Debug --build=missing

======== Input profiles ========
Profile host:
[settings]
arch=armv8
build_type=Debug
compiler=clang
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=17
os=Linux
[conf]
tools.build:compiler_executables={'c': '/usr/bin/clang-17', 'cpp': '/usr/bin/clang++-17'}

Profile build:
[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=17
os=Linux
[conf]
tools.build:compiler_executables={'c': '/usr/bin/clang-17', 'cpp': '/usr/bin/clang++-17'}


======== Computing dependency graph ========
gtest/1.13.0: Not found in local cache, looking in remotes...
gtest/1.13.0: Checking remote: conancenter
gtest/1.13.0: Downloaded recipe revision 8a0bc5b3e159ed45de97260c2bff65b5
Graph root
    conanfile.txt: /root/project/conanfile.txt
Requirements
    gtest/1.13.0#8a0bc5b3e159ed45de97260c2bff65b5 - Downloaded (conancenter)

======== Computing necessary packages ========
gtest/1.13.0: Checking 7 compatible configurations
gtest/1.13.0: Compatible configurations not found in cache, checking servers
gtest/1.13.0: '9b4c2f6b49db816370fdebd345e69d191d893d6f': compiler.cppstd=14
gtest/1.13.0: 'b958df093b1bcc3502d46db4c1060a6a9c3680df': compiler.cppstd=gnu14
gtest/1.13.0: 'ca0c8be92d637d07baa71301ff6cc7b25e227286': compiler.cppstd=gnu17
gtest/1.13.0: '34ff8327f9fa35c6dc44f6d424d2974ae4307d63': compiler.cppstd=20
gtest/1.13.0: '7e5c59d71178fb11c224fd5e889026d3b402cfd9': compiler.cppstd=gnu20
gtest/1.13.0: '9a6fe150aae8610188b60a078c5017f667d07826': compiler.cppstd=23
gtest/1.13.0: '268471286227420ff3f05506257f802e9dc67aec': compiler.cppstd=gnu23
Requirements
    gtest/1.13.0#8a0bc5b3e159ed45de97260c2bff65b5:9a21e417e84e3beb767cab96f8fb8e93120fa2ca - Build

======== Installing packages ========
gtest/1.13.0: Sources downloaded from 'conancenter'
gtest/1.13.0: Calling source() in /root/.conan2/p/gtest1b66e38815454/s/src

-------- Installing package gtest/1.13.0 (1 of 1) --------
gtest/1.13.0: Building from source
gtest/1.13.0: Package gtest/1.13.0:9a21e417e84e3beb767cab96f8fb8e93120fa2ca
gtest/1.13.0: Copying sources to build folder
gtest/1.13.0: Building your package in /root/.conan2/p/b/gtest907ad17c8dd3f/b
gtest/1.13.0: Calling generate()
gtest/1.13.0: Generators folder: /root/.conan2/p/b/gtest907ad17c8dd3f/b/build/Debug/generators
gtest/1.13.0: CMakeToolchain generated: conan_toolchain.cmake
gtest/1.13.0: CMakeToolchain generated: CMakePresets.json
gtest/1.13.0: CMakeToolchain generated: ../../../src/CMakeUserPresets.json
gtest/1.13.0: Generating aggregated env files
gtest/1.13.0: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
gtest/1.13.0: Calling build()
gtest/1.13.0: apply_conandata_patches(): No patches defined in conandata
gtest/1.13.0: Running CMake.configure()
gtest/1.13.0: RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/root/.conan2/p/b/gtest907ad17c8dd3f/b/build/Debug/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/root/.conan2/p/b/gtest907ad17c8dd3f/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Debug" "/root/.conan2/p/b/gtest907ad17c8dd3f/b/src"
-- Using Conan toolchain: /root/.conan2/p/b/gtest907ad17c8dd3f/b/build/Debug/generators/conan_toolchain.cmake
-- Conan toolchain: Setting CMAKE_POSITION_INDEPENDENT_CODE=ON (options.fPIC)
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The C compiler identification is Clang 17.0.6
-- The CXX compiler identification is Clang 17.0.6
-- Check for working C compiler: /usr/bin/clang-17
-- Check for working C compiler: /usr/bin/clang-17 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++-17
-- Check for working CXX compiler: /usr/bin/clang++-17 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /root/.conan2/p/b/gtest907ad17c8dd3f/b/build/Debug

gtest/1.13.0: Running CMake.build()
gtest/1.13.0: RUN: cmake --build "/root/.conan2/p/b/gtest907ad17c8dd3f/b/build/Debug" -- -j10
Scanning dependencies of target gtest
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
2 warnings generated.
[ 25%] Linking CXX static library ../lib/libgtest.a
[ 25%] Built target gtest
Scanning dependencies of target gmock
Scanning dependencies of target gtest_main
[ 37%] Building CXX object googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 50%] Building CXX object googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 62%] Linking CXX static library ../lib/libgtest_main.a
[ 62%] Built target gtest_main
[ 75%] Linking CXX static library ../lib/libgmock.a
[ 75%] Built target gmock
Scanning dependencies of target gmock_main
[ 87%] Building CXX object googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[100%] Linking CXX static library ../lib/libgmock_main.a
[100%] Built target gmock_main

gtest/1.13.0: Package '9a21e417e84e3beb767cab96f8fb8e93120fa2ca' built
gtest/1.13.0: Build folder /root/.conan2/p/b/gtest907ad17c8dd3f/b/build/Debug
gtest/1.13.0: Generating the package
gtest/1.13.0: Packaging in folder /root/.conan2/p/b/gtest907ad17c8dd3f/p
gtest/1.13.0: Calling package()
gtest/1.13.0: Running CMake.install()
gtest/1.13.0: RUN: cmake --install "/root/.conan2/p/b/gtest907ad17c8dd3f/b/build/Debug" --prefix "/root/.conan2/p/b/gtest907ad17c8dd3f/p"
-- Install configuration: "Debug"
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/gmock-more-actions.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/internal
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/internal/gmock-internal-utils.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/internal/gmock-pp.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/internal/custom
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/internal/custom/README.md
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/internal/custom/gmock-generated-actions.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/internal/custom/gmock-matchers.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/internal/custom/gmock-port.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/internal/gmock-port.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/gmock-function-mocker.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/gmock-nice-strict.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/gmock.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/gmock-spec-builders.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/gmock-actions.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/gmock-matchers.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/gmock-cardinalities.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gmock/gmock-more-matchers.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/libgmock.a
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/libgmock_main.a
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/pkgconfig/gmock.pc
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/pkgconfig/gmock_main.pc
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/cmake/GTest/GTestTargets.cmake
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/cmake/GTest/GTestTargets-debug.cmake
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/cmake/GTest/GTestConfigVersion.cmake
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/cmake/GTest/GTestConfig.cmake
-- Up-to-date: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest-message.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/gtest-param-util.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/gtest-type-util.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/gtest-death-test-internal.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/gtest-port-arch.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/gtest-port.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/custom
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/custom/gtest.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/custom/gtest-printers.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/custom/gtest-port.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/custom/README.md
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/gtest-internal.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/gtest-string.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/internal/gtest-filepath.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest-printers.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest-death-test.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest-test-part.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest-typed-test.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest-matchers.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest-assertion-result.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest-param-test.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest-spi.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest_prod.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/include/gtest/gtest_pred_impl.h
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/libgtest.a
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/libgtest_main.a
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/pkgconfig/gtest.pc
-- Installing: /root/.conan2/p/b/gtest907ad17c8dd3f/p/lib/pkgconfig/gtest_main.pc

gtest/1.13.0: package(): Packaged 1 file: LICENSE
gtest/1.13.0: package(): Packaged 4 '.a' files: libgtest.a, libgmock_main.a, libgmock.a, libgtest_main.a
gtest/1.13.0: package(): Packaged 38 '.h' files
gtest/1.13.0: package(): Packaged 2 '.md' files: README.md, README.md
gtest/1.13.0: Created package revision 51b314fcadb11ccb373f0b69abdc1091
gtest/1.13.0: Package '9a21e417e84e3beb767cab96f8fb8e93120fa2ca' created
gtest/1.13.0: Full package reference: gtest/1.13.0#8a0bc5b3e159ed45de97260c2bff65b5:9a21e417e84e3beb767cab96f8fb8e93120fa2ca#51b314fcadb11ccb373f0b69abdc1091
gtest/1.13.0: Package folder /root/.conan2/p/b/gtest907ad17c8dd3f/p
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.names' used in: gtest/1.13.0

======== Finalizing install (deploy, generators) ========
conanfile.txt: Writing generators to /root/project/conan/deb
conanfile.txt: Generator 'CMakeToolchain' calling 'generate()'
conanfile.txt: CMakeToolchain generated: conan_toolchain.cmake
conanfile.txt: Preset 'conan-debug' added to CMakePresets.json. Invoke it manually using 'cmake --preset conan-debug' if using CMake>=3.23
conanfile.txt: If your CMake version is not compatible with CMakePresets (<3.23) call cmake like: 'cmake <path> -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/root/project/conan/deb/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Debug'
conanfile.txt: CMakeToolchain generated: CMakePresets.json
conanfile.txt: CMakeToolchain generated: ../../CMakeUserPresets.json
conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
conanfile.txt: CMakeDeps necessary find_package() and targets for your CMakeLists.txt
    find_package(GTest)
    target_link_libraries(... gtest::gtest)
conanfile.txt: Generating aggregated env files
conanfile.txt: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
Install finished successfully

# cmake -DCMAKE_TOOLCHAIN_FILE="conan/deb/conan_toolchain.cmake" -DCMAKE_CXX_COMPILER="/usr/bin/clang-17" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_CXX_COMPILER="/usr/bin/clang++-17" -S . -B build
-- Using Conan toolchain: /root/project/conan/deb/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- The CXX compiler identification is Clang 17.0.6
-- Check for working CXX compiler: /usr/bin/clang++-17
-- Check for working CXX compiler: /usr/bin/clang++-17 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Component target declared 'GTest::gtest'
-- Conan: Component target declared 'GTest::gtest_main'
-- Conan: Component target declared 'GTest::gmock'
-- Conan: Component target declared 'GTest::gmock_main'
-- Conan: Target declared 'gtest::gtest'
-- Configuring done
-- Generating done
-- Build files have been written to: /root/project/build

# cmake --build build/
Scanning dependencies of target tests
[ 50%] Building CXX object CMakeFiles/tests.dir/main.cpp.o
[100%] Linking CXX executable tests
[100%] Built target tests

# ./build/tests 
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from MyTestCase
[ RUN      ] MyTestCase.MyTestName
[       OK ] MyTestCase.MyTestName (0 ms)
[----------] 1 test from MyTestCase (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[  PASSED  ] 1 test.

Some important considerations:

@matheusgomes28
Copy link
Contributor Author

matheusgomes28 commented Jan 26, 2024

@uilianries Thank you very much for trying it out and providing your workflow. I figured the issue is the compiler.cppstd=20 not working. Although that setting is accepted, it doesn't build gtest correectly with the right string ABI.

Is there a reason why Conan supports compiler.cppstd=20 but the recipe for gtest doesn't work under it?

For those who may have the same issue: use compiler.cppstd=17 - Make sure you're building from source with the same compiler.cppstd

@uilianries
Copy link
Member

@matheusgomes28 Now I see your error, is about C++20, not C++17 like you described in your Conan profile in this issue description!!!

For those who may have the same issue: use compiler.cppstd=17

Not true!! I'll explain:

There is another related issue (spdlog) with same error somewhere (I couldn't find). The thing is:

You are consuming the pre-built binary of GTest from Conan Center. It was built using C++14, which Conan takes as ABI compatible. However, there is a breaking in C++20 that does not make it compatible (it works for C++17). Right now, we have a new feature to Conan (conan-io/conan#15348) to make it incompatible between C++14 and C++20.

You have to do: Build GTest from sources

conan install conanfile.txt -s build_type=Debug --build=gtest

It will cache a new package of Gtest, using your defined compiler.cppstd.

@matheusgomes28
Copy link
Contributor Author

matheusgomes28 commented Jan 26, 2024

@uilianries I had built from source as well with the std set to 20 in the profile before btw, but no luck. I'll run a few more tests after work and I'll port the findings here!

I.e. I was not consuming a pre built package, I also tried --build="*" and it hadn't worked with the standard set to 20

@uilianries
Copy link
Member

@matheusgomes28 It should work, if you are doing it locally, please remove all your cache related to gtest: conan remove gtest -c, my guess is you are still consuming older cppstd version, as Conan will take the first "compatible", including that one built with C++14.

@matheusgomes28
Copy link
Contributor Author

@uilianries Confirmed locally, works on compiler.cppstd=20 as well. No idea why it didn't work before, maybe I have wrongly specified the compiler on a cmake preset or something. I should be able to fix my CI now. Thank you very much and I'll close this now 😄

@uilianries
Copy link
Member

@matheusgomes28 Thank you for your feedback 😸

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

No branches or pull requests

2 participants