gpt4 book ai didi

c++ - 生成可执行文件时为 `File not found` 但在 Eclipse C++ 中运行正常

转载 作者:行者123 更新时间:2023-11-28 05:22:58 24 4
gpt4 key购买 nike

我正在尝试为我一直在处理的 C++ 脚本生成可执行文件,但遇到了错误,

ParameterTest.cpp:3:10: fatal error:
'3.04.01_2/include/tesseract/baseapi.h' file not found
#include <3.04.01_2/include/tesseract/baseapi.h>

这很奇怪,因为我可以在 Eclipse 中正常运行脚本。

我在做什么。

  1. 在 Eclipse C++ 中保存并构建项目
  2. g++ ParameterTest.cpp -o output.bin 命令行

当我停止包含库时,生成 output.bin 可执行文件也能正常工作。

这会不会与头文件或库的位置有关?

有没有其他人遇到过这个错误?

我是 C++ 开发的新手。


更新

在将所有库复制到目录中,使用 ./... 符号引用 header ,然后尝试创建可执行文件后,我遇到了另一个错误。

Undefined symbols for architecture x86_64:
"tesseract::TessBaseAPI::GetUTF8Text()", referenced from:
_main in ParameterTest-a6efcb.o
"tesseract::TessBaseAPI::End()", referenced from:
_main in ParameterTest-a6efcb.o
"tesseract::TessBaseAPI::Init(char const*, char const*, tesseract::OcrEngineMode, char**, int, GenericVector<STRING> const*, GenericVector<STRING> const*, bool)", referenced from:
tesseract::TessBaseAPI::Init(char const*, char const*) in ParameterTest-a6efcb.o
"tesseract::TessBaseAPI::SetImage(Pix*)", referenced from:
_main in ParameterTest-a6efcb.o
"tesseract::TessBaseAPI::TessBaseAPI()", referenced from:
_main in ParameterTest-a6efcb.o
"_pixDestroy", referenced from:
_main in ParameterTest-a6efcb.o
"_pixRead", referenced from:
_main in ParameterTest-a6efcb.o
ld: symbol(s) not found for architecture x86_64

我怀疑这与动态库链接有关。

最佳答案

首先尝试使用 " " 的周围路径而不是 < > . < >括号通常用于系统标题和 " "引号用于工作目录中的标题。参见 Difference between angle bracket < > and double quotes " " while including header files in C++?

如果不起作用,请尝试将 baseapi.h 移动到与 ParameterTest.cpp 相同的位置并将您的包含更改为

#include "baseapi.h"

如果可能的话。

更新:

在你的目录树中你应该看到这样的东西:

/src
| - ParameterTest.cpp
| - baseapi.h

在你设法使用 g++ 编译器编译你的代码后,你想将你的头文件移动到子目录“subdir”:

/src
| - ParameterTest.cpp
| /subdir
| | - baseapi.h

将您的包含更改为:

#include "./subdir/baseapi.h"

如果你想将你的header移动到与src同级的目录中:

/src
| - ParameterTest.cpp
/include
| - baseapi.h

将您的包含更改为:

#include "../include/baseapi.h"

一段时间后,当您的项目变得越来越大时,您可能会对更改每个源文件中的头文件路径只是为了将一个头文件移动到其他目录而感到厌倦,创建一个 Makefile 会更舒服

关于c++ - 生成可执行文件时为 `File not found` 但在 Eclipse C++ 中运行正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41081686/

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