clickhouse-cpp icon indicating copy to clipboard operation
clickhouse-cpp copied to clipboard

relative import error

Open kkonevets opened this issue 3 years ago • 22 comments

I did

$ git clone https://github.com/abseil/abseil-cpp.git (latest commit 1415b5936a2ac2f084850b09057e05fb5798b2f1)
$ cmake ..
$ make
$ sudo make install

Then I tried to build this example

                 from /usr/local/include/clickhouse/block.h:3,
                 from /usr/local/include/clickhouse/query.h:3,
                 from /usr/local/include/clickhouse/client.h:3,
                 from /home/guyos/Documents/analytics/main.cpp:1:
/usr/local/include/clickhouse/types/types.h:3:10: fatal error: absl/numeric/int128.h: No such file or directory
    3 | #include "absl/numeric/int128.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~

Seems like absl should not be explicitly included to types.h but be linked with some function instead. Relative import error

kkonevets avatar Apr 07 '21 08:04 kkonevets

Abseil is included as a submodule in clickhouse-cpp. You should just clone the clickhouse-cpp repo recursively, with submodules:

git clone --recursive https://github.com/ClickHouse/clickhouse-cpp.git

traceon avatar Apr 07 '21 12:04 traceon

Can't find no .gitmodules in a root directory

kkonevets avatar Apr 07 '21 14:04 kkonevets

Looks like git clone --recursive does not help. /usr/local/include/ does not contain contrtib/absl

(base) [guyos@tc build]$ sudo make install
[  5%] Built target lz4-lib
[  8%] Built target absl-lib
[ 11%] Built target cityhash-lib
[ 55%] Built target clickhouse-cpp-lib-static
[100%] Built target clickhouse-cpp-lib
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libclickhouse-cpp-lib.so
-- Installing: /usr/local/lib/libclickhouse-cpp-lib-static.a
-- Installing: /usr/local/include/clickhouse/block.h
-- Installing: /usr/local/include/clickhouse/client.h
-- Installing: /usr/local/include/clickhouse/error_codes.h
-- Installing: /usr/local/include/clickhouse/exceptions.h
-- Installing: /usr/local/include/clickhouse/protocol.h
-- Installing: /usr/local/include/clickhouse/query.h
-- Installing: /usr/local/include/clickhouse/base/buffer.h
-- Installing: /usr/local/include/clickhouse/base/coded.h
-- Installing: /usr/local/include/clickhouse/base/compressed.h
-- Installing: /usr/local/include/clickhouse/base/input.h
-- Installing: /usr/local/include/clickhouse/base/output.h
-- Installing: /usr/local/include/clickhouse/base/platform.h
-- Installing: /usr/local/include/clickhouse/base/singleton.h
-- Installing: /usr/local/include/clickhouse/base/socket.h
-- Installing: /usr/local/include/clickhouse/base/string_utils.h
-- Installing: /usr/local/include/clickhouse/base/string_view.h
-- Installing: /usr/local/include/clickhouse/base/wire_format.h
-- Installing: /usr/local/include/clickhouse/columns/array.h
-- Installing: /usr/local/include/clickhouse/columns/column.h
-- Installing: /usr/local/include/clickhouse/columns/date.h
-- Installing: /usr/local/include/clickhouse/columns/decimal.h
-- Installing: /usr/local/include/clickhouse/columns/enum.h
-- Installing: /usr/local/include/clickhouse/columns/factory.h
-- Installing: /usr/local/include/clickhouse/columns/ip4.h
-- Installing: /usr/local/include/clickhouse/columns/ip6.h
-- Installing: /usr/local/include/clickhouse/columns/itemview.h
-- Installing: /usr/local/include/clickhouse/columns/lowcardinality.h
-- Installing: /usr/local/include/clickhouse/columns/nullable.h
-- Installing: /usr/local/include/clickhouse/columns/numeric.h
-- Installing: /usr/local/include/clickhouse/columns/string.h
-- Installing: /usr/local/include/clickhouse/columns/tuple.h
-- Installing: /usr/local/include/clickhouse/columns/utils.h
-- Installing: /usr/local/include/clickhouse/columns/uuid.h
-- Installing: /usr/local/include/clickhouse/types/type_parser.h
-- Installing: /usr/local/include/clickhouse/types/types.h
(base) [guyos@tc build]$ 

kkonevets avatar Apr 07 '21 14:04 kkonevets

/usr/local/include/ does not contain contrtib/absl

/usr/local/include/ should not contain contrtib/absl. The goal is to build clickhouse-cpp, and the output you posted shows that it was successfully built and installed.

traceon avatar Apr 07 '21 17:04 traceon

yes, it is successfully installed but can't be used.Try to run your example after fresh sudo make install

kkonevets avatar Apr 07 '21 17:04 kkonevets

What do you mean it can't be used? How are you trying to use it exactly?

traceon avatar Apr 07 '21 17:04 traceon

git clone --recursive https://github.com/ClickHouse/clickhouse-cpp.git
cd clickhouse-cpp/
mkdir build
cd build/
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j8
sudo make install

This is my test project:

git clone https://github.com/kkonevets/test_clickhouse_cpp.git
cd test_clickhouse_cpp
mkdir build
cd build/
cmake -DCMAKE_BUILD_TYPE=Release ..
make

And this is what I get:

