ibayer / fastFM

fastFM: A Library for Factorization Machines
http://ibayer.github.io/fastFM
Other
1.07k stars 206 forks source link

cython-wrapper: modified setup.py to link against ffm2. Added cpp_ffm… #94

Closed caos21 closed 7 years ago

caos21 commented 7 years ago

it compiles, but I did not check, I am thinking about how to do this. I got one warning but is not important.

ibayer commented 7 years ago

Ultimately we want to replace https://github.com/ibayer/fastFM/blob/master/fastFM/base.py#L102

return ffm.ffm_predict(self.w0_, self.w_, self.V_, X_test)

with the predict function from the c++ lib

return ffm2.ffm_predict(self.w0_, self.w_, self.V_, X_test)

if this works without breaking any of the unit-tests (see README for how to run them) we are golden.

ibayer commented 7 years ago

I would suggest to start by writing a cython wrapper ffm2.ffm_predit() analogously to ffm.ffm_predit(). You could add an additional test to https://github.com/ibayer/fastFM/blob/master/fastFM/tests/test_ffm.py that checks if the new predict wrapper works.

def test_ffm2_predict():
    w0, w, V, y, X = get_test_problem()
    y_pred = ffm2.ffm_predict(w0, w, V, X)
assert_equal(y_pred, y)

https://github.com/ibayer/fastFM2/blob/api/fastFM_tests/api_tests/api_test.cpp should help you to see how to setup ffm2.ffm_predict.

It might even be a good idea to start with even simpler tests in the beginning.

def test_ffm2_predict_w0():
    w0, w, V, y, X = get_test_problem()
    w = 0
    V = 0
    y_pred = ffm2.ffm_predict(w0, w, V, X)
assert_equal(y_pred, w0)

Please don't hesitate to ask any clarifying questions. I think this PR is tackling a quite tricky problem.

caos21 commented 7 years ago

Thank you very much for the guiding. I will follow...

caos21 commented 7 years ago

Please, I do not follow the correspondences between the C and C++ API variable names: I have to preserve this signature ffm_predict(self.w0_, self.w_, self.V_, X_test) Then I have ffm2_predict(double w_0, double[:] w, np.ndarray[np.float64_t, ndim = 2] V, X): I tried to assign some of this values to Data and Model instances. I'm pushing changes.

caos21 commented 7 years ago

For instance, in ffm2.pyx line 30: I guessed:

m.add_parameter(&w_0)
m.add_parameter(&w[0], k)

d.add_prediction(&y[0], k, X.shape[0])

But I am not sure... Also I do not know what to do with V and X. I set split = 0. Thanks

ibayer commented 7 years ago
n_features = w.shape[0]
rank, n_features = V.shape
n_samples, n_features = X.shape

m.add_parameter(&w_0)
m.add_parameter(&w[0], n_features)
m.add_parameter(&V[0], rank, n_features, order=2)

d.add_prediction(&y[0], n_samples) # Same for target
#d.add_design_matrix(...

I have just merged changes onto the api branch that make the parameter names in fastfm.h more explicit. I have droped split from the api.

caos21 commented 7 years ago

Thanks, I will check.

caos21 commented 7 years ago

I can't test, some errors when installing fastfm using pip. Doesn't like this path/file #include "../../fastFM2/fastFM/fastfm.h" in the cython generated ffm2.cpp, but I checked and it's valid.

caos21 commented 7 years ago

Ok, I managed to install with pip: 1) Cloned fastFM2 in fastFM dir 2) Modified setup.py and cpp_ffm.pxd to point to correct addresses

Now I am having a problem when importing ffm2. Undefined references, I have to check.

ImportError: /home/ben/anaconda3/lib/python3.5/site-packages/ffm2.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _ZTINSt8ios_base7failureB5cxx11E

caos21 commented 7 years ago

I solved this error, now I have another


