/usr/bin/ld: 在链接 g++ 期间找不到
这个问题已经出现过很多次了。但我没有找到答案。
我有这个 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ld
的手册页对-l
选项的描述如下(省略无关细节):如果您仔细阅读本文,您将得出这样的结论:
-llibclickhouse-cpp-lib
指示ld
搜索名为liblibclickhouse-cpp 的库-lib.so
显然不存在。这应该只是
-lclickhouse-cpp-lib
。ld
's manual page describes the-l
option as follows (irrelevant details omitted):If you read this very carefully, you will reach the conclusion that
-llibclickhouse-cpp-lib
instructsld
to search for a library namedliblibclickhouse-cpp-lib.so
which, obviously, does not exist.This should simply be
-lclickhouse-cpp-lib
.就我而言,当我将 Cmake 版本更改为 2.9 时,问题得到解决
in my case, the problem was solved when I change the Cmake version to 2.9
试试这个:
Try this: