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

2019-03-06 18:23发布

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

标签: c++ gcc cmake
1条回答
女痞
2楼-- · 2019-03-06 19:10

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().

查看更多
登录 后发表回答