0

here is my code of cmake :

PROJECT (HELLO)
SET(SRC ./main.c)
MESSAGE(STATUS "This is BINARY dir "${HELLO_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir"${HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello SRC)

if I run, what appears in front of me is that:

-- Configuring done
CMake Error at CMakeLists.txt:5 (ADD_EXECUTABLE):
  Cannot find source file:

    SRC

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx


CMake Error: CMake can not determine linker language for target: hello
CMake Error: Cannot determine link language for target "hello".
-- Generating done

if I change my code to

PROJECT (HELLO)
SET(SRC ./main.c)
MESSAGE(STATUS "This is BINARY dir "${HELLO_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir"${HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello ./main.c)

it just works well. So, what happens to SET? why didn't it work well?

John Zhang
  • 23
  • 3

1 Answers1

0

You need to use:

ADD_EXECUTABLE(hello ${SRC})

Otherwise, cmake just thinks you have a source file named "SRC" leading to that error you see.

dwosk
  • 1,202
  • 8
  • 11