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

relative import error #86

Closed
kkonevets opened this issue Apr 7, 2021 · 22 comments · Fixed by #281 · May be fixed by #87
Closed

relative import error #86

kkonevets opened this issue Apr 7, 2021 · 22 comments · Fixed by #281 · May be fixed by #87

Comments

@kkonevets
Copy link

kkonevets commented Apr 7, 2021

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

@traceon
Copy link
Collaborator

traceon commented Apr 7, 2021

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

@kkonevets
Copy link
Author

Can't find no .gitmodules in a root directory

@kkonevets
Copy link
Author

kkonevets commented Apr 7, 2021

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]$ 

@traceon
Copy link
Collaborator

traceon commented Apr 7, 2021

/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.

@kkonevets
Copy link
Author

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

@traceon
Copy link
Collaborator

traceon commented Apr 7, 2021

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

@kkonevets
Copy link
Author

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

@traceon
Copy link
Collaborator

traceon commented Apr 7, 2021

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.

@kkonevets
Copy link
Author

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 :)

@traceon
Copy link
Collaborator

traceon commented Apr 7, 2021

#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.

@kkonevets
Copy link
Author

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.

@traceon
Copy link
Collaborator

traceon commented Apr 8, 2021

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.

@frkn4129
Copy link

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

@frkn4129
Copy link

@kkonevets can you help me solve your problem ?

@kkonevets
Copy link
Author

kkonevets commented Nov 12, 2021

@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

@frkn4129
Copy link

@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?

@kkonevets
Copy link
Author

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

@kkonevets
Copy link
Author

kkonevets commented Nov 12, 2021

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

@frkn4129
Copy link

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

@kkonevets
Copy link
Author

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

read this

@frkn4129
Copy link

frkn4129 commented Nov 12, 2021

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

@kkonevets
Copy link
Author

kkonevets commented Nov 12, 2021

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.

DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Apr 5, 2022
This change solves ClickHouse#86, ClickHouse#99.

Furthermore, it eases Conan packaging, as Conan already provides
abseil, lz4 and cityhash.

Signed-off-by: David Keller <[email protected]>
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Apr 13, 2022
This change solves ClickHouse#86, ClickHouse#99.

Furthermore, it eases Conan packaging, as Conan already provides
abseil, lz4 and cityhash.

Signed-off-by: David Keller <[email protected]>
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Apr 13, 2022
This change solves ClickHouse#86, ClickHouse#99.

Furthermore, it eases Conan packaging, as Conan already provides
abseil, lz4 and cityhash.

Signed-off-by: David Keller <[email protected]>
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Apr 13, 2022
This change solves ClickHouse#86, ClickHouse#99.

Furthermore, it eases Conan packaging, as Conan already provides
abseil, lz4 and cityhash.

Signed-off-by: David Keller <[email protected]>
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Apr 13, 2022
This change solves ClickHouse#86, ClickHouse#99.

Furthermore, it eases Conan packaging, as Conan already provides
abseil, lz4 and cityhash.

Signed-off-by: David Keller <[email protected]>
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Apr 20, 2022
This change solves ClickHouse#86, ClickHouse#99.

Furthermore, it eases Conan packaging, as Conan already provides
abseil, lz4 and cityhash.

Signed-off-by: David Keller <[email protected]>
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Jul 28, 2022
DavidKeller pushed a commit to woorton/clickhouse-cpp that referenced this issue Nov 23, 2022
xakod pushed a commit to xakod/clickhouse-cpp that referenced this issue Feb 2, 2023
@Enmk Enmk closed this as completed in #281 Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants