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.
Related
This is my tmp.hpp:
#include <cstdlib>
#include <utility>
#include <unordered_map>
using namespace std;
struct int_int_hasher {
size_t operator()(pair<int, int> const& p) const {
return static_cast<size_t>(p.first) << 32 | p.second;
}
};
template<class T, class H>
class BiBag {
unordered_map<T, uint, H> t_to_id_;
};
And simple tmp.cpp:
#include "tmp.hpp"
class tmp {
BiBag<pair<int, int>, int_int_hasher> tt =
BiBag<std::pair<int, int>, int_int_hasher>();
};
The error message is beyond my understanding:
g++ -std=c++11 -O2 tmp.cpp -lm -o tmp
tmp.cpp:6:32: error: expected ‘;’ at end of member declaration
BiBag<std::pair<int, int>, int_int_hasher>();
^
tmp.cpp:6:32: error: declaration of ‘BiBag<std::pair<int, int>, int_int_hasher> tmp::int_int_hasher’ [-fpermissive]
In file included from tmp.cpp:2:0:
tmp.hpp:7:8: error: changes meaning of ‘int_int_hasher’ from ‘struct int_int_hasher’ [-fpermissive]
struct int_int_hasher {
^
tmp.cpp:6:46: error: expected unqualified-id before ‘>’ token
BiBag<std::pair<int, int>, int_int_hasher>();
^
tmp.cpp:6:16: error: wrong number of template arguments (1, should be 2)
BiBag<std::pair<int, int>, int_int_hasher>();
^
If I remove the hasher from the picture and replace the map with a simple <int,int> map I get no error.
Thank you.
I'm trying to build a simple project using biicode , including the catch cpp unit test library. For now I've a simple vanilla project with no extra declarations , looks something like
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "cbs-algorithm-sort.hpp"
int returnInt(int n){ return n; };
TEST_CASE( "Sample test", "[Sample Test]" ) {
REQUIRE( returnInt(1) == 1 );
REQUIRE( returnInt(2) == 2 );
REQUIRE( returnInt(3) == 6 );
REQUIRE( returnInt(10) == 3628800 );
}
when building with g++ 5.1.0 , the following errors are shown and project never gets built:
INFO: Processing changes...
INFO: Saving files from: florianwolters/catch
Running: "cmake" -G "Unix Makefiles" -Wno-dev ../cmake
-- The C compiler identification is GNU 5.1.0
-- The CXX compiler identification is GNU 5.1.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
BLOCK: florianwolters/catch
-----------------------------------------------------------
+ LIB: florianwolters_catch
-- Writing default cmake_dummy.cpp for building library
+ EXE: florianwolters_catch_projects_SelfTest_TestMain
+ EXE: florianwolters_catch_projects_SelfTest_ToStringWhich
BLOCK: agauniyal/cbs-algorithm-sort
-----------------------------------------------------------
+ LIB: agauniyal_cbs-algorithm-sort
+ EXE: agauniyal_cbs-algorithm-sort_unit_test
-- Initializing variables to create tests with CTest
-- Added custom target for all the tests:
-- Following targets are defined like tests (excluded from build)
+ TEST: agauniyal_cbs-algorithm-sort_unit_test
-- Configuring done
-- Generating done
-- Build files have been written to: /home/agauniyal/projects/cbs-algorithm-sort/bii/build
Building: "cmake" --build .
Scanning dependencies of target florianwolters_catch
[ 20%] Building CXX object florianwolters_catch/CMakeFiles/florianwolters_catch.dir/projects/SelfTest/TestMain.cpp.o
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_impl.hpp:19:0,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch.hpp:47,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/projects/SelfTest/TestMain.cpp:10:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:73:9: error: invalid suffix "f5615272b0fb51bcd7a669e68f3b4c7a87d93bb" on integer constant
>>>>>>> 7f5615272b0fb51bcd7a669e68f3b4c7a87d93bb
^
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_expression_lhs.hpp:12:0,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_result_builder.h:91,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_capture.hpp:11,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch.hpp:28,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/projects/SelfTest/TestMain.cpp:10:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:43:17: error: ‘nullptr_t’ in namespace ‘std’ does not name a type
inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; }
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:165:58: error: ‘template<Catch::Internal::Operator Op, class T> bool Catch::Internal::compare’ conflicts with a previous declaration
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:159:44: note: previous declaration ‘namespace Catch::Internal { }::compare’
template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:165:53: error: ‘nullptr_t’ is not a member of ‘std’
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:165:70: error: expected primary-expression before ‘*’ token
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:165:72: error: ‘rhs’ was not declared in this scope
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:165:76: error: expression list treated as compound expression in initializer [-fpermissive]
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:165:44: warning: variable templates only available with -std=c++14 or -std=gnu++14
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:165:78: error: expected ‘;’ before ‘{’ token
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:168:66: error: ‘std::nullptr_t’ has not been declared
template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:168:44: error: redefinition of ‘template<Catch::Internal::Operator Op, class T> bool Catch::Internal::compare(T*, int)’
template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) {
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_evaluate.hpp:159:44: note: ‘template<Catch::Internal::Operator Op, class T> bool Catch::Internal::compare(T*, int)’ previously declared here
template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
^
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_expression_lhs.hpp:13:0,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_result_builder.h:91,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_capture.hpp:11,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch.hpp:28,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/projects/SelfTest/TestMain.cpp:10:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_tostring.h:54:38: error: ‘std::string Catch::toString’ redeclared as different kind of symbol
std::string toString( std::nullptr_t );
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_tostring.h:51:13: note: previous declaration ‘std::string Catch::toString(unsigned char)’
std::string toString( unsigned char value );
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_tostring.h:54:23: error: ‘nullptr_t’ is not a member of ‘std’
std::string toString( std::nullptr_t );
^
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_impl.hpp:19:0,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch.hpp:47,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/projects/SelfTest/TestMain.cpp:10:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp: In member function ‘Catch::Totals Catch::Runner::runTests()’:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:63:1: error: expected primary-expression before ‘<<’ token
<<<<<<< HEAD
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:63:3: error: expected primary-expression before ‘<<’ token
<<<<<<< HEAD
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:63:5: error: expected primary-expression before ‘<<’ token
<<<<<<< HEAD
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:63:7: error: expected primary-expression before ‘<’ token
<<<<<<< HEAD
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:63:9: error: ‘HEAD’ was not declared in this scope
<<<<<<< HEAD
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:64:3: error: expected primary-expression before ‘==’ token
=======
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:64:5: error: expected primary-expression before ‘==’ token
=======
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:64:7: error: expected primary-expression before ‘=’ token
=======
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:65:35: error: expected primary-expression before ‘skippedTestCases’
std::vector<TestCase> skippedTestCases;
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:66:91: error: ‘skippedTestCases’ was not declared in this scope
getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, skippedTestCases, true );
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:69:27: error: name lookup of ‘itEnd’ changed for ISO ‘for’ scoping [-fpermissive]
it != itEnd;
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:69:27: note: (if you use ‘-fpermissive’ G++ will accept your code)
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:73:1: error: expected primary-expression before ‘>>’ token
>>>>>>> 7f5615272b0fb51bcd7a669e68f3b4c7a87d93bb
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:73:3: error: expected primary-expression before ‘>>’ token
>>>>>>> 7f5615272b0fb51bcd7a669e68f3b4c7a87d93bb
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:73:5: error: expected primary-expression before ‘>>’ token
>>>>>>> 7f5615272b0fb51bcd7a669e68f3b4c7a87d93bb
^
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:73:7: error: expected primary-expression before ‘>’ token
>>>>>>> 7f5615272b0fb51bcd7a669e68f3b4c7a87d93bb
^
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_impl.hpp:35:0,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch.hpp:47,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/projects/SelfTest/TestMain.cpp:10:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_tostring.hpp: At global scope:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_tostring.hpp:163:38: error: ‘std::string Catch::toString’ redeclared as different kind of symbol
std::string toString( std::nullptr_t ) {
^
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_expression_lhs.hpp:13:0,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_result_builder.h:91,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_capture.hpp:11,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch.hpp:28,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/projects/SelfTest/TestMain.cpp:10:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_tostring.h:199:13: note: previous declaration ‘template<class T, class Allocator> std::string Catch::toString(const std::vector<_Tp, _Alloc>&)’
std::string toString( std::vector<T,Allocator> const& v ) {
^
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_impl.hpp:35:0,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch.hpp:47,
from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/projects/SelfTest/TestMain.cpp:10:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_tostring.hpp:163:23: error: ‘nullptr_t’ is not a member of ‘std’
std::string toString( std::nullptr_t ) {
^
florianwolters_catch/CMakeFiles/florianwolters_catch.dir/build.make:54: recipe for target 'florianwolters_catch/CMakeFiles/florianwolters_catch.dir/projects/SelfTest/TestMain.cpp.o' failed
make[2]: *** [florianwolters_catch/CMakeFiles/florianwolters_catch.dir/projects/SelfTest/TestMain.cpp.o] Error 1
CMakeFiles/Makefile2:110: recipe for target 'florianwolters_catch/CMakeFiles/florianwolters_catch.dir/all' failed
make[1]: *** [florianwolters_catch/CMakeFiles/florianwolters_catch.dir/all] Error 2
Makefile:85: recipe for target 'all' failed
make: *** [all] Error 2
ERROR: Build failed
and with clang++ , using bii configure -D CMAKE_CXX_COMPILER=clang++ :
Scanning dependencies of target florianwolters_catch
[ 20%] Building CXX object florianwolters_catch/CMakeFiles/florianwolters_catch.dir/projects/SelfTest/TestMain.cpp.o
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/projects/SelfTest/TestMain.cpp:10:
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch.hpp:47:
In file included from /home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/internal/catch_impl.hpp:19:
/home/agauniyal/projects/cbs-algorithm-sort/bii/deps/florianwolters/catch/include/catch_runner.hpp:63:1: error: version control conflict marker in file
<<<<<<< HEAD
^
1 error generated.
florianwolters_catch/CMakeFiles/florianwolters_catch.dir/build.make:54: recipe for target 'florianwolters_catch/CMakeFiles/florianwolters_catch.dir/projects/SelfTest/TestMain.cpp.o' failed
make[2]: *** [florianwolters_catch/CMakeFiles/florianwolters_catch.dir/projects/SelfTest/TestMain.cpp.o] Error 1
CMakeFiles/Makefile2:110: recipe for target 'florianwolters_catch/CMakeFiles/florianwolters_catch.dir/all' failed
make[1]: *** [florianwolters_catch/CMakeFiles/florianwolters_catch.dir/all] Error 2
Makefile:85: recipe for target 'all' failed
make: *** [all] Error 2
I've no idea about errors generated by both compilers specially the clang one. Any kind of help would suffice.
You most likely have a git merge, either in progress or aborted. These:
<<<<<<< HEAD
=================
>>>>>>> 7f5615272b0fb51bcd7a669e68f3b4c7a87d93bb
are the markers git places where version conflicts arise that cannot be solved automatically. Search for all occurences of <<<<<, do the required edits, possibly commit and then recompile.
If it isn't your code, maybe downloading or cloning again will be a quick solution.
#include <vector>
int main() {
struct st { int a; };
std::vector<st> v;
for (std::vector<st>::size_type i = 0; i < v.size(); i++) {
v.operator[](i).a = i + 1; // v[i].a = i+1;
}
}
The above code gives the following errors when compiled with GNU g++ compiler.
test.cpp: In function ‘int main()’:
test.cpp:6:19: error: template argument for ‘template<class _Alloc> class std::allocator’ uses local type ‘main()::st’
test.cpp:6:19: error: trying to instantiate ‘template<class _Alloc> class std::allocator’
test.cpp:6:19: error: template argument 2 is invalid
test.cpp:6:22: error: invalid type in declaration before ‘;’ token
test.cpp:7:24: error: template argument for ‘template<class _Alloc> class std::allocator’ uses local type ‘main()::st’
test.cpp:7:24: error: trying to instantiate ‘template<class _Alloc> class std::allocator’
test.cpp:7:24: error: template argument 2 is invalid
test.cpp:7:37: error: expected initializer before ‘i’
test.cpp:7:44: error: ‘i’ was not declared in this scope
test.cpp:7:50: error: request for member ‘size’ in ‘v’, which is of non-class type ‘int’
test.cpp:8:20: error: request for member ‘operator[]’ in ‘v’, which is of non-class type ‘int’
Why I am not able to create vector of structures?
Before C++11, you couldn't instantiate templates with local classes. You have two options:
1) Put the st definition outside of main
#include <vector>
struct st { int a; };
int main()
{
std::vector<st> v;
}
2) Compile with a c++11 compiler
I am trying to use boost::future .then() functionality.
The snippet is taken from Boost 1.54.0 thread synchronisation documentation
#include <string>
#include <boost/thread/future.hpp>
int main() {
boost::future<int> f1 = boost::async([]() { return 123; });
boost::future<std::string> f2 = f1.then([](boost::future<int> f)->std::string {
int x = f.get();
return ("Done" + std::to_string(x));
});
}
Setup :
Ubuntu 13.04
g++ version g++ (Ubuntu 4.8.1-2ubuntu1~13.04) 4.8.1
Boost version 1.54.0
command line :
g++ then_test.cc -std=c++0x -DBOOST_THREAD_VERSION=4 -I /home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost -L /home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost/stage/lib -static -lboost_thread-mt -lboost_date_time-mt -lboost_system-mt -lpthread
Error:
g++ then_test.cc -std=c++0x -DBOOST_THREAD_VERSION=4 -I /home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost -L /home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost/stage/lib -static -lboost_thread-mt -lboost_date_time-mt -lboost_system-mt -lpthread
then_test.cc: In function ‘int main()’:
then_test.cc:10:44: error: no matching function for call to ‘boost::future<int>::then(main()::__lambda1)’
});
^
then_test.cc:10:44: note: candidates are:
In file included from then_test.cc:2:0:
/home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost/boost/thread/future.hpp:1598:9: note: template<class F> boost::future<typename boost::result_of<F(boost::future<R>&)>::type> boost::future<R>::then(F&&) [with F = F; R = int]
then(BOOST_THREAD_FWD_REF(F) func);
^
/home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost/boost/thread/future.hpp:1598:9: note: template argument deduction/substitution failed:
In file included from then_test.cc:2:0:
/home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost/boost/thread/future.hpp: In substitution of ‘template<class F> boost::future<typename boost::result_of<F(boost::future<R>&)>::type> boost::future<R>::then(F&&) [with F = F; R = int] [with F = main()::__lambda1]’:
then_test.cc:10:44: required from here
/home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost/boost/thread/future.hpp:62:29: error: no type named ‘type’ in ‘struct boost::result_of<main()::__lambda1(boost::future<int>&)>’
#define BOOST_THREAD_FUTURE future
^
/home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost/boost/thread/future.hpp:3840:3: note: in expansion of macro ‘BOOST_THREAD_FUTURE’
BOOST_THREAD_FUTURE<R>::then(BOOST_THREAD_FWD_REF(F) func)
^
In file included from then_test.cc:2:0:
/home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost/boost/thread/future.hpp:1601:9: note: template<class F> boost::future<typename boost::result_of<F(boost::future<R>&)>::type> boost::future<R>::then(boost::launch, F&&) [with F = F; R = int]
then(launch policy, BOOST_THREAD_FWD_REF(F) func);
^
/home/prakash/maidsafe/MaidSafe/build/boost_1_54_0/src/boost/boost/thread/future.hpp:1601:9: note: template argument deduction/substitution failed:
then_test.cc:10:44: note: cannot convert ‘<lambda closure object>main()::__lambda1{}’ (type ‘main()::__lambda1’) to type ‘boost::launch’
});
Please let me know if I am missing something here.
Passing future by reference to .then() fixes the compilation issue on gcc 4.8 & clang.
For windows and gcc 4.7 we additionally need to define BOOST_RESULT_OF_USE_DECLTYPE. (as per Xeo's comment). For gcc 4.8 & clang it seems available already.
boost::future<std::string> f2 = f1.then([](boost::future<int>& f)->std::string {
^
See the below code,
The question is: how can I delay the construction of an object that is non-copyable, using optional<>.
I'm using boost::optional in the example, although I believe its now in the std::optional standard too.
Yes, I could use scoped_ptr<>, however I wanted to allocate on the stack, not the heap.
#include <boost/optional.hpp>
#include <boost/utility.hpp>
using namespace boost;
struct HardFoo : noncopyable { };
int main()
{
optional<HardFoo> ok_1( in_place() ); // OK
// optional<HardFoo> no_1( HardFoo() ); // won't compile
optional<HardFoo> delay_construct;
// delay_construct = HardFoo(); // won't compile
// delay_construct = optional<HardFoo>( in_place() ); // won't compile
// delay_construct.swap( optional<HardFoo>( in_place() ) ); // won't compile
return 0;
}
I'm using g++, I assume it wouldn't matter whether its C++03 or C++11 in this case, as its a fundamental design issue rather than just a stuff up in the code.
As requested, some error messages, for this one, I uncommented:
delay_construct = HardFoo();
$ g++ -g -Wall -o test -I/stuff/boost/ test.cpp
In file included from /stuff/boost/utility.hpp:18:0,
from test.cpp:2:
test.cpp: In instantiation of ‘void boost::optional_detail::optional_base<T>::assign_value(boost::optional_detail::optional_base<T>::argument_type, boost::optional_detail::optional_base<T>::is_not_reference_tag) [with T = HardFoo; boost::optional_detail::optional_base<T>::argument_type = const HardFoo&; boost::optional_detail::optional_base<T>::is_not_reference_tag = mpl_::bool_<false>]’:
/stuff/boost/optional/optional.hpp:307:12: required from ‘void boost::optional_detail::optional_base<T>::assign(boost::optional_detail::optional_base<T>::argument_type) [with T = HardFoo; boost::optional_detail::optional_base<T>::argument_type = const HardFoo&]’
/stuff/boost/optional/optional.hpp:606:9: required from ‘boost::optional<T>& boost::optional<T>::operator=(boost::optional<T>::argument_type) [with T = HardFoo; boost::optional<T> = boost::optional<HardFoo>; boost::optional<T>::argument_type = const HardFoo&]’
test.cpp:14:30: required from here
/stuff/boost/noncopyable.hpp:28:26: error: ‘const boost::noncopyable_::noncopyable& boost::noncopyable_::noncopyable::operator=(const boost::noncopyable_::noncopyable&)’ is private
test.cpp:6:8: error: within this context
In file included from /stuff/boost/optional.hpp:15:0,
from test.cpp:1:
/stuff/boost/optional/optional.hpp:433:69: note: synthesized method ‘HardFoo& HardFoo::operator=(const HardFoo&)’ first required here
In file included from /stuff/boost/utility.hpp:18:0,
from test.cpp:2:
test.cpp: In instantiation of ‘void boost::optional_detail::optional_base<T>::construct(boost::optional_detail::optional_base<T>::argument_type) [with T = HardFoo; boost::optional_detail::optional_base<T>::argument_type = const HardFoo&]’:
/stuff/boost/optional/optional.hpp:308:12: required from ‘void boost::optional_detail::optional_base<T>::assign(boost::optional_detail::optional_base<T>::argument_type) [with T = HardFoo; boost::optional_detail::optional_base<T>::argument_type = const HardFoo&]’
/stuff/boost/optional/optional.hpp:606:9: required from ‘boost::optional<T>& boost::optional<T>::operator=(boost::optional<T>::argument_type) [with T = HardFoo; boost::optional<T> = boost::optional<HardFoo>; boost::optional<T>::argument_type = const HardFoo&]’
test.cpp:14:30: required from here
/stuff/boost/noncopyable.hpp:27:7: error: ‘boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&)’ is private
test.cpp:6:8: error: within this context
In file included from /stuff/boost/optional.hpp:15:0,
from test.cpp:1:
/stuff/boost/optional/optional.hpp:346:8: note: synthesized method ‘HardFoo::HardFoo(const HardFoo&)’ first required here
There is an answer suggesting to use in_place directly,
it works with this:
optional<HardFoo> ok( in_place() );
but not this:
optional<HardFoo> no( in_place<HardFoo>() ); // BAD
The error messages:
$ g++ -g -Wall -o test -I/stuff/boost/ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:15:44: error: no matching function for call to ‘in_place()’
test.cpp:15:44: note: candidates are:
In file included from /stuff/boost/preprocessor/iteration/detail/iter/forward1.hpp:52:0,
from /stuff/boost/utility/in_place_factory.hpp:24,
from /stuff/boost/optional/optional.hpp:37,
from /stuff/boost/optional.hpp:15,
from test.cpp:1:
/stuff/boost/utility/in_place_factory.hpp:73:1: note: template<class A0> boost::in_place_factory1<A0> boost::in_place(const A0&)
/stuff/boost/utility/in_place_factory.hpp:73:1: note: template argument deduction/substitution failed:
test.cpp:15:44: note: candidate expects 1 argument, 0 provided
In file included from /stuff/boost/preprocessor/iteration/detail/iter/forward1.hpp:57:0,
from /stuff/boost/utility/in_place_factory.hpp:24,
from /stuff/boost/optional/optional.hpp:37,
from /stuff/boost/optional.hpp:15,
from test.cpp:1:
/stuff/boost/utility/in_place_factory.hpp:73:1: note: template<class A0, class A1> boost::in_place_factory2<A0, A1> boost::in_place(const A0&, const A1&)
/stuff/boost/utility/in_place_factory.hpp:73:1: note: template argument deduction/substitution failed:
test.cpp:15:44: note: candidate expects 2 arguments, 0 provided
In file included from /stuff/boost/preprocessor/iteration/detail/iter/forward1.hpp:62:0,
from /stuff/boost/utility/in_place_factory.hpp:24,
from /stuff/boost/optional/optional.hpp:37,
from /stuff/boost/optional.hpp:15,
from test.cpp:1:
You need to in_place directly into the object:
delay_construct = boost::in_place<Type>(params);
Note that it appears that boost didn't support default construction through factories (nullary factories) until 1.35.
In C++14, we will have std::optional, which happens to have std::optional::emplace. So you can do:
std::optional<HardFoo> delay_construct;
delay_construct.emplace(constructor_arg_1, constructor_arg_2);