Hi all,
today I tryed to build my Project with cMake in Codelite and I got strange results of it- so I created a new minimal project to test the behavier of CMake cause I never used it.
# -*- CMakeLists.txt generated by CodeLite IDE. Do not edit by hand -*-
cmake_minimum_required(VERSION 2.8.11)
# Workspace name
project(test11)
# This setting is useful for providing JSON file used by CodeLite for code completion
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Set default locations
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CONFIGURATION_NAME "Debug")
# Projects
# Top project
# Define some variables
set(PROJECT_PATH "${CMAKE_SOURCE_DIR}/")
#{{{{ User Code 1
# Place your code here
#}}}}
include_directories(
.
.
)
# Compiler options
add_definitions(-g)
add_definitions(-O0)
add_definitions(-Wall)
# Linker options
# Library path
set(CMAKE_LDFLAGS "${CMAKE_LDFLAGS} -L. ")
# Define the CXX sources
set ( CXX_SRCS
${CMAKE_SOURCE_DIR}/main.cpp
${CMAKE_SOURCE_DIR}/test.cpp
)
set_source_files_properties(
${CXX_SRCS} PROPERTIES COMPILE_FLAGS
" -g -O0 -Wall")
#{{{{ User Code 2
# Place your code here
#}}}}
add_executable(test111 ${CXX_SRCS} ${C_SRCS})
target_link_libraries(test111 ${LINK_OPTIONS})
#{{{{ User Code 3
# Place your code here
#}}}}
Since you **define** the variable "int x;" in the header file "test.h" and then you include it **twice**
Once in test.cpp and later in main.cpp
This means that you have defined it twice (basically #include "test.h" is a compiler copy paste into the source file).
You need to define it once (in one of the .cpp files) and in the header file, add the "extern" keyword
Oops, how I forgot this one. I should have know this.
The compiler output confused me a bit cause if you are using cMake and get this error and then swich to default build system, this error is gone.
So thats why I thought cMake needs something to rebuild or something like that.
If I create a new Project and start with the default build system then I get the same error message.
It was not clear for me anyway when I should run cMake from within Codelite, sometimes I get build error messages, then I run cMake and everything is fine again.
As I understand it now (and this is coming from many different pages where you have put some pieces together and hope you get the right picture, even you dont know how it should look like)
Cmake creates a make file and codelite builds using this make file. So in this case I need to rerun Cmake everytime I create a new file for the project. If this is the way how it works, codelite could maybe mark this state of file and run cMake automaticly if that make sense. But as I said I dont know how exactly this build works.
I should stick with writing batsh files for the build where I write down every step the compiler and linker is doing.
Cmake creates a make file and codelite builds using this make file. So in this case I need to rerun Cmake everytime I create a new file for the project
Yes, this is how CMake works, you need to re-run cmake after adding new files
Fox Mulder wrote:codelite could maybe mark this state of file and run cMake automaticly if that make sense