Reputation: 1674
Something quite weird is happening to me: CMake fails to choose the correct version of g++ only if I compile a project for the first time (or I delete 'build' folder).
So a 'fresh' compilation brings error when using auto
but if I compile it again, everything goes smoothly (until I delete 'build' folder).
Here you are my files:
CMakeLists.txt
file(GLOB_RECURSE SOURCES
include/*.h
src/*.cpp
)
SET(CMAKE_CXX_FLAGS "-std=c++14")
set(filename $ENV{env_filename})
cmake_minimum_required(VERSION 2.8)
project( filename )
add_executable( ${filename} ${filename}.cpp ${SOURCES})
compile.sh
#!/bin/bash
clear
set -e
source filedata.txt
export env_filename=$filename
mkdir -p build && cd build
cmake .. &> /dev/null
make -B
./$filename
filedata.txt
filename="1_Example"
Thanks in advance,
Eduardo
Upvotes: 0
Views: 169
Reputation: 3608
Can't really help you with the actual error, BUT...
Why do you use set -e? You shouldn't skip errors, you should fix them...
Your CMakeLists.txt is also incorrectly structured. You should at the very first lines have:
cmake_minimum_required(VERSION 2.8)
project( filename )
Otherwise it's considered incorrect. It might work but it shouldn't. Before running CMake commands you have to specify what version is required to run the file.
Your SOURCES entries should have double quotes around them.
UPDATE
Turns out putting cmake_minimum_requirement(VERSION 2.8) first fixed it for the OP. After that point not much is required structurally in CMake, you can use your common sense for the rest, but having the version requirement first is a must.
Upvotes: 1