生成可执行文件时“找不到文件”但在Eclipse C ++中运行正常

时间:2016-12-11 00:10:17

标签: c++ eclipse executable

我正在尝试为我一直在处理的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在命令行中
  3. 当我停止包含库时,生成output.bin可执行文件也可以正常工作。

    这可能与头文件或库的位置有关吗?

    有没有其他人有过这个错误的经历?

    我对C ++开发很陌生。

    更新

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

    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
    

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

1 个答案:

答案 0 :(得分:1)

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

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

#include "baseapi.h"

如果可能的话。

更新:

在您的目录树中,您应该看到如下内容:

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

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

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

将您的包含更改为:

#include "./subdir/baseapi.h"

如果要将标题移动到与src相同级别的目录:

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

将您的包含更改为:

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

一段时间后,当你的项目变大时,你可能会厌倦在每个源文件中更改标题路径,只是将一个标题移动到其他目录,创建一个Makefile会更加舒适