2

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

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

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 提供
libqfs_client
libqfs_qcdio
libqfs_io
libqfs_common
libqfs_qcrs 的 .so 和 .a

如何构建我的包装器(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 没有区别

4

1 回答 1

4

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

为了演示,我创建了一个带有Connectand的简单示例Readdir(为简洁起见,我省略了它,但如果您想查看它,请告诉我)。这是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_PATHDYLD_LIBRARY_PATH在 Max OS X 上)来运行它:

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

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

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

更新: QFS API 的 C 绑定现在在 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 工作。

于 2013-08-02T16:38:33.987 回答