Basic Cmake and make on Mac OS Maverick for C

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?

Answers


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
)

Need Your Help

GWT/Spring/Hibernate data change events and transactions

hibernate spring events gwt transactions

I'm working on an AJAX application using GWT, Spring and Hibernate. I'm keeping some configuration data on the client side, which is almost never changed, but when it is changed, I have to notify all

PHP/MySQL Need to merge data from two tables to one object and sort them by date

php mysql sql sorting merge

I have two tables in my DB. One for one kind of items, second for another kind of items (some columns are same, some are different, first table contains 23 columns, second one contains 24 columns)....