1

I have want to build a shared object/shared library to be used by an executable later on.

I have a directory with my own *.cpp as well as the corresponding *.h files. All the files are located in the same directory as my makefile (-I.):

#makefile to create shared library w/o executable from own headers and tesseract

CC = g++

INCL = -I. -I/usr/include/tesseract/ -I/usr/include/leptonica/

CFLAGS= -Wall -g -c -fPIC

LDFLAGS = -shared


LIBS = libtesseract.a liblept.a

RM = rm -f

TARGET_LIB = libTargetLib.so

SRCS = *.cpp
OBJS = $(SRCS:.cpp=.o)

.PHONY: all
all: ${TARGET_LIB}

$(TARGET_LIB): $(OBJS)
        $(CC) $(LDFLAGS) $(INCL) -Wl,-rpath=/usr/lib/x86_64-linux-gnu/ -o $(TARGET_LIB) $^ -L/usr/lib/x86_64-linux-gnu/ -llept -ltesseract

$(OBJS): $(SRCS)
        $(CC) $(CFLAGS) $(SRCS)

The library files to be linked, libtesseract.a and liblept.a are in the location /usr/lib/x86_64-linux-gnu, I doublechecked.

I am aware of this problem: ambiguous symbol File: tesscallback.h so I also commented out the correspondent lines.

When I run make, I get this error (tons of lines more):

In file included from /usr/include/tesseract/baseapi.h:34:0, from file1.h:16, from file1.cpp:4: /usr/include/tesseract/tesscallback.h:296:12: error: expected nested-name-specifier before ‘remove_reference’ typename remove_reference::type p1_; ^~~~~~~~~~~~~~~~ /usr/include/tesseract/tesscallback.h:296:12: error: expected ‘;’ at end of member declaration /usr/include/tesseract/tesscallback.h:296:28: error: expected unqualified-id before ‘<’ token typename remove_reference::type p1_; ^ /usr/include/tesseract/tesscallback.h: In constructor ‘_ConstTessMemberResultCallback_1_0::_ConstTessMemberResultCallback_1_0(const T*, _ConstTessMemberResultCallback_1_0::MemberSignature, P1)’: /usr/include/tesseract/tesscallback.h:301:29: error: class ‘_ConstTessMemberResultCallback_1_0’ does not have any field named ‘p1_’ member_(member), p1_(p1) { } ^~~ /usr/include/tesseract/tesscallback.h: In member function ‘virtual R _ConstTessMemberResultCallback_1_0::Run()’: /usr/include/tesseract/tesscallback.h:305:38: error: ‘p1_’ was not declared in this scope R result = (object_->*member_)(p1_); ^~~ /usr/include/tesseract/tesscallback.h:308:38: error: ‘p1_’ was not declared in this scope R result = (object_->member_)(p1_); ^~~ /usr/include/tesseract/tesscallback.h: At global scope: /usr/include/tesseract/tesscallback.h:326:12: error: expected nested-name-specifier before ‘remove_reference’ typename remove_reference::type p1_; ^~~~~~~~~~~~~~~~ /usr/include/tesseract/tesscallback.h:326:12: error: expected ‘;’ at end of member declaration /usr/include/tesseract/tesscallback.h:326:28: error: expected unqualified-id before ‘<’ token typename remove_reference::type p1_; ^ /usr/include/tesseract/tesscallback.h: In constructor ‘_ConstTessMemberResultCallback_1_0::_ConstTessMemberResultCallback_1_0(const T, _ConstTessMemberResultCallback_1_0::MemberSignature, P1)’: /usr/include/tesseract/tesscallback.h:331:29: error: class ‘_ConstTessMemberResultCallback_1_0’ does not have any field named ‘p1_’ member_(member), p1_(p1) { } ^~~ /usr/include/tesseract/tesscallback.h: In member function ‘virtual void _ConstTessMemberResultCallback_1_0::Run()’: /usr/include/tesseract/tesscallback.h:335:27: error: ‘p1_’ was not declared in this scope (object_->*member_)(p1_); ^~~ /usr/include/tesseract/tesscallback.h:337:27: error: ‘p1_’ was not declared in this scope (object_->*member_)(p1_);

When I do not comment it out (i. e., lines still there), I get:

