我在新安装的Ubuntu上安装了Eclipse和CDT插件.索引设置为"快速索引"(建议使用"快速索引")("完全索引"似乎具有边际差异).
在很多地方,如果我按'F3'任何class名称或包含文件名按('show declaration'),光标将保持静止,并且不会导致声明.但是,它适用于标准的文件和符号像,stdio.h,std::vector等等.
例如,我有2个文件,
/home/myself/Workspace/Project/X/Y/include/file.h
/home/myself/Workspace/Project/X/src/file.cpp
Run Code Online (Sandbox Code Playgroud)
我无法看到任何class显示在file.cpp其中的任何或变量的声明file.h.即使按'F3'上#include"file.h",我不能去file.h.
在Workspace文件夹中创建Eclipse Workspace,在文件夹中创建C++项目Project.为了存储include路径,我在Eclipse中遵循了这个过程:
项目 - >属性 - > C/C++常规 - >路径和符号 - >库和路径 - >添加"/Project/X/Y/include/file.h"(使用'Workspace'和'FileSystem'选项卡)
但仍然没有运气.我已经在互联网和SO上做了足够的搜索,但找不到任何有用的东西.请注意,我使用eclipse仅用于代码浏览,而不是用于构建现在的代码.
当使用clang构建时,它似乎使用gcc4.4.4版本的包含文件,而我希望它使用更新的版本.
[ ~ ] locate move.h
/home/apps/gcc_versions/gcc-4_8_install/include/c++/4.8.3/bits/move.h
/usr/include/c++/4.4.4/bits/move.h
/usr/local/include/c++/4.7.1/bits/move.h
Run Code Online (Sandbox Code Playgroud)
gcc路径:
`gcc -print-prog-name=cc1plus` -v
ignoring nonexistent directory "/apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../include/c++/4.8.3
/apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../include/c++/4.8.3/x86_64-unknown-linux-gnu
/apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../include/c++/4.8.3/backward
/apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/include
/usr/local/include
/apps/gcc_versions/gcc-4_8_install/include
/apps/gcc_versions/gcc-4_8_install/lib/gcc/x86_64-unknown-linux-gnu/4.8.3/include-fixed
/usr/include
End of search list.
Run Code Online (Sandbox Code Playgroud)
gcc包括工作正常但是有了clang它失败了
[ ~ ] clang -v
clang version 3.5 (http://llvm.org/git/clang.git 8e674ff884113429b53d23b18409caf67aaec1b7) (http://llvm.org/git/llvm.git 7add5421a686877e0aa87616b92b1f5a85c6feee)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.4.4
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7
Selected GCC installation: …Run Code Online (Sandbox Code Playgroud) 我目前正在使用https://marketplace.visualstudio.com/items?itemName=mitaki28.vscode-clang,它非常适合访问成员函数.
但是我对我正在导入的项目有一个问题.虽然上面的clang功能有效,但我在使用include目录时遇到了特殊问题.我的项目结构如下:
|- src/
|- main.cpp
|- include/
|- MyHelper.h
|- CMakeLists.txt
Run Code Online (Sandbox Code Playgroud)
有没有办法在Visual Studio代码中配置我的包含目录,这样main.cpp我就可以:
#include "MyHelper.h"而不是#include "include/MyHelper.h"?
在编辑器中,它突出显示我的include语句,说它无法找到该文件.虽然编辑器不是一个大问题(我的项目编译),后续问题是vscode-clang插件不起作用,因为它没有看到该文件.
也许甚至让它在编辑器中使用我的CMakeLists.txt中的配置进行必要的包含?
谢谢!
这可能是一个非常简单的问题,但我无法弄明白,所以任何帮助都表示赞赏.
我有一个位于常规文件夹中的标题,因为我想在几个项目中使用它,例如:
C:\用户\ geninclude \程序\ header.h
我创建了一个新的空项目,主要是一个非常简单的主要项目
#include <program/header.h>
Run Code Online (Sandbox Code Playgroud)
然后我去了项目属性并在VC++中的include目录中添加了C:\ user\geninclude \
但是当我尝试构建程序时程序告诉我它找不到header.h,因为它不在当前目录或构建系统路径中.
我还尝试在C/C++的项目属性中添加C:\ user\geninclude \的附加包含目录,但仍然是同样的错误.
我知道这是一件很简单的事我想念,但我不知道是什么,我对这只是学习很新.
作为参考,我使用的是Visual Studio 2013.
预先感谢您的帮助.
更新:谢谢大家的回复,我已经尝试了你告诉我的一切(在两个实例中检查发布与调试,更改/为\和<>为"",并仔细检查标题,但系统仍未看到它真的很奇怪.我会继续努力......
所以我总是不得不使用项目的“附加包含目录”属性来设置我依赖于给定解决方案的其他(库)项目的相对路径。
所以解决方案结构本质上是:
我的 App.sln
-> 我的 App.vcxproj
-> 我的 Lib.vcxproj
我想要的是让我的应用程序项目自动将我的 Lib 项目文件的路径添加为它的“附加包含目录”中的条目,因为我的应用程序依赖于我的 Lib。
我通过在我的应用程序的“引用”下添加它来设置库/链接依赖项,这很好地意味着我的应用程序将自动链接到我的 Lib 的输出 .lib。完美的!
但是......我不知道如何从 My Lib 中获取 .h 文件以包含到我的应用程序中,而无需手动指定其路径(或相对路径)到我的应用程序项目的“附加包含目录”属性。
我已经忍受了很多年,但我不得不解决依赖依赖的链接问题,并找到了一种非常巧妙的方法来做到这一点,而无需接触项目设置。
这让我想到 - 当然有一种方法可以为“项目 A 依赖于项目 B,因此应该自动搜索项目 B 以获取 #include 引用”
我是一厢情愿的想法吗?还是我在 VS 中缺少一些很棒的功能?
我目前正在开发一个PHP Web应用程序,我想知道包含文件(include_once)的最佳方式是什么,它仍然是可维护的代码.通过maintanable我的意思是,如果我想移动一个文件,重构我的应用程序以使其正常工作是很容易的.
我有很多文件,因为我尝试了很好的OOP实践(一个类=一个文件).
这是我的应用程序的典型类结构:
namespace Controls
{
use Drawing\Color;
include_once '/../Control.php';
class GridView extends Control
{
public $evenRowColor;
public $oddRowColor;
public function __construct()
{
}
public function draw()
{
}
protected function generateStyle()
{
}
private function drawColumns()
{
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的命令:
/usr/bin/c++ -fPIC -I/Users/me/project/include -I/usr/local/include/opencv \
-I/usr/local/include -I/opt/local/include -std=c++11 -O3 -M -c \
/Users/me/project/src/program.cpp | grep opencv
Run Code Online (Sandbox Code Playgroud)
program.cpp有:
#include "opencv2/core/core.hpp"
#include "opencv2/ml/ml.hpp"
Run Code Online (Sandbox Code Playgroud)
输出:
/opt/local/include/opencv2/core/core.hpp \
/opt/local/include/opencv2/core/types_c.h /usr/include/assert.h \
/usr/include/math.h /opt/local/include/opencv2/core/version.hpp \
/opt/local/include/opencv2/core/operations.hpp \
/opt/local/include/opencv2/core/mat.hpp \
/opt/local/include/opencv2/objdetect/objdetect.hpp \
/opt/local/include/opencv2/ml/ml.hpp \
Run Code Online (Sandbox Code Playgroud)
然而,存在:/usr/local/include/opencv2/core/core.hpp、 和/usr/local/include/opencv2/ml/ml.hpp。
使用该-v标志, clang 告诉我:
ignoring duplicate directory "/usr/local/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
/Users/me/project/include
/usr/local/include/opencv
/opt/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1 …Run Code Online (Sandbox Code Playgroud) 使用嵌入式 C 项目。有库,包含文件等 - 用于微控制器。我不需要为主机和操作系统(Linux Mint 64 位)使用 GCC。按照惯例...
但是现在我正在尝试从 Github编译mspdebug项目——当然是使用 GCC。我在 make 一开始就收到一个错误:
mspdebug$ make
cc -DUSE_READLINE -O1 -Wall -Wno-char-subscripts -ggdb -I. -Isimio -Iformats -Itransport -Idrivers -Iutil -Iui -DLIB_DIR=\"/usr/local/lib/\" -o util/btree.o -c util/btree.c
util/btree.c:19:20: fatal error: assert.h: No such file or directory
#include <assert.h>
^
compilation terminated.
Run Code Online (Sandbox Code Playgroud)
我在所有可能的路径中搜索包含(我通过 gcc -v 命令获得了它们的列表) - 没有 assert.h 文件,以及 stdio.h 等等。除了虚拟框目录只有一个地方(GCC 不搜索包含的地方):/usr/lib/syslinux/com32/include
AFAIK,所有标准库和包含都与 GCC 一起安装。所以我尝试重新安装 GCC (4.8.4) - 没有任何变化。
为 GCC 提供所需的所有标准环境的正常方法是什么?
假设我有一个目录结构如下的项目:
myproject
??? .git [...]
??? CMakeLists.txt
??? src
??? CMakeLists.txt
??? foo.cc
??? foo.h
Run Code Online (Sandbox Code Playgroud)
如果在src/foo.cc我包含头文件#include "foo.h",然后在其上运行 Google 的cpplint.py,它会抱怨
src/foo.cc:8: Include the directory when naming .h files [build/include] [4]
Run Code Online (Sandbox Code Playgroud)
所以我把它作为#include "./foo.h". 现在我收到另一个投诉:
src/foo.cc:8: src/foo.cc should include its header file src/foo.h [build/include] [5]
Run Code Online (Sandbox Code Playgroud)
但是,如果我将它包含为#include "src/foo.h",编译器将找不到它,因为我当前的 CMake 设置。这是我的两个 CMakeLists.txt 文件的样子:
CMakeLists.txt:
project(myproject)
add_subdirectory(src)
Run Code Online (Sandbox Code Playgroud)
源代码/CMakeLists.txt:
set(SRCS foo.cc)
add_executable(foo ${SRCS})
Run Code Online (Sandbox Code Playgroud)
我使用 CMake 的方式在某种程度上从根本上是错误的吗?我应该src/CMakeLists.txt完全删除文件,并使用CMakeLists.txt完整路径指定基础中的所有源文件吗?
或者我应该简单地忽略 cpplint 的抱怨,因为它们并不真正适合 CMake 项目的设置方式?
在C 预处理器版本 10.0.1的第 8 页中,我们有以下声明:
\n\n\n\n\n\n\n
#include "file"此变体用于您自己的程序的头文件。
\nfile它首先在包含当前文件的目录中搜索名为的文件,然后在引用目录中搜索,然后在用于<file>. 您可以使用该选项将目录添加到\n 引用目录列表中\xe2\x80\x98-iquote\xe2\x80\x99。
“然后在报价目录中”是什么意思?
\n