I'm trying to create a C++ project with an existing CMakeLists.txt file, but I have an error "Running make failed" in Netbeans C++ IDE. Here is the Build Output :
cd '/home/hamani/NetBeansProjects/BNproject'
/usr/bin/make -f Makefile
Scanning dependencies of target bnproject
[ 33%] Building CXX object CMakeFiles/bnproject.dir/main.cpp.o
[ 66%] Building CXX object CMakeFiles/bnproject.dir/CMakeFiles/3.5.1/CompilerIdCXX/CMakeCXXCompilerId.cpp.o
[100%] Linking CXX executable bnproject
CMakeFiles/bnproject.dir/CMakeFiles/3.5.1/CompilerIdCXX/CMakeCXXCompilerId.cpp.o: dans la fonction « main »:
/home/hamani/NetBeansProjects/BNproject/CMakeFiles/3.5.1/CompilerIdCXX/CMakeCXXCompilerId.cpp:514: définitions multiples de « main »
CMakeFiles/bnproject.dir/main.cpp.o:/home/hamani/NetBeansProjects/BNproject/main.cpp:4: défini pour la première fois ici
CMakeFiles/bnproject.dir/main.cpp.o: dans la fonction « gum::HashTable, std::allocator >, int, std::allocator, std::allocator >, int> > > ::HashTable(unsigned long, bool, bool) »: /home/hamani/usr/include/agrum/core/hashTable.tcc:1573: référence indéfinie vers « gum::debug::__inc_creation(char const*, char const*, long, char const*, void const*, int) »
CMakeFiles/bnproject.dir/main.cpp.o: dans la fonction « gum::HashTable, std::allocator >, int, std::allocator, std::allocator >, int> > >::~HashTable() »:
/home/hamani/usr/include/agrum/core/hashTable.tcc:1675: référence indéfinie vers « gum::debug::__inc_deletion(char const*, char const*, long, char const*, void const*)
collect2: error: ld returned 1 exit status
CMakeFiles/bnproject.dir/build.make:120 : la recette pour la cible « bnproject » a échouée
make[2]: *** [bnproject] Erreur 1
CMakeFiles/Makefile2:67 : la recette pour la cible « CMakeFiles/bnproject.dir/all » a échouée
make[1]: ***[CMakeFiles/bnproject.dir/all] Erreur 2
Makefile:83 : la recette pour la cible « all » a échouée
make: *** [all] Erreur 2
BUILD FAILED (exit value 2, total time: 8s)
I'm using a library called aGrUM (https://forge.lip6.fr/projects/aGrUM/wiki) on Ubuntu 16.04, I installed it under the path
~/usr
I installed aGrUM in RELEASE mode, not in DEBUG mode
python act install release -d ~/usr
In Pre-Build Action, Netbeans suggests me these arguments :
-G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=${IDE_CC} -DCMAKE_CXX_COMPILER=${IDE_CXX} -DCMAKE_C_FLAGS_DEBUG="-g3 -gdwarf-2" -DCMAKE_CXX_FLAGS_DEBUG="-g3 -gdwarf-2" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
so I think I have to change the value of -DCMAKE_BUILD_TYPE to "RELEASE", to be compatible with my CMakeLists.txt.
Here is my CMakeLists.txt :
project(BNPROJECT)
cmake_minimum_required(VERSION 2.8)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11")
# do not forget to change this line if needed ("act install -d...")
#set(AGRUM_INSTALLATION_DIRECTORY "installation_path")
set(AGRUM_INSTALLATION_DIRECTORY "~/usr")
set(aGrUM_DIR "${AGRUM_INSTALLATION_DIRECTORY}/lib/cmake/aGrUM/")
find_package(aGrUM)
if (aGrUM_FOUND)
include_directories(${AGRUM_INCLUDE_DIR})
link_directories(${AGRUM_LIB_DIR})
else (aGrUM_FOUND)
message(FATAL_ERROR "Please install aGrUM")
endif (aGrUM_FOUND)
# cmake -DCMAKE_BUILD_TYPE=DEBUG
# or
# cmake -DCMAKE_BUILD_TYPE=RELEASE
# RELEASE is the default option (thanks to the next 3 lines)
if( NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE Release)
endif()
file(GLOB_RECURSE BNPROJECT_SOURCE ${BNPROJECT_SOURCE_DIR}/*.cpp)
file(GLOB_RECURSE BNPROJECT_INCLUDE ${BNPROJECT_SOURCE_DIR}/*.h)
add_executable (bnproject ${BNPROJECT_SOURCE})
if ($CMAKE_BUILD_TYPE STREQUAL "RELEASE") # release : act install release
target_link_libraries(bnproject agrum)
else() # debug : act install debug
#target_link_libraries(bnproject agrum-dbg)
target_link_libraries(bnproject agrum)
endif()
and here is my main.cpp (example here : http://www-desir.lip6.fr/~phw/aGrUM/officiel/doxygen/db/db6/using_agrum.html) :
#include <iostream>
#include <agrum/core/hashTable.h>
int main(void) {
gum::HashTable<std::string,int> h;
h.insert("Hello",1);
h.insert("World",2);
std::cout<<h<<std::endl;
}