This is the CMakeList.txt in src directory:
ADD_EXECUTABLE(Expression ExpressionValue.cpp) INCLUDE_DIRECTORIES(/root/fengwu/codes/headfiles/expression/include) LINK_DIRECTORIES(/root/fengwu/codes/headfiles/expression/lib) TARGET_LINK_LIBRARIES(Expression test)
When I enter cmake ..
in build directory, it is ok. After that I enter make
, it shows /usr/bin/ld: cannot find -ltest
. However when I use g++, it is ok.
g++ ExpressionValue.cpp -I/root/fengwu/codes/headfiles/expression/include -L/root/fengwu/codes/headfiles/expression/lib -ltest -o expr.out
From the documentation for link_directories:
For make
link_directories()
call work you need to move it beforeadd_executable()
.