[guyos@tc build]$ make
Scanning dependencies of target main
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
In file included from /usr/local/include/clickhouse/columns/column.h:5,
                 from /usr/local/include/clickhouse/block.h:3,
                 from /usr/local/include/clickhouse/query.h:3,
                 from /usr/local/include/clickhouse/client.h:3,
                 from /home/guyos/Documents/test_clickhouse_cpp/main.cpp:1:
/usr/local/include/clickhouse/types/types.h:3:10: fatal error: absl/numeric/int128.h: No such file or directory
    3 | #include "absl/numeric/int128.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/main.dir/build.make:82: CMakeFiles/main.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:103: all] Error 2

kkonevets avatar Apr 07 '21 17:04 kkonevets

You have 2 options:

  • install abseil in your system
  • add clickhouse-cpp as a submodule in your repo and add it as a subproject in your cmake configs, and then link with clickhouse-cpp library in cmake. That will bring the internal abseil library to your project as a transitive dependency.

traceon avatar Apr 07 '21 18:04 traceon

The first option will not work, because you make a relative include #include "absl/numeric/int128.h", something like #include <absl/numeric/int128.h> would work. The second option is not convenient, I don't want to grow my code base unnecessarily.

P.S.: now I got the impression about the library :)

kkonevets avatar Apr 07 '21 18:04 kkonevets

#include "absl/numeric/int128.h" should still be able to locate the system-wide installed abseil. You can also try an older version of sources, the v1.4.1 tag - it should be free of abseil dependency.

traceon avatar Apr 07 '21 19:04 traceon

Yes, I confirm that #include "absl/numeric/int128.h" will work if one sets CMAKE_PREFIX_PATH to abseil install path. But then in my opinion directorycontrib/absl is redundant and confuses a user and it would be nice to add info about abseil installation option to a README.

kkonevets avatar Apr 08 '21 02:04 kkonevets

Thanks for your input. If you have any specific improvement on you mind, feel free to open a PR with proposed changes. Meanwhile, I am sure the maintainers will look into improving this at some point.

traceon avatar Apr 08 '21 08:04 traceon

i am having the same problem. What should I do? can you help me

frkn4129 avatar Nov 10 '21 06:11 frkn4129

@kkonevets can you help me solve your problem ?

frkn4129 avatar Nov 12 '21 06:11 frkn4129

@kkonevets can you help me solve your problem ?

Didn't try to compile the fresh version of the code, as I wrote set CMAKE_PREFIX_PATH to abseil install path and it should work

kkonevets avatar Nov 12 '21 06:11 kkonevets

@kkonevets I was able to build but I couldn't run i run the code like this -> g++ -std=c++17 example.cpp , Do I need to give a different parameter?

frkn4129 avatar Nov 12 '21 06:11 frkn4129

yes, try g++ -I /path/to/abseil -std=c++17 example.cpp

kkonevets avatar Nov 12 '21 06:11 kkonevets

Why you are not able to run the example if you could build it? @frkn4129 g++ -std=c++17 example.cpp - this is a build procedure, not a run. To run you use an executable that you get from g++, do not confuse this things

kkonevets avatar Nov 12 '21 06:11 kkonevets

i can't understand my code : #include <clickhouse/client.h>

using namespace clickhouse;

/// Initialize client connection. Client client(ClientOptions().SetHost("localhost")); . . .

i run -> g++ -I /usr/local/include/absl -std=c++17 deneme.cpp /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function _start': (.text+0x24): undefined reference to main' /usr/bin/ld: /tmp/ccD9lgR9.o: in function __static_initialization_and_destruction_0(int, int)': deneme.cpp:(.text+0x50): undefined reference to clickhouse::NetrworkInitializer::NetrworkInitializer()' /usr/bin/ld: deneme.cpp:(.text+0xca): undefined reference to clickhouse::Client::Client(clickhouse::ClientOptions const&)' /usr/bin/ld: deneme.cpp:(.text+0x10c): undefined reference to clickhouse::Client::~Client()' collect2: error: ld returned 1 exit status this error. @kkonevets

frkn4129 avatar Nov 12 '21 07:11 frkn4129

you should also link with ClickHouse lib, g++ -Ldir -lLIBRARY -std=c++17 deneme.cpp

read this

kkonevets avatar Nov 12 '21 07:11 kkonevets

i can try g++ -L/usr/local/lib -lclickhouse-cpp-lib -I /usr/local/include/absl -std=c++17 deneme.cpp but again this error

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function _start': (.text+0x24): undefined reference to main' /usr/bin/ld: /tmp/cctXGpYn.o: in function __static_initialization_and_destruction_0(int, int)': deneme.cpp:(.text+0x50): undefined reference to clickhouse::NetrworkInitializer::NetrworkInitializer()' /usr/bin/ld: deneme.cpp:(.text+0xca): undefined reference to clickhouse::Client::Client(clickhouse::ClientOptions const&)' /usr/bin/ld: deneme.cpp:(.text+0x10c): undefined reference to clickhouse::Client::~Client()' collect2: error: ld returned 1 exit status

frkn4129 avatar Nov 12 '21 07:11 frkn4129

First of all, why do you use sudo to compile? Then, you don't need -L/usr/local/lib because /usr/local/lib is a standard lookup dir. Then looks like you don't have a main function in your example or it is misspelled. I guess this is not a place to ask questions like this, go ask stack overflow, your questions have nothing related to current issue.

kkonevets avatar Nov 12 '21 07:11 kkonevets