g++ -pthread -shared -L/home/ben/anaconda3/lib -Wl,-rpath=/home/ben/anaconda3/lib,--no-as-needed,-z,defs build/temp.linux-x86_64-3.5/fastFM/ffm2.o -LfastFM/ -LfastFM2/_builds/fastFM -L/home/ben/anaconda3/lib -lpython3.5m -o/home/ben/src/fastFM/ffm2.cpython-35m-x86_64-linux-gnu.so -I fastFM2
build/temp.linux-x86_64-3.5/fastFM/ffm2.o: In function `__pyx_pf_4ffm2_ffm2_predict':
/home/ben/src/fastFM/fastFM/ffm2.cpp:2562: undefined reference to `fastfm::Model::Model()'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2571: undefined reference to `fastfm::Data::Data()'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2580: undefined reference to `fastfm::Model::add_parameter(double*)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2600: undefined reference to `fastfm::Model::add_parameter(double*, int)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2610: undefined reference to `fastfm::Model::add_parameter(double*, int, int, int)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2630: undefined reference to `fastfm::Data::add_target(int, double*)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2650: undefined reference to `fastfm::Data::add_prediction(int, double*)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2708: undefined reference to `fastfm::Data::add_design_matrix(int, int, int, int*, int*, double*)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2717: undefined reference to `fastfm::predict(fastfm::Model*, fastfm::Data*)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2726: undefined reference to `fastfm::Model::~Model()'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2726: undefined reference to `operator delete(void*, unsigned long)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2735: undefined reference to `fastfm::Data::~Data()'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2735: undefined reference to `operator delete(void*, unsigned long)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2571: undefined reference to `operator delete(void*, unsigned long)'
/home/ben/src/fastFM/fastFM/ffm2.cpp:2562: undefined reference to `operator delete(void*, unsigned long)'
collect2: error: ld returned 1 exit status

For some reason I have a problem when linking and got this undefined references.

ibayer commented 7 years ago

Looks like cython doesn't find the fastFM2 header fastFM2/fastFM/fastfm.h or the library. Can you add fastFM2 as submodule (alongside fastFM-core). This way I can checkout your branch and get exactly the same setup as you have.

ibayer commented 7 years ago

I case you don't use it already, this can be quite handy: "Editable" Installs $ pip install -e path/to/SomeProject.

caos21 commented 7 years ago

Yes, yesterday I did some changes there. The problem is when linking fastFM: case 1: in setup.py

    Extension('ffm2', ['fastFM/ffm2.pyx'],
              libraries=['m', 'fastfm', 'fastFM'],
              library_dirs=['fastFM/', 'fastFM-core/bin/',
                            'fastFM2/_builds/fastFM'],
              include_dirs=['fastFM2/fastFM/',
                            numpy.get_include()],
              extra_compile_args=['-std=c++11'],
              extra_link_args=['-std=c++11'],
              language="c++")]

make clean && make in fastFM

gives the error:

/usr/bin/ld: fastFM2/_builds/fastFM/libfastFM.a(fastfm.cpp.o): relocation R_X86_64_32 against.rodata' can not be used when making a shared object; recompile with -fPIC`

case 2: So if I add to the CMakeLists.txt of fastFM2

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

make clean && make in fastFM, compile without errors but if I check for undefined references:


g++ -pthread -shared -L/home/ben/anaconda3/lib -Wl,-rpath=/home/ben/anaconda3/lib,--no-as-needed,-z,defs build/
temp.linux-x86_64-3.5/fastFM/ffm2.o -LfastFM/ -LfastFM-core/bin/ -LfastFM2/_dfpic/fastFM -L/home/ben/anaconda3/li
b -lm -lfastfm -lfastFM -lpython3.5m -o /home/ben/src/fastFM/ffm2.cpython-35m-x86_64-linux-gnu.so -std=c++11
fastFM2/_dfpic/fastFM/libfastFM.a(fastfm.cpp.o): In function `fastfm::Model::add_parameter(double*, int, int, int)':
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:48: undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int, google::CheckOpString const&)'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:48: undefined reference to `google::LogMessage::stream()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:48: undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:49: undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int, google::CheckOpString const&)'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:49: undefined reference to `google::LogMessage::stream()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:49: undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:59: undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:59: undefined reference to `google::LogMessage::stream()' ...

and


import ffm2

ImportError: /home/ben/src/fastFM/ffm2.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _ZN6google4base21CheckOpMessageBuilderD1Ev

fails.

case 3:


I tried adding the path for `glog`:

