【问题标题】:About No such file or directory compilation terminated error关于 No such file or directory 编译终止错误
【发布时间】:2011-06-30 21:59:15
【问题描述】:

我是 C++ 新手,我已经安装了 lib Com++ 用于网络编程 但是当我只包含头文件时

#include <iostream>
#include <ComPP/ComPlusPlus>
using namespace std;

int main(int argc ,char *argv[]){

    cout << "Hello World" << endl;
    return 0;
}

我得到了错误

main.cpp:2:29: fatal error: ComPP/ComPlusPlus: No such file or directory

使用 Fedora linux 我使用此命令按照手册中所述进行编译

g++ -I ./ -L./ -o server  main.cpp -lCommPP -lsys -lpthread -lrt

目录 /usr/include/ComPP/ 与所有头文件都存在

ComPP
├── ComPlusPlus
│   ├── AClnt.h
│   ├── ASrvContext.h
│   ├── ASrv.h
│   ├── ASrvProperties.h
│   ├── Clone.h
│   ├── Comm.h
│   ├── ComPlusPlus
│   ├── Context.h
│   ├── Daemon.h
│   ├── Directory.h
│   ├── DirEntry.h
│   ├── File.h
│   ├── Launch.h
│   ├── Mutex.h
│   ├── Poll.h
│   ├── Process.h
│   ├── SClnt.h
│   ├── Sem.h
│   ├── ShMem.h
│   ├── Signalling.h
│   ├── Socket.h
│   ├── SocketTcp.h
│   ├── SocketUdp.h
│   ├── SocketUnix.h
│   ├── SrvProperties.h
│   ├── SSrvContext.h
│   ├── SSrv.h
│   ├── SSrvProperties.h
│   └── Thread.h
└── SysPlusPlus
    ├── ComException.h
    ├── config.h
    ├── GenCfg.h
    ├── Logger.h
    ├── syscall.h
    ├── syslib.h
    ├── SysPlusPlus
    └── Tools.h

【问题讨论】:

  • 您没有指定要包含哪些头文件。

标签: c++ network-programming include-path


【解决方案1】:

您没有包含头文件。 #include &lt;ComPP/ComPlusPlus&gt; 这是一个目录。根据您发布的内容,您需要添加另一个 ComPlusPlus。 #include &lt;ComPP/ComPlusPlus/ComPlusPlus&gt; 但很少使用没有 .h 结尾的标题。所以你最好检查目录和文件的拼写。

仔细阅读 cplusplus.com 网站后。错误确实是别的东西。
他们假设您将编译器的包含路径设置为 ComPP。例如,Ahmed 已经用 -I /usr/include/ComPP 进行了评论。
因此,您可以完全限定您在 cpp 文件中的包含,因为 /usr/include/ 是 gcc 的标准搜索路径,或者您添加另一个路径。
不过,我发现使用没有 .h 结尾的标题非常烦人。

【讨论】:

  • 当我使用 -I /usr/include/ComPP 选项时,我认为一切正常
  • 这是另一种方法。如果您将 ComPP 添加到您的搜索路径,则包含语句会再次指向一个文件。
  • 不少库和 c++ std 库确实使用带有“.h”后缀的头文件。
  • 这是完全正确的,根据标准,可以命名带有或不带有 .h 的标头。但我仍然认为结束标头 .h 是一种很常见的做法。我个人认为标准化小组放弃 .h 结尾是一个坏主意,但我不想就这个决定的利弊展开一场激烈的战争。
【解决方案2】:

当您下载 comPP 库时,文档文件夹中有一个 ProgrammersGuide.pdf。在那里你可以找到需要的库。该文件并非 100% 准确。我让它使用这种格式工作:

g++ -I/usr/include/ComPP -lComPP -lSysPP -lpthread -lrt ExampleClient.cpp -o ExampleClient

这只有在您拥有以下内容时才有效:

#include <SysPlusPlus/SysPlusPlus>
#include <ComPlusPlus/ComPlusPlus>

亲切的问候,

马丁

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2016-11-01
    • 2019-03-18
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    相关资源
    最近更新 更多