为QFS构建C ++包装器

时间:2013-07-30 21:16:57

标签: c++ c interface wrapper qfs

我对编译/链接非常可怕。

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

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 of 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没有什么区别

1 个答案:

答案 0 :(得分:4)

看起来你错误地将-L参数用于g ++。 -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

然后可以通过在Max OS X上指定LD_LIBRARY_PATHDYLD_LIBRARY_PATH)来运行它:

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

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

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

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

例如,以下是在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工作。