提问人:Shuto 提问时间:10/31/2023 最后编辑:TsyvarevShuto 更新时间:10/31/2023 访问量:80
我们如何传递包含路径?
How do we pass the include Path?
问:
我创建了一个“build”目录并运行ViennaTS软件。它起作用了,但是当我运行时,我遇到了以下错误。cmake ..
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
在这种情况下,我应该修改还是应该修改 includePath ?我不知所措,所以如果你知道更多,请帮助我。
代码的 include 部分如下所示。#include "sprng/sprng.h"
${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.txt
如下所示:
# 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} )
cmake ..
生成了以下 Makefile。
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.22
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Disable VCS-based implicit rules.
% : %,v
# Disable VCS-based implicit rules.
% : RCS/%
# Disable VCS-based implicit rules.
% : RCS/%,v
# Disable VCS-based implicit rules.
% : SCCS/s.%
# Disable VCS-based implicit rules.
% : s.%
.SUFFIXES: .hpux_make_needs_suffix_list
# Command-line flag to silence nested $(MAKE).
$(VERBOSE)MAKESILENT = -s
#Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E rm -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/ishitanaken23/ViennaTS
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/ishitanaken23/ViennaTS/build
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
/usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/ishitanaken23/ViennaTS/build/CMakeFiles /home/ishitanaken23/ViennaTS/build//CMakeFiles/progress.marks
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /home/ishitanaken23/ViennaTS/build/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
#=============================================================================
# Target rules for targets named MAKE_HEADERS_VISIBLE
# Build rule for target.
MAKE_HEADERS_VISIBLE: cmake_check_build_system
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 MAKE_HEADERS_VISIBLE
.PHONY : MAKE_HEADERS_VISIBLE
# fast build rule for target.
MAKE_HEADERS_VISIBLE/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/MAKE_HEADERS_VISIBLE.dir/build.make CMakeFiles/MAKE_HEADERS_VISIBLE.dir/build
.PHONY : MAKE_HEADERS_VISIBLE/fast
#=============================================================================
# Target rules for targets named viennats
# Build rule for target.
viennats: cmake_check_build_system
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 viennats
.PHONY : viennats
# fast build rule for target.
viennats/fast:
$(MAKE) $(MAKESILENT) -f src/CMakeFiles/viennats.dir/build.make src/CMakeFiles/viennats.dir/build
.PHONY : viennats/fast
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... MAKE_HEADERS_VISIBLE"
@echo "... viennats"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system
答:
1赞
kote
10/31/2023
#1
首先,您使用的是什么编辑器/环境?这有时会有所作为。
切勿修改 includes 指令。如果应该如此,那么它需要保持如此。一旦文件中包含其他文件,尝试修改该指令将立即失败。"sprng/sprng.h"
"sprng/sprng.h"
您需要发布您的或您的 .CMakeList.txt
Makefile
但只是提前考虑:如果你正在使用 makefile 并进行编译,那么你可以附加到 build 命令中。例如: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(...)
Makefile
评论
0赞
Shuto
10/31/2023
我正在使用 WSL2 的 Ubuntu。
0赞
kote
10/31/2023
${SPRNG_INCLUDE_DIR} 曾经定义过吗?
0赞
Shuto
10/31/2023
CMakeList.txt 和 Makefile 在网站上方。
评论
c_cpp_properties.json
CMakeLists.txt
SPRNG_INCLUDE_DIR="/home/Username/sprng/include"