When I use Cmake to compile the file, it shows /us

2019-03-06 18:35发布

问题:

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

回答1:

From the documentation for link_directories:

The command will apply only to targets created after it is called.

For make link_directories() call work you need to move it before add_executable().



标签: c++ gcc cmake