2

I am absolutely horrible with compiling/linking.

I have tried everything i could find, nothing works.

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 to 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 provides .so and .a of
libqfs_client
libqfs_qcdio
libqfs_io
libqfs_common
libqfs_qcrs

How do i build my wrapper (cqfs.cpp, cqfs.h)?

This is my current command:

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 

based on the example application(not library) provided by 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 or .so did not make a difference

Morgan
  • 4,143
  • 27
  • 35
Gaby_64
  • 77
  • 7

1 Answers1

4

It looks like you are incorrectly using the -L argument to g++. The argument of -L should refer to the directory that contains the libraries, rather than directly referencing them.

To demonstrate, I created a simple example with a Connect and Readdir (I've omitted it for brevity, but let me know if you want to see it). Here is the c++ command I crafted to get it to compile and link correctly:

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

One can then run it by specifying the LD_LIBRARY_PATH (DYLD_LIBRARY_PATH on Max OS X):

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

Note that you'll have to LD_LIBRARY_PATH instead of DYLD_LIBRARY_PATH on Linux.

We are actually working on building C bindings for QFS in the main project. Here is the pull request. If you're not comfortable with working directly from the fork (they are very experimental), you can check it out and build with make VERBOSE=1 to see the commands that are actually used to build the components and apply that to build your own bindings.

UPDATE: The C bindings for the QFS API are now available in the master branch.

For example, here is the line that is output to build the shared library on my 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

Disclaimer: I work for Quantcast.

stevvooe
  • 68
  • 3
  • currently this is my makefile string `g++ -Wall -DBOOST_SP_USE_QUICK_ALLOCATOR -shared -fPIC -o libcqfs.so cqfs.cpp cqfs.h libqfs_client.a libqfs_qcdio.a libqfs_io.a libqfs_common.a libqfs_qcdio.a libqfs_qcrs.a -lpthread -lrt -lz -lboost_regex-mt -lcrypto -lc` – Gaby_64 Aug 22 '13 at 21:36
  • my current wrapper implementation produces name mangling for a few functions no matter what, implemented is: `struct cqfs; struct qfs_fileattr; qfs_init (mangled) qfs_read (mangled) qfs_stat (mangled) qfs_error qfs_mkdir qfs_rename qfs_readdir qfs_rmdir qfs_create qfs_open qfs_close qfs_seek qfs_tell qfs_write qfs_sync qfs_del qfs_exists qfs_isfile qfs_isdir` I will take a look at your c bindings – Gaby_64 Aug 22 '13 at 21:48