1

I am trying to link a shared object on my executable with an executable in my cmake project.

my CMakeLists.txt

cmake_minimum_required (VERSION 2.8)
project (proto_app)

add_executable( helloDemo hello.cpp )
add_executable( faissDemo 1-Flat.cpp )

My executable faissDemo doesn't compile like this because the shared object is not linked. The shared object is located in /usr/local/lib/libfaiss.so. My question is how should I link to the shared object in CMake?

I can compile 1-Flat.cpp successfully from the command line like: $ g++ 1-Flat.cpp -L /usr/local/lib/ -lfaiss

Kevin
  • 16,549
  • 8
  • 60
  • 74
mkuse
  • 2,250
  • 4
  • 32
  • 61

1 Answers1

1

You need to add the dir to the link_directories and add the lib as target_link_libraries:

 cmake_minimum_required (VERSION 2.8)
 project (proto_app)

 link_directories(/usr/local/lib)     

 add_executable( helloDemo hello.cpp )
 add_executable( faissDemo 1-Flat.cpp )
 target_link_libraries(faissDemo faiss)
Kevin
  • 16,549
  • 8
  • 60
  • 74
user6556709
  • 1,272
  • 8
  • 13