g++ -pthread -shared -L/home/ben/anaconda3/lib -Wl,-rpath=/home/ben/anaconda3/lib,--no-as-needed,-z,defs build/temp.linux-x86_64-3.5/fastFM/ffm2.o -LfastFM/ -LfastFM-core/bin/ -LfastFM2/_dfpic/fastFM -L/home/ben/anaconda3/lib -lm -lfastfm -lfastFM -lpython3.5m -o /home/ben/src/fastFM/ffm2.cpython-35m-x86_64-linux-gnu.so -std=c++11 -DGOOGLE_GLOG_DLL_DECL="" -I /home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/include/eigen -L ~/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/lib/ -lglog
/usr/bin/ld: /home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/lib//libglog.a(logging.cc.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/lib//libglog.a(raw_logging.cc.o): relocation R_X86_64_32S against symbol `_ZN6google16LogSeverityNamesE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/lib//libglog.a(utilities.cc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/lib//libglog.a(vlog_is_on.cc.o): relocationR_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/lib//libglog.a(symbolize.cc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/lib//libglog.a(demangle.cc.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

Again it fails.

ibayer commented 7 years ago

Not sure what going on

can not be used when making a shared object; recompile with -fPIC`

but make sure that you compile fastFM2 as static lib. The lib should run without installing any dependencies.

caos21 commented 7 years ago

I think it is done here CMakeLists.txt


target_link_libraries(IFM_proto
        fastFM
        gflags-static
        )
ibayer commented 7 years ago

I thinks that's only for gflaks.

make clean && make in fastFM

I'm not sure that is does what you want. I would recommend to use the build instructions from the README.

I can try to reproduce your errors tonight if you:

Can you add fastFM2 as submodule (alongside fastFM-core). This way I can checkout your branch and get exactly the same setup as you have.

caos21 commented 7 years ago

Not sure if I can add fastFM2 as a submodule, because is a private repo. I tried git submodule add git@github.com:/ibayer/fastFM2.git and no luck

ibayer commented 7 years ago

git submodule add git@github.com:ibayer/fastFM2.git

works for me, what error message do you get? (Can you try it with your private fork of fastFM2?)

ibayer commented 7 years ago

I have pushed the changes to a new branch https://github.com/ibayer/fastFM/tree/fastFM2 (and changed this PR to point against it). I hope it works if your rebase or merge the fastFM2 branch.

caos21 commented 7 years ago

Thanks, I got this error (when adding submodule)

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
ibayer commented 7 years ago

Does it work if you merge / rebase my fastFM2 branch (it already contains the additional submodule)?

caos21 commented 7 years ago

Sorry not sure about you want to and how to do it. I tried to checkout your branch fastFM2

git checkout -b fastFM2 origin/fastFM2
fatal: Cannot update paths and switch to branch 'fastFM2' at the same time.
Did you intend to checkout 'origin/fastFM2' which can not be resolved as commit?
ibayer commented 7 years ago

Oh well, then let's forget about the submodule business is not worth the effort. You can also just give me your last git hash.

ibayer commented 7 years ago

Do you get the same link error if you compile with cmake according to the README instructions?

caos21 commented 7 years ago

yes, I also change CMakeFileLists.txt in fastFM2 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -static")

No errors installing with pip but importing in python. If I check for undefined references I got a lot. Do you think that hunter need to compile dependencies with the flag -fPIC?

ibayer commented 7 years ago

I think the hunter setup should be okay but I'm not sure (I haven't done the setup and haven't looked in all the details).

I would probably try to isolate the problem with the following to steps (or something similar).

  1. Write a little C++ program and link against the fastFM2 lib in order to test if the lib is properly (statically) compiled.
  2. Write a simple C++ library fastFM2-mock and make sure that I can get Cython/fastFM to work with this lib.
  3. If 1 and 2 work, replace fastFM2-mock with fastFM2.
caos21 commented 7 years ago

Sounds good, the undefined references are for glog and eigen

ibayer commented 7 years ago

Did the linking in step 1. work?

caos21 commented 7 years ago

Diving into it today.

caos21 commented 7 years ago
  1. Yes
#include <iostream>
#include "../fastFM/fastfm.h"
#include "../fastFM/cd_impl.h"

using namespace std;

using namespace fastfm::cd::impl;

int main(int argc, char** argv) {

    cout << endl << "[ii] Little test" << endl;

    Vector y_true(4);
    y_true << 27.,  26.,  52.,  78.;

    Matrix w2_zero = Matrix::Zero(2, 3);
    Vector res(4);

    const int l = 2;    

    return 0;
}

Compiled with

g++ little.cpp -std=c++11 -lfastFM -LfastFM/ -I ../fastFM/

and it runs I will continue on this path...

ibayer commented 7 years ago

Can you change the test for step 1 to closer reflect the wrapping situation. Drop #include "../fastFM/cd_impl.h" and use something without Eigen like (code not tested):

static const int size = 4;
double* tmp_array = new double[size];
double tmp = 4;

Model* m = new Model();
m->add_parameter(&tmp);
m->add_parameter(tmp_array, size);

Data* d = new Data();
d->add_prediction(size, tmp_array);

del d;
del m;
del[] tmp_array

I don't expect it will change something, but better save then sorry ;-).

caos21 commented 7 years ago

It doesn't work. Same undefined references of glog and eigen.

caos21 commented 7 years ago

When I force static, I got some errors because in my system libunwind is not statically compiled,

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -static")

Now I am compiling libunwind from source to make it static.

ibayer commented 7 years ago

Okay good, lucks like we found already our main problem. The issue with libunwind as come up before, have a look at https://github.com/ibayer/fastFM2/issues/2 . Please keep me posted.

caos21 commented 7 years ago

thanks, yes we have this problem

.hunter/_Base/033a6ff/14d0f80/dce0303/Install/lib/libgmock_maind.a(gtest-all.cc.o): In function `testing::internal::StreamingListener::SocketWriter::MakeConnection()':
.hunter/_Base/033a6ff/14d0f80/dce0303/Build/GTest/Source/googletest/src/gtest.cc:3793: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Looking for a solution, or force dynamic in libunwind: -fPIC -static -static-libstdc++ -Wl,-Bdynamic -lunwind

