我有一个程序依赖于多个包含文件。当我按照下面所示的顺序定义包含时,程序可以正常编译。
#include <iostream>
#include "opencv2/cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/internal.hpp" // For TBB wrappers
#include "arrayfire.h"
Run Code Online (Sandbox Code Playgroud)
但是,当我切换最后两个包含时,如下所示
#include <iostream>
#include "opencv2/cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "arrayfire.h"
#include "opencv2/core/internal.hpp" // For TBB wrappers
Run Code Online (Sandbox Code Playgroud)
我收到编译器错误:
1>d:\libraries\tbb41\tbb41_20130613oss\include\tbb\task.h(765): 错误 C2059: 语法错误: '{' 1>d:\libraries\tbb41\tbb41_20130613oss\include\tbb\task.h( 765): 错误 C2334: '{' 之前的意外标记;跳过明显的函数体
这是出乎意料的,我想解决它。所有包含内容均来自库(OpenCV 和 ArrayFire)。关于可能的原因以及如何解决此问题有什么建议吗?
编辑这是task.h的相关部分:
759 #if __TBB_TASK_GROUP_CONTEXT
760 //! This method is deprecated and will be removed in the future.
761 /** Use method group() instead. **/
762 task_group_context* context() {return prefix().context;} …Run Code Online (Sandbox Code Playgroud) 我有以下课程如何在php中包含另一个文件(如include())中的视图。
class A extends Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>A</Text>
</View>
);
}
}
class B extends Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>B</Text>
</View>
);
}
}
class C extends Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>B</Text>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我必须包含来自外部文件的视图。我们可以通过导入将一个类包含到另一个类中,但是视图呢?
我收到错误:
ndefined symbols for architecture x86_64:
"_setVal", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
Run Code Online (Sandbox Code Playgroud)
我查看了其他帖子,但似乎没有什么可以解决问题。我认为我正确使用了 include 。
主要.c:
#include "game.h"
int main(int argc, char *argv[]) {
setVal(board, 1, 0, 6);
}
Run Code Online (Sandbox Code Playgroud)
游戏.h:
#ifndef GAME_H_
#define GAME_H_
bool SetVal(Board* board, int row, int col, int value);
#endif
Run Code Online (Sandbox Code Playgroud)
游戏.c:
ndefined symbols for architecture x86_64:
"_setVal", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: …Run Code Online (Sandbox Code Playgroud) 我真的不喜欢我必须在我的包含中向后导航。如果有办法避免这种情况,我会更喜欢。以这个文件夹为例:
有什么方法可以告诉编译器 (gcc) 开始从 RootFolder 寻找包含,所以我可以#include "Logic/Entitiy/Player.h"在我的 MainView.h/c 或其他任何地方说,这样我就可以避免那种不吸引人的向后导航。
我为什么想要这个?
我想使用最初于 2007 年构建并根据变更日志于 2016 年最新更新的C 软件包。我认为它会干净地编译回来。
可悲的是,现在情况已不再如此。
错误
运行./configure和make,我得到一个Multiply defined错误:
gcc -g -O2 -o laplaafit laplaafit.o multimin.o common.o lib/libgnu.a -lgsl -lgslcblas -lm
/usr/bin/ld: common.o:/home/<user>/build/subbotools/subbotools-1.3.0/common.c:27: multiple definition of `Size'; laplaafit.o:/home/<user>/build/subbotools/subbotools-1.3.0/laplaafit.c:38: first defined here
/usr/bin/ld: common.o:/home/<user>/build/subbotools/subbotools-1.3.0/common.c:26: multiple definition of `Data'; laplaafit.o:/home/<user>/build/subbotools/subbotools-1.3.0/laplaafit.c:37: first defined here
Run Code Online (Sandbox Code Playgroud)
具体来说,两个文件 (laplaafit.c和common.c) 都有声明
double *Data; /*the array of data*/
unsigned Size;/*the number of data*/
Run Code Online (Sandbox Code Playgroud)
在两个文件的代码中进一步定义了两个变量(我相信使用load(&Data,&Size,infile);which 调用函数int load(),在该函数中从文件common.c读取数组并确定其长度)。*DataSize …
我知道如果有一个值数组,则必须使用这种方法:
console.log(['joe', 'jane', 'mary'].includes('jane')); // true
Run Code Online (Sandbox Code Playgroud)
但是在数组数组的情况下,是否有一种简短的方法来做到这一点?之间没有其他计算。
对于此输入:
[['jane'],['joe'],['mary']]
Run Code Online (Sandbox Code Playgroud) 我知道 #inclusion 通常被描述为文本复制粘贴预处理器指令。现在,如果标头受到 #include 保护或 #pragma 一次,那么我们如何描述第一个翻译单元之后实际发生的情况到 #include 所述标头?
我想理解为什么对 Traits 的讨论似乎从来不包括与 Require 的比较,而是总是与继承进行比较。
据我了解,Require 本质上与运行时的复制/粘贴相同,并且 Require_Once 确保代码不重复。特征通常也被称为与复制/粘贴几乎相同。
也就是说,Require 和 Include 可以在条件逻辑中使用,因此在某些情况下它们可以成为 Trait 的更好替代方案。Traits 具有多态性和其他理想的功能,而这些功能是严格复制代码所无法获得的。例如,能够抽象特征中的函数,然后选择性地在容器类中重写。
这两个“代码包含/导入”功能在范围方面具有相似的行为,例如 $this。
但一个明显的区别是 Include/Require 代码默认会进入 HTML 处理,并且 <?php 是可选的,具体取决于上下文,通过 Trait 我们知道代码必须是 PHP 并且必须以 <?php 为前缀。
所以对我来说,Trait 更像是一个更高级别的 OOP 工具,而 Require 是一个不了解 OOP 细节的语言级指令。然而,在许多情况下,使用 Require 代码似乎比使用 Trait 来包含相同的代码同样简单和有用。
我希望有人能够提供清晰的示例,其中将选择一个而不是另一个,以便更明显地应该使用哪一个。除了我所引用的内容之外,还有更多细节。我是否已经走在做出这些选择的正确道路上?比这更简单,还是更复杂?比较表将是理想的。
#include <iostream>
#include<eigen3/Eigen/src/Core/Matrix.h> // does not define Eigen::StorageOptions
// need something like this
#include<eigen3/Eigen/src/ everything_in_here >
int main()
{
Eigen::Matrix<double,2,2> mat;
std::cout << mat(0,0) <<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在那里,我试图构建一个矩阵对象,它总是询问 6 个模板参数并带有错误消息:
模板参数数量错误(3,应该是 6)
所以我开始添加它们,第四个是Eigen::StorageOptions并且没有在Matrix.h标头中定义。另外,还有太多的标题需要搜索。那么,我可以将所有文件包含在一个文件中吗#include?
include ×10
c ×4
c++ ×4
arrayfire ×1
arrays ×1
class ×1
compilation ×1
ecmascript-6 ×1
eigen ×1
import ×1
javascript ×1
linux ×1
php ×1
react-native ×1
require ×1
traits ×1
view ×1