ClickHouse/clickhouse-cpp

Error running example

Abhi4356-S opened this issue · 3 comments

Compiling in Linux gives me error.

I am supposed to use below CMakeLists.txt file

cmake_minimum_required(VERSION 3.0)
project(clickhouse-example)
set(CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME} "clickhouse.cpp")
target_link_libraries(${PROJECT_NAME} /usr/local/lib/libclickhouse-cpp-lib.so)

I have libclickhouse-cpp-lib.a at usr/local/lib and hence I modified above file as..

target_link_libraries(${PROJECT_NAME} /usr/local/lib/libclickhouse-cpp-lib.a)

Below is the error, I get

/usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(types.cpp.o): in function clickhouse::Type::GetTypeUniqueId() const': types.cpp:(.text+0x3493): undefined reference to CityHash64WithSeed(char const*, unsigned long, unsigned long)'
/usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(compressed.cpp.o): in function clickhouse::CompressedOutput::Compress(void const*, unsigned long)': compressed.cpp:(.text+0xf4): undefined reference to LZ4_compress_default'
/usr/bin/ld: compressed.cpp:(.text+0x122): undefined reference to CityHash128(char const*, unsigned long)' /usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(compressed.cpp.o): in function clickhouse::CompressedOutput::PreallocateCompressBuffer(unsigned long)':
compressed.cpp:(.text+0x1b5): undefined reference to LZ4_compressBound' /usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(compressed.cpp.o): in function clickhouse::CompressedOutput::CompressedOutput(clickhouse::OutputStream*, unsigned long)':
compressed.cpp:(.text+0x307): undefined reference to LZ4_compressBound' /usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(compressed.cpp.o): in function clickhouse::CompressedInput::Decompress()':
compressed.cpp:(.text+0x60d): undefined reference to CityHash128(char const*, unsigned long)' /usr/bin/ld: compressed.cpp:(.text+0x691): undefined reference to LZ4_decompress_safe'
/usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(lowcardinality.cpp.o): in function clickhouse::ColumnLowCardinality::computeHashKey(clickhouse::ItemView const&)': lowcardinality.cpp:(.text+0x397): undefined reference to CityHash64(char const*, unsigned long)'
/usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(lowcardinality.cpp.o): in function clickhouse::ColumnLowCardinality::LoadBody(clickhouse::InputStream*, unsigned long)': lowcardinality.cpp:(.text+0x2a52): undefined reference to CityHash64(char const*, unsigned long)'
/usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(lowcardinality.cpp.o): in function clickhouse::ColumnLowCardinality::AppendNullItem()': lowcardinality.cpp:(.text+0x3772): undefined reference to CityHash64(char const*, unsigned long)'
/usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(lowcardinality.cpp.o): in function clickhouse::ColumnLowCardinality::AppendDefaultItem()': lowcardinality.cpp:(.text+0x4148): undefined reference to CityHash64(char const*, unsigned long)'
/usr/bin/ld: /usr/local/lib/libclickhouse-cpp-lib.a(lowcardinality.cpp.o): in function clickhouse::ColumnLowCardinality::AppendUnsafe(clickhouse::ItemView const&)': lowcardinality.cpp:(.text+0x51ae): undefined reference to CityHash64(char const*, unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/clickhouse-example.dir/build.make:84: clickhouse-example] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/clickhouse-example.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I built the library using the steps provided on github
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
cmake version 3.16.3

Please help.

Can you upload the CMakeLists.txt and simple code ? @Abhi4356-S

Hi

I resolved the above issue. I am trying to use this library in my project to check if click house fits our project. I am using the libclickhouse-cpp-lib.so file to link to our code.

I am able to compile it using g++ without any errors

g++ test1.cc -o test -L/home/Proj/lib -Wl,-R/home/Proj/lib -lclickhouse-cpp-lib

but with CMakeLists.txt file it is giving me below error

/usr/bin/ld: src/unit_test/metrics1/CMakeFiles/ut_metrics1.dir/test1.cc.o: in function main::{lambda(clickhouse::Block const&)#1}::operator()(clickhouse::Block const&) const': /home/user1/Proj/builds/trp/Build/../src/unit_test/metrics1/test1.cc:41: undefined reference to clickhouse::ColumnString::At(unsigned long) const'
/usr/bin/ld: src/unit_test/metrics1/CMakeFiles/ut_metrics1.dir/test1.cc.o: in function main': /home/user1/Proj/builds/trp/Build/../src/unit_test/metrics1/test1.cc:27: undefined reference to clickhouse::ColumnString::Append(std::string const&)'
/usr/bin/ld: /home/user1/Proj/builds/trp/Build/../src/unit_test/metrics1/test1.cc:28: undefined reference to clickhouse::ColumnString::Append(std::string const&)' /usr/bin/ld: /home/user1/Proj/builds/trp/Build/../src/unit_test/metrics1/test1.cc:30: undefined reference to clickhouse::Block::AppendColumn(std::string const&, std::shared_ptrclickhouse::Column const&)'
/usr/bin/ld: /home/user1/Proj/builds/trp/Build/../src/unit_test/metrics1/test1.cc:31: undefined reference to clickhouse::Block::AppendColumn(std::string const&, std::shared_ptr<clickhouse::Column> const&)' /usr/bin/ld: /home/user1/Proj/builds/trp/Build/../src/unit_test/metrics1/test1.cc:33: undefined reference to clickhouse::Client::Insert(std::string const&, clickhouse::Block const&)'
/usr/bin/ld: /home/user1/Proj/builds/trp/Build/../src/unit_test/metrics1/test1.cc:37: undefined reference to `clickhouse::Client::Select(std::string const&, std::function<void (clickhouse::Block const&)>)'
collect2: error: ld returned 1 exit status

My CMakeLists.txt file:

set(outfileNameNoExt test)
set(projectName ut_metrics1)
set(SRCS test1.cc)
add_executable(${projectName} ${SRCS})
TARGET_PROPS(${projectName} ${outfileNameNoExt})
LINK_DIRS(${projectName})
if (MSVC)
LINK_AGAINST(${projectName} clickhouse-cpp-lib
)
elseif(LINUX)
set (libList clickhouse-cpp-lib)
LINK_AGAINST(${projectName} ${libList})
endif()

Please help

please use link_directories and target_link_libraries