caos21 commented 7 years ago

The latter doesn't work, got the same undefined references.

ibayer commented 7 years ago

@caos21 Can you post your little c++ prog that calls fastFM2 (incl. compile command)? @ruslo I'll see if I can get someone with a lot of hunter/cmake experience to help us out.

caos21 commented 7 years ago

Sure!


#include <iostream>
#include "../fastFM/fastfm.h"
#include "../fastFM/cd_impl.h"

using namespace std;

using namespace fastfm;

int main(int argc, char** argv) {

    cout << endl << "[ii] Little test" << endl;

    Vector y_true(4);
    y_true << 27.,  26.,  52.,  78.;

    Matrix w2_zero = Matrix::Zero(2, 3);
    Vector res(4);

    const int l = 2;    

    static const int size = 4;
    double* tmp_array = new double[size];
    double tmp = 4;

    Model* m = new Model();
    m->add_parameter(&tmp);
    m->add_parameter(tmp_array, size);

    Data* d = new Data();
    d->add_prediction(size, tmp_array);

    delete d;
    delete m;
    delete[] tmp_array;

    return 0;
}

I compiled with no success with:

g++ little.cpp -std=c++11 -lfastFM -LfastFM/ -I ../fastFM/

Got:

fastFM//libfastFM.a(fastfm.cpp.o): In function `fastfm::Model::add_parameter(double*, int, int, int)':
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:48: undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int, google::CheckOpString const&)'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:48: undefined reference to `google::LogMessage::stream()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:48: undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:49: undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int, google::CheckOpString const&)'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:49: undefined reference to `google::LogMessage::stream()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:49: undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:59: undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:59: undefined reference to `google::LogMessage::stream()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:59: undefined reference to `google::LogMessage::~LogMessage()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:48: undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:49: undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/home/ben/src/fastFM/fastFM2/fastFM/fastfm.cpp:59: undefined reference to `google::LogMessage::~LogMessage()'
fastFM//libfastFM.a(fastfm.cpp.o): In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*)':
/home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/include/glog/logging.h:686: undefined reference to `google::base::CheckOpMessageBuilder::CheckOpMessageBuilder(char const*)'
/home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/include/glog/logging.h:688: undefined reference to `google::base::CheckOpMessageBuilder::ForVar2()'
/home/ben/.hunter/_Base/033a6ff/14d0f80/dce0303/Install/include/glog/logging.h:689: undefined reference to `google::base::CheckOpMessageBuilder::NewString[abi:cxx11]()'
...

and more undefined references.

ibayer commented 7 years ago

Can you try again with the new static build added to fastFM2 (api) (see README for build instructions). https://github.com/ibayer/fastFM2/issues/2

caos21 commented 7 years ago

Sure! I'm setting an ubuntu 16.04 in virtualbox, before I was working in my main system Arch Linux which does not deliver libunwind static, and I needed to recompile, etc. I'll keep in touch.

caos21 commented 7 years ago

I followed the README.rst:

$ cmake -H. -B_builds -DCMAKE_BUILD_TYPE=Debug -DHUNTER_STATUS_DEBUG=ON

$ cmake --build _builds

$ ctest -VV -C Debug
...
100% tests passed, 0 tests failed out of 3
...

Then,

$ g++ little.cpp -std=c++11 -lfastFM -LfastFM -I ../fastFM/ 
In file included from ../fastFM/cd_impl.h:8:0,
                 from little.cpp:3:
../fastFM/fastfm_impl.h:8:23: fatal error: Eigen/Dense: No such file or directory
compilation terminated.

I can get rid of this error and make it work using:

$ g++ little.cpp -std=c++11   -I/home/ben/.hunter/_Base/033a6ff/14d0f80/e1266bb/Install/include/eigen3/ -rdynamic fastFM/libfastFM.a /home/ben/.hunter/_Base/033a6ff/14d0f80/e1266bb/Install/lib/libgtest_maind.a /home/ben/.hunter/_Base/033a6ff/14d0f80/e1266bb/Install/lib/libgmock_maind.a /home/ben/.hunter/_Base/033a6ff/14d0f80/e1266bb/Install/lib/libglogd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/e1266bb/Install/lib/libprotobufd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/e1266bb/Install/lib/libzd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/e1266bb/Install/lib/libgtestd.a -lpthread
$ ./a.out 

[ii] Little test

and

$ readelf -d fastFM/libfastFM.a | grep 'NEEDED'

$ readelf -d a.out | grep 'NEEDED' 
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

$ ldd a.out 
        linux-vdso.so.1 =>  (0x00007fffcc93f000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f39530ed000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f3952d65000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f3952b4d000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f395277d000)
        /lib64/ld-linux-x86-64.so.2 (0x0000557c407d7000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f395246d000)

$ ldd fastFM/libfastFM.a 
        not a dynamic executable
ibayer commented 7 years ago

I think you are missing these steps http://polly.readthedocs.io/en/latest/toolchains/gcc-musl.html#gcc-musl from the readme.

But lets' wait and see if ruslo manages to compile on 16.04 https://github.com/ibayer/fastFM2/issues/2 .

caos21 commented 7 years ago

Dont pay attention to the MUSL part, I forgot to build gcc-musl as you already pointed out

ruslo commented 7 years ago

But lets' wait and see if ruslo manages to compile on 16.04 ibayer/fastFM2#2

It's 17.04

ibayer commented 7 years ago

I guess I lost track :) but I got the same error on 16.04 for sure and it worked on 14.04.

caos21 commented 7 years ago

I compiled gcc-musl in ubuntu 16.04. Seems to work:

$ cmake -H. -Bbmusl -DCMAKE_BUILD_TYPE=Debug

$ cmake --build bmusl

test:

$ ctest -VV -C Debug
...
100% tests passed, 0 tests failed out of 3
...

Then compiled the little code,

$ /home/ben/opt/cross/x86_64-linux-musl/bin/x86_64-linux-musl-g++ -static  -std=c++11 little.cpp  -I/home/ben/.hunter/_Base/033a6ff/14d0f80/e1266bb/Install/include/eigen3/   -rdynamic fastFM/libfastFMd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libgtest_maind.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libgmock_maind.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libglogd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libprotobufd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libzd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libgtestd.a
$ ./a.out 

[ii] Little test

checking...

$ readelf -d fastFM/libfastFMd.a | grep 'NEEDED'

$ readelf -d a.out | grep 'NEEDED'

$ ldd fastFM/libfastFMd.a 
        not a dynamic executable

$ ldd a.out 
        not a dynamic executable
caos21 commented 7 years ago

I think that I must tell to cython to link against:

/home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libgtest_maind.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libgmock_maind.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libglogd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libprotobufd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libzd.a /home/ben/.hunter/_Base/033a6ff/14d0f80/71979ef/Install/lib/libgtestd.a

what do you think?

ibayer commented 7 years ago

I just finished a similar experiment in https://github.com/ibayer/fastFM2/issues/2 . I think telling cython to link against (glog)

-lglog -L/root/.hunter/_Base/033a6ff/14d0f80/2cdd8a5/Install/lib/ -I ../fastFM/ -pthread

should be sufficient.

caos21 commented 7 years ago

Thanks, the only problem I see is that we need to know a priori the location of hunter's libraries. /root/.hunter/_Base/033a6ff/14d0f80/2cdd8a5/Install/lib/ in your example, but different to me.

ibayer commented 7 years ago

Don't think that's an issue. Later we will probably separate the c++ (upload static libs somewhere) and cython build.