facebook / CacheLib

Pluggable in-process caching engine to build and scale high performance services
https://www.cachelib.org
Apache License 2.0
1.21k stars 262 forks source link

gold linker cannot link to folly #23

Closed tangliisu closed 3 years ago

tangliisu commented 3 years ago

I tried to compile cachelib in an internal repo. I met a problem when Linking CXX executable cachebench-util (the last step lol). The error msg is /usr/bin/ld.gold: error: cannot find -lfolly. It seems the linker gold cannot link to folly. I enable the cmake verbose. Here is the output

[ 99%] Linking CXX executable cachebench-util
cd /opt/cachelib/cachelib/build/cachebench && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cachebench-util.dir/link.txt --verbose=1
/usr/bin/c++     CMakeFiles/cachebench-util.dir/util/main.cpp.o  -o cachebench-util -Wl,-rpath,"\$ORIGIN/../lib/cachelib/" libcachelib_cachebench.a ../datatype/libcachelib_datatype.a ../allocator/libcachelib_allocator.a ../navy/libcachelib_navy.a ../shm/libcachelib_shm.a ../common/libcachelib_common.a /usr/local/lib/libthriftcpp2.so /usr/local/lib/libthriftfrozen2.so /usr/local/lib/libReactiveSocket.so /usr/local/lib/libyarpl.so /usr/local/lib/libglog.so -fuse-ld=gold /usr/local/lib/libthriftprotocol.so /usr/local/lib/libthrift.so /usr/local/lib/libasync.so /usr/local/lib/libprotocol.so /usr/local/lib/libtransport.so /usr/local/lib/libconcurrency.so /usr/local/lib/libthrift-core.so /usr/local/lib/libfmt.so.7.1.4 -Wl,--as-needed /usr/local/lib/libwangle.so.1.0.0 /usr/local/lib/libfizz.so.1.0.0 /usr/lib/x86_64-linux-gnu/librt.so -lfolly /usr/local/lib/libfolly_exception_counter.so /usr/local/lib/libfolly_exception_tracer.so /usr/local/lib/libfolly_exception_tracer_base.so /usr/local/lib/libfolly.so /usr/local/lib/libglog.so /usr/lib/x86_64-linux-gnu/libgflags.so.2.2.1 /usr/lib/x86_64-linux-gnu/libboost_system.so /usr/lib/x86_64-linux-gnu/libboost_thread.so /usr/lib/x86_64-linux-gnu/libboost_filesystem.so /usr/lib/x86_64-linux-gnu/libboost_regex.so /usr/lib/x86_64-linux-gnu/libboost_context.so /usr/lib/x86_64-linux-gnu/libboost_date_time.so /usr/lib/x86_64-linux-gnu/libboost_program_options.so /usr/lib/x86_64-linux-gnu/libboost_chrono.so /usr/lib/x86_64-linux-gnu/libboost_atomic.so /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/x86_64-linux-gnu/libcrypto.so /usr/lib/x86_64-linux-gnu/libevent.so /usr/lib/x86_64-linux-gnu/libdouble-conversion.so -pthread /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/liblzma.so /usr/lib/x86_64-linux-gnu/liblz4.so /usr/local/lib/libzstd.so /usr/lib/x86_64-linux-gnu/libsnappy.so /usr/lib/x86_64-linux-gnu/libdwarf.so /usr/lib/x86_64-linux-gnu/libiberty.a -ldl /usr/lib/x86_64-linux-gnu/libsodium.so /usr/lib/x86_64-linux-gnu/libunwind.so /usr/lib/x86_64-linux-gnu/libgflags.so.2.2.1 -lpthread 
/usr/bin/ld.gold: error: cannot find -lfolly
collect2: error: ld returned 1 exit status
cachebench/CMakeFiles/cachebench-util.dir/build.make:134: recipe for target 'cachebench/cachebench-util' failed

I can find /usr/local/lib/libfolly.so. And i have already tried to make some changes in cachebench/CMakelist.txt (the lines i comment)

In cachelib/cachebench/CMakeList.txt
add_executable (cachebench main.cpp)
target_link_libraries(cachebench
  cachelib_cachebench
  #folly
  #/usr/local/lib/libfolly.so
)
add_executable (cachebench-util util/main.cpp)
target_link_libraries(cachebench-util
  cachelib_cachebench
  #folly
  #/usr/local/lib/libfolly.so
)
tangliisu commented 3 years ago

We are trying to compile the cachelib in an internal repo. This repo already has a folly with old version https://github.com/facebook/folly/commit/60be5ec6d5b85c89cadd6ff9a986fa59e88b714d Unfortunately we cannot upgrade the folly version to the lastest since it might affect our other service in the repo. I tried to patch folly and cachelib to make cachelib compilable in an old version of folly/fbthrift. I am not sure this error is related to folly version.

sathyaphoenix commented 3 years ago

@tangliisu Are you intending to build cachebench or simply the cachelib code to hook inside your application ?

tangliisu commented 3 years ago

i am intending to build cachebench. I have resolved this issue by linking ln -s /usr/local/lib/libfolly.so /usr/lib/libfolly.so thank you

sathyaphoenix commented 3 years ago

Thanks for confirming. IIUC, you intend to build cachelib with an older version of folly and got that to working by symlinking the older version directly, overriding the build setup that ships with cachelib and got it to work ?

tangliisu commented 3 years ago

yes that is correct.