0

When I compile my c++ program using manually written makefile, I use the following command:

LNK_FLAG      = -L $(LIB_PATH) -lnameofmylib
RPATH_FLAG    = -Wl,-rpath,$(LIB_PATH)

and I use make LIB_PATH=/path/to/my/lib to build my program.

Now I want to use cmake to build my program, so, I wonder if there are some mechanisms to do that? or do I have to use set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L ${LIB_PATH} -lnameofmylib -Wl,-rpath,${LIB_PATH}")?

Alaya
  • 3,287
  • 4
  • 27
  • 39
  • 1
    Too many questions in one post: `-L` and `-l` options are described in @Joel answer, setting `LIB_PATH` for use in makefile may be replaced with `set(LIB_PATH <...> CACHE ...)` in CMake, RPATH handling in CMake is described in [Wiki](https://cmake.org/Wiki/CMake_RPATH_handling). – Tsyvarev Mar 21 '16 at 07:08
  • https://www.google.com/search?q=cmake+rpath and https://www.google.com/search?q=cmake+linking+library – Antonio Mar 21 '16 at 11:13
  • 1
    Possible duplicate of [CMake link to external library](http://stackoverflow.com/questions/8774593/cmake-link-to-external-library) – Antonio Mar 21 '16 at 11:14

1 Answers1

1

If you want to add a library search path, use link_directories. For linking a library, use link_libraries. This can be portable on any OS or compiler/linker, or less your are using compiler dependend features.

Joel
  • 1,805
  • 1
  • 22
  • 22