gpt4 book ai didi

c++ - 关于 No such file or directory compilation terminated 错误

转载 作者:行者123 更新时间:2023-11-30 04:33:45 27 4
gpt4 key购买 nike

我是 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

最佳答案

您不包含头文件。 #include <ComPP/ComPlusPlus>这是一个目录。根据您发布的内容,您需要添加另一个 ComPlusPlus。 #include <ComPP/ComPlusPlus/ComPlusPlus>但是使用没有 .h 结尾的 header 是非常罕见的。所以你最好检查目录和文件的拼写。

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

关于c++ - 关于 No such file or directory compilation terminated 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6507734/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com