我正在尝试使用现有的CMakeLists.txt文件创建一个C ++项目,但我在Netbeans C ++ IDE中遇到错误“正在运行make failed”。这是构建输出:
cd'/ home / hamani / NetBeansProjects / BNproject'
/ usr / bin / make -f Makefile
扫描目标bnproject的依赖关系
[33%]构建CXX对象CMakeFiles / bnproject.dir / main.cpp.o
[66%]构建CXX对象CMakeFiles / bnproject.dir / CMakeFiles / 3.5.1 / CompilerIdCXX / CMakeCXXCompilerId.cpp.o
[100%]链接CXX可执行文件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éfinitionsdultilesde«main»
CMakeFiles / bnproject.dir / main.cpp.o:/home/hamani/NetBeansProjects/BNproject/main.cpp:4:définipourlapremièrefoisici
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érenceindéfinievers«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érenceindéfinievers«gum :: debug :: __ inc_deletion(char const *,char const *,long ,char const *,void const *)collect2:错误:ld返回1退出状态
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
制作:*** [全部] Erreur 2
BUILD FAILED(退出值2,总时间:8s)
我在Ubuntu 16.04上使用名为 aGrUM (https://forge.lip6.fr/projects/aGrUM/wiki)的库,我在路径下安装了
〜/ USR
我在RELEASE模式下安装了aGrUM,而不是在DEBUG模式下
python act install release -d~ / usr
在预建行动中,Netbeans向我推荐了这些参数:
-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
所以我想我必须将-DCMAKE_BUILD_TYPE的值更改为“RELEASE”,以便与我的CMakeLists.txt兼容。
这是我的 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()
这是我的 main.cpp (例如: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;
}