1

I'm a complete beginner in using Cmake to compile my own C code and I'm running Mac OS X Mavericks.

My problem is as follow. For my intro to Cmake, created a folder containing the following folders

bin/
build/
src/
   fonctions.h
   fonctions.c
   main.c

Here my CMakeLists.txt file:

project(Addition)
add_executable(
    bin/addition
    src/main.c
    src/fonctions.h
    src/fonctions.c
)

When I run:

$ cmake . -G "Unix Makefiles"

and then make from my root folder, no problem.

But when I run:

$ cmake .. -G "Unix Makefiles"

and then make from my /build folder I got this error message:

Linking C executable bin/addition
ld: can't open output file for writing: bin/addition, errno=2 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/addition] Error 1
make[1]: *** [CMakeFiles/bin/addition.dir/all] Error 2
make: *** [all] Error 2

Anyone knows why?

Don Cruickshank
  • 5,641
  • 6
  • 48
  • 48
Frederic
  • 13
  • 2

1 Answers1

0

Remove bin/ from your add_executable and use CMAKE_RUNTIME_OUTPUT_DIRECTORY to change your build location

add_executable(
    addition
    src/main.c
    src/fonctions.h
    src/fonctions.c
)
Community
  • 1
  • 1
Peter Petrik
  • 9,701
  • 5
  • 41
  • 65