当包含的文件本身包含另一个文件但是用点前缀引用它时,我遇到了包含问题.例如,有三个文件 - inc1.php,inc2.php和subdir/test.php,其内容是 -
子目录/ test.php的:
set_include_path(get_include_path().":../:../.");
require("inc1.php");
Run Code Online (Sandbox Code Playgroud)
inc1.php:
require("./inc2.php");
Run Code Online (Sandbox Code Playgroud)
inc2.php
echo "OK";
Run Code Online (Sandbox Code Playgroud)
这包括此处显示的树因无法打开的流而失败:没有此类文件或目录错误.如果inc1.php包含一个简单的require("inc2.php"),它就可以工作.,没有"./"前缀.我添加了"../." 将include路径作为尝试使其工作,但这没有任何效果.
除了使用"./"前缀执行include之外,这里有什么解决方案,假设inc1.php和inc2.php不可写,你只能改变subdir/test.php?你怎么能在test.php中包含inc1.php?
作为参考,我使用的是PHP 5.2.9.
在我的PHP框架中,我想使用另一个PHP框架的几个函数.其他框架只有一个门户脚本(index.php).它从那里做所有事情(引导程序,呼叫控制器和动作等).另一个框架包括以./开头的所有文件
另一个框架的index.php:
include './inc/bootstrap.php';
Run Code Online (Sandbox Code Playgroud)
在bootstrap.php中:
include './inc/configs.php';
include './inc/database.php';
Run Code Online (Sandbox Code Playgroud)
等等
因此看起来所有包含都与index.php所在的文件夹相关.
有没有办法设置环境,所以我可以从另一个文件夹(我的框架中的某个地方,所以一个完全不同的文件夹,而不是门户网站脚本)引导框架?
include_path包括.和我已经尝试了include_path中的其他框架的文件夹,但没有改变任何东西.
我猜它是./包含,但我不能改变它们(另一个框架不是我的框架的一部分,并将在一段时间内更新).有没有办法围绕他们(或者我做错了)?
我已经设置了apache,以便所有请求都转到文件/var/www/common_index.php
现在,common_index.php查看请求的文件名和来源相应的文件/var/www/123/public_html/requested_file.php
当我在requested_file.php中包含一个文件(具有相对路径)时,我遇到了问题.它试图在/ var/www而不是/ var/www/123/public_html /中搜索文件
怎么解决这个?
我正在使用Linux 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 GNU/Linux,我需要#include<linux/getcpu.h>。编译器抱怨找不到文件。Linux的头文件在哪里?
注意:这个问题在我编写时就已经解决了.我无法找到有关此问题的信息,所以我觉得无论如何发布它都会很有用.建议欢迎.
大家好.我最近在我的Linux Mint上安装了GCC 4.9.1,一直在编译我的一些项目,一切都进展顺利.
现在我想再次开始研究一个这样的项目,从一些源文件排序开始.所以我创建了一个新文件夹并在里面移动了几个.h和.tpp文件.结构如下所示:
.
??? clip
? ??? Clip.h
? ??? ClipImpl.tpp
? ??? Mask.h
:
??? main.cpp
:
??? vect.cpp
??? vect.h
:
Run Code Online (Sandbox Code Playgroud)
main.cpp只是#include "clip/Clip.h",稍后将包含一些用于测试目的的模板实例.clip/Clip.h包括clip/Mask.h,哪些需要vect.h.
注意后者包括不满意,所以编译器正确地抱怨.现在,我希望我#include的所有s都与项目的根目录相关,而不是它们的文件.好吧,我编辑我的Makefile:
# Retrieve the root directory
WD = $(shell pwd)
...
# Add it to the include search paths
%.o: %.cpp # vvvvvvv
$(CXX) $(CXXFLAGS) -I$(WD) -c $<
Run Code Online (Sandbox Code Playgroud)
然后......轰!
g++ -std=c++1y `sdl2-config --cflags` -Wall -Wextra -Winline -fno-rtti -I/home/quentin/NetBeansProjects/glk -c AutoDisplayed.cpp …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 cmake 运行 wxWidget 示例,但无法在我的 C++ 项目(CMakeLists.txt)中包含 wxWidgets 的标头。如果我使用命令运行程序
\ng++ main.cpp `wx-config --cppflags --libs` -o wxTest\nRun Code Online (Sandbox Code Playgroud)\n程序运行并显示窗口。但我该如何使用 CMakeLists.txt 文件来做到这一点。例如,通常我创建一个名为external-libs的单独文件夹,然后在其中创建一个名为whateverlibraryname的文件夹,然后在其中创建一个头文件、src和lib文件夹,我在其中放置头文件、任何源文件和.so文件分别。但就 wxWidgets 而言,我有几个静态库文件,并且标头内有许多单独的文件夹,我不知道如何将它们全部包含在内。他们产生错误:
\nfatal error: wx/wx.h: No such file or directory\n #include <wx/wx.h>\nRun Code Online (Sandbox Code Playgroud)\n我使用的是Ubuntu 18.04,我的项目目录结构如下:
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 build\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 source\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 CMakeLists.txt\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 external-libraries\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 wxWidgets\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 headers\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 msvc\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 wx\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 wx\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 android\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 aui\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dfb\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x82\xc2\xa0\xc2\xa0 …Run Code Online (Sandbox Code Playgroud) 在包含文件时我想知道的事情:
假设我想要包含文件或链接到它.我应该只是举例如:
include("../localfile.php");
Run Code Online (Sandbox Code Playgroud)
或者我应该改用
include("http://sameserver.com/but/adirect/linkto/localfile.php");
Run Code Online (Sandbox Code Playgroud)
这个比那个好吗?还是更安全?或者只是个人偏好?
显然,如果你有一个文件包含在多个目录中的文件中,并且那个文件包含一个不同的文件,或者有其他方法可以做到这一点,那将是必要的吗?
我目前正在使用index.php来包含另一个文件,它的结构如下:
root / index.php
/ new/ index.php
/ img/ test.jpg
Run Code Online (Sandbox Code Playgroud)
我在root/index.php中写了以下内容:
<?php
require_once("new/index.php");
?>
Run Code Online (Sandbox Code Playgroud)
问题是,其中的所有路径都是错误的.因为所有路径都基于new/index.php.
例如,在new/index.php中,我的test.jpg就像
<img src="img/test.jpg" />
Run Code Online (Sandbox Code Playgroud)
它显示http://www.test.com/new/img/test.jpg我何时直接访问new/index.php
但它显示http://www.test.com/img/test.jpg我在index.php中包含php.
怎么解决?我试过chdir(),但它不起作用期待谢谢
我找不到该stdio.h文件。我正在使用 Linux Mint 18.2 XFCE 和 gcc-7.2 编译器。
这是输出find . -type f -name stdio.h
smit@smit-Aspire-5742:/usr/lib/gcc$ find . -type f -name stdio.h
./i686-w64-mingw32/5.3-win32/include/ssp/stdio.h
./i686-w64-mingw32/5.3-win32/include/c++/tr1/stdio.h
./i686-w64-mingw32/5.3-posix/include/ssp/stdio.h
./i686-w64-mingw32/5.3-posix/include/c++/tr1/stdio.h
./x86_64-w64-mingw32/5.3-win32/include/ssp/stdio.h
./x86_64-w64-mingw32/5.3-win32/include/c++/tr1/stdio.h
./x86_64-w64-mingw32/5.3-posix/include/ssp/stdio.h
./x86_64-w64-mingw32/5.3-posix/include/c++/tr1/stdio.h
Run Code Online (Sandbox Code Playgroud)
我不需要 mingw 文件。这是一个我很少使用的交叉编译器。我找不到 gcc-7.2 的stdio.h文件。我是否在错误的目录中查找?
简单地说:它没有找到包含路径:
CC = g++
OBJS = *.o #*/*.o
DEBUG = -g
PNAME = game
INCLUDES = -Iheaders
CFLAGS = -Wall $(DEBUG)
LFLAGS = -Wall -lsfml-graphics -lsfml-window -lsfml-system $(DEBUG)
all: build
build: $(OBJS)
$(CC) $(LFLAGS) $(OBJS) -o $(PNAME)
clean:
\rm *.o *~ $(PNAME)
.cpp:
$(CC) $(CFLAGS) $(INCLUDES) -c $(.SOURCE)
Run Code Online (Sandbox Code Playgroud) 我有一些文件,如:〜/ code/include/test.h,〜/ code/src/test.c.我在test.c中使用include"test.h"但是编译器找不到test.h. 有没有办法解决问题除了包括"../include/test.h"
我想在我的.php文件中包含一个css文件.
在.php文件中,我有;
<?php
Loads of code..
?>
Run Code Online (Sandbox Code Playgroud)
我想要这样......
<?php
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
Loads of code..
?>
Run Code Online (Sandbox Code Playgroud)
但显然这不起作用.有什么方法可以做到这一点吗?
谢谢!