【问题标题】:Including includes that contain the same includes包含包含相同包含的包含
【发布时间】:2014-10-07 14:45:43
【问题描述】:

好的,所以我有我的 main.cpp:

#include "chromosome.h"
#include "functions.h"

int main(){
blah;
return 0;

}

'functions.h' 和 'chromosome.h' 都有:

#include <vector> 
#include <random> 
#include <math.h>

这导致了错误:'linker command failed with exit code 1'。

谁能解释一下?我想这是一件非常简单的事情。我正在使用 xcode 5。

谢谢大家。

【问题讨论】:

  • 这应该不是问题。它很可能是别的东西。
  • 你读过任何本书吗?如果是,那么请阅读其他书籍,其中与警卫正确描述了链接。
  • 不,错误不是由此引起的。
  • 在每个头文件的开头放一次#pragma

标签: c++ include xcode5


【解决方案1】:

也许您在将文件链接在一起时遇到问题?进入 Target Settings -> Build Phases 并将您的文件添加到 Compile Sources。

【讨论】:

  • 谢谢,这里应该包括什么?我已经把所有的 .cpp 都放在那里了
【解决方案2】:

你应该在每个头文件中使用#include gaurds,像这样:

#ifndef MYHEADER
#define MYHEADER

/*your code here*/

#endif /* MYHEADER*/

您必须确保命名方案不会与可能使用的其他第三方标头冲突。

一个更优雅的解决方案是非标准的#pragma once 指令。

#pragma once

/*your code here*/

【讨论】:

    猜你喜欢
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多