我们如何传递包含路径?

问题描述 投票:0回答:1

我创建了一个“build”目录并运行

cmake ..
来运行 ViennaTS 软件。它有效,但是当我运行
make
时,我收到以下错误。

Username@DESKTOP-DMU7A5N:~/ViennaTS/build$ make
[ 50%] Building CXX object src/CMakeFiles/viennats.dir/viennats.cpp.o
In file included from /home/Username/ViennaTS/src/viennats.cpp:61:
/home/Username/ViennaTS/viennats/Parameters.h:35:10: fatal error: sprng/sprng.h: No such file or directory
   35 | #include "sprng/sprng.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [src/CMakeFiles/viennats.dir/build.make:76: src/CMakeFiles/viennats.dir/viennats.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:125: src/CMakeFiles/viennats.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

我了解到sprng目录中的文件sprng.h丢失了,但是SPRNG目录中不存在文件sprng/sprng.h。文件 sprng.h 存在于以下路径中。

/home/Username/sprng/SRC
/home/Username/sprng/include

这种情况下,我应该修改

#include "sprng/sprng.h"
还是应该修改includePath
${workspaceFolder}/**
?我很茫然,如果你知道更多,请帮助我。
Parameters.h
中的包含部分代码如下。

#ifndef DEF_PARAMETERS
#define DEF_PARAMETERS

/* =========================================================================
   Copyright (c)    2008-2015, Institute for Microelectronics, TU Wien.
                            -----------------
                 ViennaTS - The Vienna Topography Simulator
                            -----------------
   Contact:         [email protected]
   License:         MIT (X11), see file LICENSE in the base directory
============================================================================= */


#include <string>
#include <map>
#include <fstream>
#include <algorithm>

#include <boost/spirit/include/classic.hpp>
#include <boost/spirit/include/classic_clear_actor.hpp>
#include <boost/spirit/include/classic_push_back_actor.hpp>
#include <boost/spirit/include/classic_increment_actor.hpp>
#include <boost/spirit/include/classic_decrement_actor.hpp>
#include <boost/spirit/include/classic_assign_actor.hpp>
#include <boost/spirit/include/classic_if.hpp>

#include "Partition/Partition.h"

#include "boundaries.h"

#include "message.h"

#include "parser_actors.h"

#include "sprng/sprng.h"

#define BOOST_SPIRIT_DEBUG

“CMakeList”如下。

# Required CMake Version
###############
 cmake_minimum_required(VERSION 2.8)
#cmake_minimum_required(VERSION 3.1.0)

# Project setup
###############
PROJECT(ViennaLS)

set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})

# Default build type
##############
IF (NOT CMAKE_BUILD_TYPE)
  SET(CMAKE_BUILD_TYPE "Release")
ENDIF()

# Default compile options
#################
SET(CMAKE_CXX_FLAGS "-Wall -pedantic")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 ")
SET(CMAKE_CXX_FLAGS_DEBUG  "-O0 -g")


# Specify general include directory
################
INCLUDE_DIRECTORIES(".")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/viennats/)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/viennats/LSlib/)

# Specify that the output executable is placed in the root build directory
################
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})


# Find prerequisites
####################

# Look for additiona CMake modules in the cmake subdirectory ..
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

# OpenMP ..
FIND_PACKAGE(OpenMP REQUIRED)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")

# Boost ..
SET(BOOST_MIN_VERSION 1.46.0)
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})

# SPRNG ..
FIND_PACKAGE(SPRNG REQUIRED)
INCLUDE_DIRECTORIES(${SPRNG_INCLUDE_DIR})
SET(LIBRARIES ${LIBRARIES} ${SPRNG_LIBRARY})

# HDF5
FIND_PACKAGE(HDF5 COMPONENTS CXX)
IF(HDF5_FOUND)
  IF(HDF5_hdf5_cpp_LIBRARY)
    add_definitions(-DUSE_HDF5)
    add_definitions(${HDF5_DEFINITIONS})
    INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIRS})
    SET(LIBRARIES ${LIBRARIES} ${HDF5_LIBRARIES})
  ELSE(HDF5_hdf5_cpp_LIBRARY)
    message(FATAL_ERROR "Missing HDF5 C++ library")
  ENDIF(HDF5_hdf5_cpp_LIBRARY)
ELSE(HDF5_FOUND)
  message(STATUS "Missing HDF5 library: ViennaTS will be built without TDR file support")
ENDIF(HDF5_FOUND)

# Subdirectories
################
add_subdirectory(src)

# Add visibility of headers
# Necessary for Qt-Creator usage.
################
file( GLOB_RECURSE MAKE_HEADERS_VISIBLE_SRC *.hpp *.h)
add_custom_target( MAKE_HEADERS_VISIBLE SOURCES ${MAKE_HEADERS_VISIBLE_SRC} )

c++ linux include fatal-error cannot-find-symbol
1个回答
0
投票

首先,您使用什么编辑器/环境?这有时会产生影响。

切勿修改包含指令。如果它应该是

"sprng/sprng.h"
那么它需要保持这样。一旦文件中包含其他文件,尝试修改指令将立即失败
"sprng/sprng.h"

您需要发布您的

CMakeList.txt
或您的
Makefile

但请提前思考:如果您正在使用 makefile 并使用

gcc
进行编译,那么您可以将
-I/home/Username/sprng/SRC -I/home/Username/sprng/SRC
附加到构建命令中。例如:

file.o : file.cpp
    g++ ... -I/home/Username/sprng/SRC -I/home/Username/sprng/SRC

编辑: 为什么您对

INCLUDE_DIRECTORIES(...)
的调用不包括上面列出的两个目录?

© www.soinside.com 2019 - 2024. All rights reserved.