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

Linking fails with cmake when not using a pre-installed abseil AND using C++17 #634

Closed
MarcinZukowski opened this issue Mar 9, 2020 · 1 comment

Comments

@MarcinZukowski
Copy link

I'm having issues linking with abseil when using a pre-installed abseil:

main.cpp:(.text.startup+0x1ed): undefined reference to `bool absl::str_format_internal::FormatArgImpl::Dispatch<std::basic_string_view<char, std::char_traits<char> > >(absl::str_format_internal::FormatArgImpl::Data, absl::str_format_internal::FormatConversionSpec, void*)'

It only happens if I use "preinstalled" abseil AND if I usee C++17.
If I do add_subdirectory it works, or if I change to C++14 it also works.

Here's CMakeLists.txt

project(abseil-bug)

set(CMAKE_CXX_STANDARD 17)

# This works with 17
add_subdirectory(abseil-cpp)

# Fails with 17, works with 14
#set(abseil_prefix ${PROJECT_SOURCE_DIR}/abseil-cpp/install/)
#include(${abseil_prefix}/lib64/cmake/absl/abslConfig.cmake)

# Fails with 17, works with 14
#find_package(absl REQUIRED PATHS ${PROJECT_SOURCE_DIR}/abseil-cpp/install/)

add_executable(abseil-bug main.cpp)
target_link_libraries(abseil-bug absl::strings absl::str_format)

and here's main.cpp


#include "absl/strings/ascii.h"
#include "absl/strings/str_format.h"

int main()
{
    std::string x = absl::StrFormat("Why? %s\n", absl::StripAsciiWhitespace(" foo "));
    printf("%s\n", x.c_str());    
}

and the Makefile that drives it all

default: all

.ONESHELL:
all: abseil-cpp
	mkdir -p build
	cd build
	cmake -DCMAKE_BUILD_TYPE=Release ../
	make -j 8
	
abseil-cpp:
	git clone --depth 1 https://github.com/abseil/abseil-cpp
	cd abseil-cpp
	mkdir build && cd build
	cmake -DCMAKE_INSTALL_PREFIX=../install -DCMAKE_BUILD_TYPE=Release ../
	make -j 8 
	make install

clean: 
	rm -rf abseil-cpp build
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

2 participants