/usr/bin/ld: 在链接 g++ 期间找不到

发布于 2025-01-11 17:27:07 字数 1279 浏览 0 评论 0原文

这个问题已经出现过很多次了。但我没有找到答案。

我有这个 .cpp 文件

#include <clickhouse/client.h>
#include <iostream>
using namespace clickhouse;


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

    client.Select("SELECT l.a, l.b from table", [] (const Block& block)
        {
            for (size_t i = 0; i < block.GetRowCount(); ++i) {
                std::cout << block[0]->As<ColumnUInt64>()->At(i) << " "
                        << block[1]->As<ColumnString>()->At(i) << "\n";
            }
        }
    );
    return 0;
}

,并且我已经实例化了 SO 库,就像写的 这里。 之后,我得到了 /usr/local/lib 目录 的以下结构:

~/$ ls /usr/local/lib
>>libclickhouse-cpp-lib-static.a  libclickhouse-cpp-lib.so

在下一步中,我尝试使用 g++ 执行编译,

~/$ g++ run.cpp -std=c++17 -o result -llibclickhouse-cpp-lib -L/usr/local/lib
>>/usr/bin/ld: cannot find -llibclickhouse-cpp-lib
>>collect2: error: ld returned 1 exit status

我不知道是什么阻碍了创建链接。

感谢您的帮助!

This question has already been here so many times. But I didn't find the answer.

I have this .cpp file

#include <clickhouse/client.h>
#include <iostream>
using namespace clickhouse;


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

    client.Select("SELECT l.a, l.b from table", [] (const Block& block)
        {
            for (size_t i = 0; i < block.GetRowCount(); ++i) {
                std::cout << block[0]->As<ColumnUInt64>()->At(i) << " "
                        << block[1]->As<ColumnString>()->At(i) << "\n";
            }
        }
    );
    return 0;
}

and I have instantiated SO library, like written here.
after that i got the following structure of /usr/local/lib directory:

~/$ ls /usr/local/lib
>>libclickhouse-cpp-lib-static.a  libclickhouse-cpp-lib.so

in next step I trying execute compilation with g++

~/$ g++ run.cpp -std=c++17 -o result -llibclickhouse-cpp-lib -L/usr/local/lib
>>/usr/bin/ld: cannot find -llibclickhouse-cpp-lib
>>collect2: error: ld returned 1 exit status

I don't know what hinders create links.

thank You for Your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

难理解 2025-01-18 17:27:07

ld的手册页对-l选项的描述如下(省略无关细节):

-l 名称规范

--library=namespec

将namespec指定的归档文件或目标文件添加到列表中
要链接的文件。 [...] ld 将在目录中搜索名为的库
libnamespec.so

如果您仔细阅读本文,您将得出这样的结论:-llibclickhouse-cpp-lib 指示 ld 搜索名为 liblibclickhouse-cpp 的库-lib.so 显然不存在。

这应该只是-lclickhouse-cpp-lib

ld's manual page describes the -l option as follows (irrelevant details omitted):

-l namespec

--library=namespec

Add the archive or object file specified by namespec to the list of
files to link. [...] ld will search a directory for a library called
libnamespec.so

If you read this very carefully, you will reach the conclusion that -llibclickhouse-cpp-lib instructs ld to search for a library named liblibclickhouse-cpp-lib.so which, obviously, does not exist.

This should simply be -lclickhouse-cpp-lib.

何止钟意 2025-01-18 17:27:07

就我而言,当我将 Cmake 版本更改为 2.9 时,问题得到解决

in my case, the problem was solved when I change the Cmake version to 2.9

私野 2025-01-18 17:27:07

试试这个:

g++ -std=c++11 -I./ -I./contrib -L./build/clickhouse/ -lclickhouse-cpp-lib-static -o demo demo.cpp ./build/clickhouse/libclickhouse-cpp-lib-static.a ./build/contrib/lz4/liblz4-lib.a ./build/contrib/cityhash/libcityhash-lib.a ./build/contrib/absl/libabsl-lib.a

Try this:

g++ -std=c++11 -I./ -I./contrib -L./build/clickhouse/ -lclickhouse-cpp-lib-static -o demo demo.cpp ./build/clickhouse/libclickhouse-cpp-lib-static.a ./build/contrib/lz4/liblz4-lib.a ./build/contrib/cityhash/libcityhash-lib.a ./build/contrib/absl/libabsl-lib.a
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文