gpt4 book ai didi

c++ - 为 QFS 构建 C++ 包装器

转载 作者:搜寻专家 更新时间:2023-10-31 01:08:30 25 4
gpt4 key购买 nike

我对编译/链接非常讨厌。

我已经尝试了我能找到的一切,没有任何效果。

websockserver.h:516: undefined reference to `qfs_init'
websockserver.h:527: undefined reference to `qfs_read'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Rmdir(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Remove(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Open(char const*, int, int, int, int, int, int, unsigned short, signed char, signed char)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Write(int, char const*, unsigned long)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Read(int, char*, unsigned long)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Rename(char const*, char const*, bool)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Tell(int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Seek(int, long, int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Stat(char const*, KFS::KfsFileAttr&, bool)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Close(int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Create(char const*, int, bool, int, int, int, int, bool, unsigned short, signed char, signed char)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Sync(int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::IsDirectory(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::ErrorCodeToStr(int)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::IsFile(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Exists(char const*)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Mkdir(char const*, unsigned short)'
./cqfs//libcqfs.so: undefined reference to `KFS::KfsClient::Readdir(char const*, std::vector<std::string, std::allocator<std::string> >&)'
./cqfs//libcqfs.so: undefined reference to `KFS::Connect(std::string const&, int)'
collect2: error: ld returned 1 exit status
make: *** [w] Error 1

websockserver.h:514 到 530

long numbytes;
struct cqfs *qfs;
if(!qfs_init(&qfs, "127.0.0.1", 20000))
printf("Failed to init qfs connection\n");

int fd = qfs_open(qfs, "APP.js", O_RDONLY);
if(fd < 0)
printf("Error opening file: %s\n", qfs_error(qfs));

numbytes = (long)qfs_seek(qfs, fd, 0L, SEEK_END);
qfs_seek(qfs, fd, 0L, SEEK_SET);
ret = calloc(numbytes + 1, sizeof(char));

if(qfs_read(qfs, fd, ret, numbytes) < 0)
printf("Error reading file: %s\n", qfs_error(qfs));

qfs_close(qfs, fd);

QFS提供了.so和.a的
libqfs_client
libqfs_qcdio
libqfs_io
libqfs_common
libqfs_qcrs

我如何构建我的包装器(cqfs.cpp、cqfs.h)?

这是我当前的命令:

g++ -Wall -DBOOST_SP_USE_QUICK_ALLOCATOR -shared -o libcqfs.so cqfs.cpp cqfs.h -fPIC -L./libqfs_client.so -L./libqfs_qcdio.so -lpthread -lrt -L./libqfs_io.so -L./libqfs_common.so -L./libqfs_qcdio.so  -lpthread -lz -lrt -lboost_regex-mt -lcrypto -L./libqfs_qcrs.so -lc 

基于 Quantcast 提供的示例应用程序(不是库):

c++ -Wall -DBOOST_SP_USE_QUICK_ALLOCATOR -g    CMakeFiles/qfssample.dir/qfssample_main.o  -o qfssample -rdynamic ../../src/cc/libclient/libqfs_client.a ../../src/cc/qcdio/libqfs_qcdio.a -lpthread -lrt ../../src/cc/kfsio/libqfs_io.a ../../src/cc/common/libqfs_common.a ../../src/cc/qcdio/libqfs_qcdio.a -lpthread -lz -lrt -lboost_regex-mt -lcrypto ../../src/cc/qcrs/libqfs_qcrs.a 

.a 或 .so 没有区别

最佳答案

看起来您错误地使用了 g++ 的 -L 参数。 -L 的参数应该引用包含库的目录,而不是直接引用它们。

为了演示,我创建了一个带有 ConnectReaddir 的简单示例(为简洁起见,我省略了它,但如果您想查看它,请告诉我) .这是我精心设计的 c++ 命令,它可以正确编译和链接:

c++ -Wall -o t -I./build/release/include -L./build/release/lib t.cc -lqfs_client -lqfs_common -lqfs_io -lqfs_qcdio -lqfs_qcrs -lpthread -lboost_regex-mt -lz -lcrypto

然后可以通过指定 LD_LIBRARY_PATH(在 Max OS X 上为 DYLD_LIBRARY_PATH)来运行它:

DYLD_LIBRARY_PATH=$PWD/build/release/lib ./t
.
..
dumpster
test
test2
test3
user

请注意,在 Linux 上您必须使用 LD_LIBRARY_PATH 而不是 DYLD_LIBRARY_PATH

我们实际上正在为主要项目中的 QFS 构建 C 绑定(bind)。这是 pull request .如果您不习惯直接从 fork 工作(它们非常实验性),您可以检查它并使用 make VERBOSE=1 构建以查看命令实际上用于构建组件并将其应用于构建您自己的绑定(bind)。

更新:QFS API 的 C 绑定(bind)现在在 master 分支中可用。

例如,这是在我的 mac 上构建共享库的输出行:

/usr/bin/c++   -I/opt/local/include -Wall -DBOOST_SP_USE_QUICK_ALLOCATOR -O2 -g -shared   -o libqfsc.dylib -install_name /Users/sday/c/qfs/build/release/src/cc/qfsc/libqfsc.dylib CMakeFiles/qfsc-shared.dir/qfsc.o ../libclient/libqfs_client.dylib ../kfsio/libqfs_io.dylib ../common/libqfs_common.dylib -lpthread -lz ../qcdio/libqfs_qcdio.dylib /usr/local/lib/libboost_regex-mt.dylib /usr/local/lib/libboost_system-mt.dylib ../qcrs/libqfs_qcrs.dylib -lcrypto

免责声明:我为 Quantcast 工作。

关于c++ - 为 QFS 构建 C++ 包装器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17957559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com