0

I'm trying to generate an executable file for a C++ script I've been working on but am running into an error,

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> 

It's weird because I can run the script fine inside Eclipse.

What I'm doing.

  1. Save and build project in Eclipse C++
  2. g++ ParameterTest.cpp -o output.bin in command line

Generating an output.bin executable also works fine when I stop including the libraries.

Could this have to do with the location of the header files or libraries?

Has anyone else had experience with this error?

I'm pretty new to C++ development.


UPDATE

After copying all libraries into the directory, referencing headers with ./... notation, and then trying to create an executable, I'm running into a different error.

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

I suspect this is related to dynamic library linking.

tim_xyz
  • 11,573
  • 17
  • 52
  • 97
  • My guess is that Eclipse knows where baseapi.h is stored but your system doesn't--path variable doesn't include the file – bpgeck Dec 11 '16 at 00:19

1 Answers1

1

First try with surrounding path with " " instead of < >. The < > brackets are usually used for system headers and " " quotes are used for headers in working directory. See Difference between angle bracket < > and double quotes " " while including header files in C++?

If doesn't work, try move baseapi.h to the same location as ParameterTest.cpp and change your include to

#include "baseapi.h"

if possible.

UPDATE:

In your directory tree you should see something like this:

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

After you managed to compile your code using g++ compiler and you want to move your header file to subdirectory "subdir":

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

change your include to:

#include "./subdir/baseapi.h"

If you want to move your header to a directory in same level as src:

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

change your include to:

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

After some time when your project gets bigger you may get bored with changing header path in every source file only to move one header to other directory and it will be more comfortable to create a Makefile

Community
  • 1
  • 1
Sebastian
  • 21
  • 6
  • Is it considered good practise to copy all required header, `.h` files into the `src` directory? – tim_xyz Dec 11 '16 at 02:27
  • no, but it will help to find a reason why you code cannot compile. When I make some small project with only one .cpp and .hpp I keep them in same place to easily compile and debug the code. For bigger projects I keep sources, headers, libraries and outputs in separated directories and create a Makefile. But if you use IDE it does it for you. – Sebastian Dec 11 '16 at 09:36
  • Thanks. That was helpful but I'm still getting stuck so I think I'll start experimenting with `cmake` if I can't get past here doing like this. – tim_xyz Dec 13 '16 at 02:51