首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >构建QFS的C++包装器

构建QFS的C++包装器
EN

Stack Overflow用户
提问于 2013-07-30 21:16:57
回答 1查看 179关注 0票数 2

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

我已经试过了我能找到的一切,都没有用。

代码语言:javascript
复制
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

代码语言:javascript
复制
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)?

这是我现在的命令:

代码语言:javascript
复制
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提供的示例应用程序(非库):

代码语言:javascript
复制
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没有起到什么作用

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-02 16:38:33

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

为了演示,我用ConnectReaddir创建了一个简单的示例(为了简洁起见,我省略了它,但是如果您想看的话请告诉我)。下面是我构建的c++命令,以使它能够正确编译和链接:

代码语言:javascript
复制
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 (DYLD_LIBRARY_PATH on Max )来运行它:

代码语言:javascript
复制
DYLD_LIBRARY_PATH=$PWD/build/release/lib ./t
.
..
dumpster
test
test2
test3
user

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

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

更新: QFS的C绑定现在可以在主分支中使用。

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

代码语言:javascript
复制
/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工作。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17957559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档