In file included from /usr/include/tesseract/baseapi.h:34:0, from process_houghlines.h:18, from process_houghlines.cpp:3: /usr/include/tesseract/tesscallback.h:278:29: error: ‘remove_reference’ is not a class template template struct remove_reference { typedef T type; }; ^~~~~~~~~~~~~~~~ /usr/include/tesseract/tesscallback.h:278:29: error: redefinition of ‘struct remove_reference’ /usr/include/tesseract/tesscallback.h:277:29: note: previous definition of ‘struct remove_reference’ template struct remove_reference { typedef T type; }; ^~~~~~~~~~~~~~~~ /usr/include/tesseract/tesscallback.h:296:12: error: expected nested-name-specifier before ‘remove_reference’ typename remove_reference::type p1_; ^~~~~~~~~~~~~~~~ /usr/include/tesseract/tesscallback.h:296:12: error: expected ‘;’ at end of member declaration /usr/include/tesseract/tesscallback.h:296:28: error: expected unqualified-id before ‘<’ token typename remove_reference::type p1_; ^ /usr/include/tesseract/tesscallback.h: In constructor ‘_ConstTessMemberResultCallback_1_0::_ConstTessMemberResultCallback_1_0(const T*, _ConstTessMemberResultCallback_1_0::MemberSignature, P1)’: /usr/include/tesseract/tesscallback.h:301:29: error: class ‘_ConstTessMemberResultCallback_1_0’ does not have any field named ‘p1 ’ member_(member), p1_(p1) { } ^~~ /usr/include/tesseract/tesscallback.h: In member function ‘virtual R _ConstTessMemberResultCallback_1_0::Run()’: /usr/include/tesseract/tesscallback.h:305:38: error: ‘p1_’ was not declared in this scope R result = (object_->*member_)(p1_); ^~~ /usr/include/tesseract/tesscallback.h:308:38: error: ‘p1_’ was not declared in this scope R result = (object_->member_)(p1_); ^~~ /usr/include/tesseract/tesscallback.h: At global scope: /usr/include/tesseract/tesscallback.h:326:12: error: expected nested-name-specifier before ‘remove_reference’ typename remove_reference::type p1_; ^~~~~~~~~~~~~~~~ /usr/include/tesseract/tesscallback.h:326:12: error: expected ‘;’ at end of member declaration /usr/include/tesseract/tesscallback.h:326:28: error: expected unqualified-id before ‘<’ token typename remove_reference::type p1_; ^ /usr/include/tesseract/tesscallback.h: In constructor ‘_ConstTessMemberResultCallback_1_0::_ConstTessMemberResultCallback_1_0(const T, _ConstTessMemberResultCallback_1_0::MemberSignature, P1)’: /usr/include/tesseract/tesscallback.h:331:29: error: class ‘_ConstTessMemberResultCallback_1_0’ does not have any field named ... (reoccurring error)

The files file1.h and file1.cpp:

...
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h> 
...

and

...
#include "file1.h"
...

The files file2.h and file2.cpp:

...
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h> 
...

and

...
#include "file2.h"
...

I dont even understand, why the errors differ, since the headers are to the extend of using Tesseract just equal and one time the error occurs in one, than in the other file.

Thank you so much for any help.

  • It's unlikely that anyone can give you an explanation for an error message from lines that you didn't even bother to include in your question. Furthermore, it's fairly likely that an [mcve] is required, and not just the lines of code in question, in order to determine the compilation error. Finally, tesseract is on github, with active contributors and forums, where you are far more likely to find someone knowledgeable on that software, who will be able to point you in the right direction. – Sam Varshavchik Oct 10 '18 at 12:57
  • Thank you for the suggestion, I will post it on github. I also added more lines of the error. Further errors are re-occurring or dependent on the error in the first lines I really thing. However, I dont know for sure. I am thankful for any help. – Sebastian-CV-ML Oct 10 '18 at 13:14
  • Do you have any instance of `using namespace std;` in your code. – Sam Varshavchik Oct 10 '18 at 13:22
  • Yes, I have. many of those. There is a conflict of `std` and tesseract, which causes the issue shown in the second block comment. I resolved it by commenting out a couple of lines in `tesscallback.h`. When doing this, the error in the first block comment occurs, which I cannot solve. – Sebastian-CV-ML Oct 10 '18 at 13:27
  • I edited my question, it shows more of the error, when I do comment out the lines as suggested in [here](https://stackoverflow.com/questions/23740431/tesseract-remove-reference-ambiguous-symbol-in-project-on-visual-studio-2012). When using CMake, everything works fine. – Sebastian-CV-ML Oct 10 '18 at 13:31
  • Don't dump it on GitHub, provide a MCVE here in the question! – Lightness Races in Orbit Oct 10 '18 at 13:32
  • 1
    Congratulations! You've just discovered [why `using namespace std;` is bad practice](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). You will do yourself a favor if you completely forget that it's a part of C++. Get rid of all "using namespace std;" in your code, and this problem goes away. That's your answer here. Learn the habit of fully adding the "std::" qualifier when referencing any class or template from the standard C++ library. It's not hard to learn to do that, it quickly becomes 2nd nature, and there is no other option. – Sam Varshavchik Oct 10 '18 at 13:37
  • Wow. I just erased `using namespace std;` from my >20000 lines project and it works so far. – Sebastian-CV-ML Oct 10 '18 at 14:56

0 Answers0