I am unable to Compile GMP on OSX 10.9. I am not entirely sure, if the problem is OSX 10.9 specific but what happens is compilation is successful but make check fails.
Please note if I don't use --enable-cxx compilation and make check both succeeds.
The full error is:
c++ -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../tests -O2 -pedantic -fomit-frame-pointer -m64 -mtune=corei7 -march=corei7 -c -o t-cast.o t-cast.cc
brew: superenv removed: -O2 -pedantic -m64 -mtune=corei7 -march=corei7
In file included from t-cast.cc:20:
In file included from ../../gmp.h:51:
/Applications/Xcode5-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cstddef:51:9: error: no member named
'ptrdiff_t' in the global namespace
using ::ptrdiff_t;
~~^
In file included from t-cast.cc:21:
In file included from ../../gmpxx.h:29:
In file included from /Applications/Xcode5-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/algorithm:594:
In file included from /Applications/Xcode5-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/memory:596:
/Applications/Xcode5-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iterator:386:13: error: unknown type name
'ptrdiff_t'
typedef ptrdiff_t difference_type;
^
/Applications/Xcode5-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iterator:413:56: error: unknown type name
'ptrdiff_t'
template<class _Category, class _Tp, class _Distance = ptrdiff_t, ^/Applications/Xcode5-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iterator:720:66: error: unknown type name
'ptrdiff_t' class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
^
/Applications/Xcode5-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iterator:720:54: error: template parameter
missing a default argument
class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
^
/Applications/Xcode5-DP2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iterator:720:27: note: previous default
template argument defined here class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
Remove the __need_size_t define and undef in gmp.h. It'll import ptrdiff_t too, rather than just size_t.
Related
I am using tesseract engine with openCV3.0.
When I use:
#include <tesseract\baseapi.h>
It shows:
x86_64-w64-mingw32-g++.exe -Wall -fexceptions -O2 -std=c++11 -DDLIB_PNG_SUPPORT -DLIB_PNG_SUPPORT -IC:\tesseract\tesseract\include -IC:\tesseract\tesseract\include\leptonica -IC:\tesseract\tesseract\include\tesseract -c F:\freelancer\RajivCK\test\ocrtest2\main.cpp -o obj\Release\main.o
In file included from C:/TDM-GCC-64/x86_64-w64-mingw32/include/combaseapi.h:153:0,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/objbase.h:14,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/ole2.h:17,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/wtypes.h:12,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/winscard.h:10,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/windows.h:97,
from C:\tesseract\tesseract\include/tesseract\host.h:25,
from C:\tesseract\tesseract\include/tesseract\tesscallback.h:22,
from C:\tesseract\tesseract\include/tesseract\baseapi.h:31,
from F:\freelancer\RajivCK\test\ocrtest2\main.cpp:1:
C:/TDM-GCC-64/x86_64-w64-mingw32/include/wtypesbase.h:385:3: error: conflicting declaration 'typedef struct tagBLOB BLOB'
} BLOB;
^
In file included from C:\tesseract\tesseract\include/tesseract\baseapi.h:27:0,
from F:\freelancer\RajivCK\test\ocrtest2\main.cpp:1:
C:\tesseract\tesseract\include/tesseract\platform.h:30:3: note: previous declaration as 'typedef struct _BLOB BLOB'
} BLOB, LPBLOB;
^
In file included from C:/TDM-GCC-64/x86_64-w64-mingw32/include/combaseapi.h:153:0,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/objbase.h:14,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/ole2.h:17,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/wtypes.h:12,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/winscard.h:10,
from C:/TDM-GCC-64/x86_64-w64-mingw32/include/windows.h:97,
from C:\tesseract\tesseract\include/tesseract\host.h:25,
from C:\tesseract\tesseract\include/tesseract\tesscallback.h:22,
from C:\tesseract\tesseract\include/tesseract\baseapi.h:31,
from F:\freelancer\RajivCK\test\ocrtest2\main.cpp:1:
C:/TDM-GCC-64/x86_64-w64-mingw32/include/wtypesbase.h:386:25: error: conflicting declaration 'typedef struct tagBLOB LPBLOB'
typedef struct tagBLOB LPBLOB;
^
In file included from C:\tesseract\tesseract\include/tesseract\baseapi.h:27:0,
from F:\freelancer\RajivCK\test\ocrtest2\main.cpp:1:
C:\tesseract\tesseract\include/tesseract\platform.h:30:10: note: previous declaration as 'typedef struct _BLOB LPBLOB'
} BLOB, *LPBLOB;
'
The guide for tesseract engine was used from this link.
I was using wrong binaries which were not prebuilt for my OS
I'm trying to compile some code utilizing C++11's library on a linux server. The code compiles fine on my mac with this line in my makefile:
CC = clang++ -std=c++11 -stdlib=libc++
However, when I try and compile the same code on a Linux server, with gcc version 4.8.1, I get the following error:
$ /usr/local/share/gcc481/bin/g++ -std=c++11 server.cpp
In file included from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/random:50:0,
from ellipse-graph.h:6,
from server.cpp:1:
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/random.h: In instantiation of 'class std::uniform_int_distribution<double>':
server.cpp:17:59: required from here
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/random.h:1668:7: error: static assertion failed: template argument not an integral type
static_assert(std::is_integral<_IntType>::value,
^
In file included from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/move.h:57:0,
from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/stl_pair.h:59,
from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/stl_algobase.h:64,
from /auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/vector:60,
from interval.h:4,
from vertex.h:4,
from ellipse-graph.h:4,
from server.cpp:1:
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/type_traits: In instantiation of 'struct std::make_unsigned<double>':
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/random.tcc:884:57: required from 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&, const std::uniform_int_distribution<_IntType>::param_type&) [with _UniformRandomNumberGenerator = std::linear_congruential_engine<long unsigned int, 16807ul, 0ul, 2147483647ul>; _IntType = double; std::uniform_int_distribution<_IntType>::result_type = double]'
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/bits/random.h:1770:51: required from 'std::uniform_int_distribution<_IntType>::result_type std::uniform_int_distribution<_IntType>::operator()(_UniformRandomNumberGenerator&) [with _UniformRandomNumberGenerator = std::linear_congruential_engine<long unsigned int, 16807ul, 0ul, 2147483647ul>; _IntType = double; std::uniform_int_distribution<_IntType>::result_type = double]'
server.cpp:20:40: required from here
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/type_traits:1531:62: error: invalid use of incomplete type 'class std::__make_unsigned_selector<double, false, false>'
{ typedef typename __make_unsigned_selector<_Tp>::__type type; };
^
/auto/pkg/gcc-4.8.1/share/gcc481/include/c++/4.8.1/type_traits:1495:11: error: declaration of 'class std::__make_unsigned_selector<double, false, false>'
class __make_unsigned_selector;
^
It appears the issue is the header. When I look here https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x, at "26.5", it appears that gcc 4.8.1 doesn't support random number generation, unless I'm interpreting this incorrectly. How might I compile this file?
The following example
// file mysort.cc
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
void mysort (const char**tab, unsigned size) {
std::vector<int> vecix;
vecix.resize(size);
struct CompareIndex {
const char**t;
CompareIndex(const char**p) : t(p) {};
bool operator() (int l, int r) {
return strcmp(t[l], t[r])<0;
}
};
CompareIndex compix(tab);
for (unsigned ix=0; ix<size; ix++) vecix[ix] = ix;
std::stable_sort(vecix.begin(), vecix.end(), compix);
std::vector<const char*> vecstr;
vecstr.resize(size);
for (unsigned ix=0; ix<size; ix++) vecstr[ix] = tab[vecix[ix]];
for (unsigned ix=0; ix<size; ix++) tab[ix] = vecstr[ix];
}
fails to compile (using GCC 4.8.2 on Debian/Sid/x86-64 in C++03 standard)
mysort.cc: In function 'void mysort(const char**, unsigned int)':
mysort.cc:19:58: error: no matching function for call to
'stable_sort(std::vector<int>::iterator,
std::vector<int>::iterator,
mysort(const char**, unsigned int)::CompareIndex&)'
std::stable_sort(vecix.begin(), vecix.end(), compix);
^
In file included from /usr/include/c++/4.8/algorithm:62:0,
from mysort.cc:4:
/usr/include/c++/4.8/bits/stl_algo.h:5682:5: note:
template<class _RAIter, class _Compare>
void std::stable_sort(_RAIter, _RAIter, _Compare)
stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
^
/usr/include/c++/4.8/bits/stl_algo.h:5682:5: note:
template argument deduction/substitution failed:
mysort.cc: In substitution of 'template<class _RAIter, class _Compare>
void std::stable_sort(_RAIter, _RAIter, _Compare)
[with _RAIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >;
_Compare = mysort(const char**, unsigned int)::CompareIndex]':
mysort.cc:19:58: required from here
mysort.cc:19:58: error: template argument for
'template<class _RAIter, class _Compare>
void std::stable_sort(_RAIter, _RAIter, _Compare)'
uses local type 'mysort(const char**, unsigned int)::CompareIndex'
std::stable_sort(vecix.begin(), vecix.end(), compix);
^
mysort.cc:19:58: error: trying to instantiate
'template<class _RAIter, class _Compare>
void std::stable_sort(_RAIter, _RAIter, _Compare)'
The above was compiled with GCC 4.8 using
g++ -Wall -c mysort.cc
I am getting the same error with
g++ -std=c++03 -Wall -c mysort.cc
or with
g++ -std=c++98 -Wall -c mysort.cc
but no errors with
g++ -std=c++11 -c mysort.cc
given that my g++ -v is a gcc version 4.8.2 (Debian 4.8.2-12)
but with Clang/LLVM 3.4 compiling with
clang++ -Wall -c mysort.cc
I'm getting only a warning:
mysort.cc:19:7: warning: template argument uses local
type 'CompareIndex'
[-Wlocal-type-template-args]
std::stable_sort(vecix.begin(), vecix.end(), compix);
^~~
1 warning generated.
(and I still get only a warning not an error when passing -std=c++03 or -std=c++98 to clang++ but no warnings with clang++ -std=c++11)
so my question is: why the error by GCC and the warning by Clang? Is my code legal and without undefined behavior (w.r.t. the C++03 standard)? Should I make my CompareIndex a global struct in my compilation unit?
motivations
Of course, this is a silly way to sort an array of C strings.
The real code is a bit different. In fact, I am trying to use std::stable_sort in my MELT plugin (a domain specific language to extend and customize GCC). MELT is generating C++ code and has a copying garbage collector (so pointers are moved by the GC). Hence, I need to sort using an array of indexes: the compare function in fact calls a MELT closure (which could trigger the copying GC at arbitrary moment), so I need to sort by indexes (and not by raw pointers). I want to keep the C++ code generated by MELT conforming to the C++ standard (03 or 98) required to compile GCC.
work-around
Thanks to juanchopanza's answer I've solved the issue by moving the declaration of CompareIndex at global scope before mysort.
I just committed the svn revision 206748 of the MELT branch of GCC; its file gcc/melt/warmelt-base.melt contains now a multiple_sort_new MELT function (to replace multiple_sort when it is working well) using std::stable_sort, and a global Melt_Sort_Compare_Index class in the generated C++ code.
Using local types as template arguments is not allowed in C++03.
From ISO/IEC 14882, 14.3.1 Template type arguments [temp.arg.type]:
A local type, a type with no linkage, an unnamed type or a type
compounded from any of these types shall not be used as a
template-argument for a template type-parameter.
The example given is along these lines:
template <typename T> struct Foo {};
void foo()
{
struct Bar {};
Foo<Bar> b1; // error: local type used as template-argument
Foo<Bar*> x4; // error: pointer to local type used as template-argument
}
This restriction has been lifted in C++11.
Sorry for my english.
I try to add iperf3 (like static link library) to my Qt project (Qt version 4.8.5, OpenSuse 13.1), and has several errors:
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../lperftest -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I../lperf/include -I. -I../lperftest -I. -o main.o ../lperftest/main.cpp
In file included from /usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:41:0,
from /usr/include/c++/4.8/bits/localefwd.h:40,
from /usr/include/c++/4.8/string:43,
from /usr/include/QtCore/qstring.h:54,
from /usr/include/QtCore/qobject.h:48,
from /usr/include/QtCore/QObject:1,
from ../lperftest/main.cpp:9:
/usr/include/c++/4.8/clocale:53:11: error: '::lconv' has not been declared
using ::lconv;
^
/usr/include/c++/4.8/clocale:54:11: error: '::setlocale' has not been declared
using ::setlocale;
^
/usr/include/c++/4.8/clocale:55:11: error: '::localeconv' has not been declared
using ::localeconv;
^
In file included from /usr/include/c++/4.8/bits/localefwd.h:40:0,
from /usr/include/c++/4.8/string:43,
from /usr/include/QtCore/qstring.h:54,
from /usr/include/QtCore/qobject.h:48,
from /usr/include/QtCore/QObject:1,
from ../lperftest/main.cpp:9:
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:52:23: error: 'uselocale' was not declared in this scope
extern "C" __typeof(uselocale) __uselocale;
^
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:52:45: error: invalid type in declaration before ';' token
extern "C" __typeof(uselocale) __uselocale;
^
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h: In function 'int std::__convert_from_v(__locale_struct* const&, char*, int, const char*, ...)':
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:75:53: error: '__gnu_cxx::__uselocale' cannot be used as a function
__c_locale __old = __gnu_cxx::__uselocale(__cloc);
^
/usr/include/c++/4.8/x86_64-suse-linux/bits/c++locale.h:100:33: error: '__gnu_cxx::__uselocale' cannot be used as a function
__gnu_cxx::__uselocale(__old);
^
../lperftest/main.cpp: At global scope:
../lperftest/main.cpp:11:5: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char *argv[])
^
../lperftest/main.cpp:11:5: warning: unused parameter 'argv' [-Wunused-parameter]
make: *** [main.o] Error 1
When i try to add iperf3 to the only C++ project all is good. This error exist only in Qt project. Is any idea?
I have the same problem with iperf3 and Qt. Basically it seems that you have to use similar compilation for iperf3 library and your project (both gcc or both g++).
Let us know how it goes. Or share your solution if already done.
-- edit --
or do the following for iperf_api.h
extern "C" {
#include <iperf_api.h>
}
I'm trying to write a container class using C++ and templates. However, I'm having a compilation error I don't understand...
The variable elems is a private vector, declaration is:
private:
vector<DataType> elems;
The vector is a custom vector. Its constructor is:
vector::vector(int init_capacity) : vect_capacity(init_capacity), vect_size(0), vect_elems(NULL){
assert(init_capacity >= 0);
if (init_capacity > 0){
vect_elems = new Object[init_capacity];
}
}
The constructor can be seen below:
template <class DataType>
bag<DataType>::bag(int init_capacity) : elems(init_capacity) {
}
This code returns the following error:
../src/vector.h: In instantiation of ‘vector<DataType>::vector(int) [with DataType = int]’:
../src/bag.h:33:60: required from ‘bag<DataType>::bag(int) [with DataType = int]’
../src/bag_test.cpp:6:17: required from here
I honestly have no idea what could be possibly happening. Will be immensely grateful to anyone that can point me in the right direction...
Sorry for the very stupid question. It's true that the compiler does complain about this, but the code actually compiles. Thanks to #WhozCraig and #n.m who insisted that this wasn't an error, I noticed that it actually was building. Thanks! For future reference, I do post the whole message:
**** Build of configuration Debug for project ADS ****
make all
Building file: ../src/bag_test.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/bag_test.d" -MT"src/bag_test.d" -o "src/bag_test.o" "../src/bag_test.cpp"
In file included from ../src/bag_test.cpp:2:0:
../src/bag.h:23:66: warning: friend declaration ‘std::ostream& operator<<(std::ostream&, const bag<DataType>&)’ declares a non-template function [-Wnon-template-friend]
../src/bag.h:23:66: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here)
In file included from ../src/bag.h:2:0,
from ../src/bag_test.cpp:2:
../src/vector.h: In instantiation of ‘vector<DataType>::vector(int) [with DataType = int]’:
../src/bag.h:34:53: required from ‘bag<DataType>::bag(int) [with DataType = int]’
../src/bag_test.cpp:6:17: required from here
../src/vector.h:100:6: warning: ‘vector<int>::vect_capacity’ will be initialized after [-Wreorder]
../src/vector.h:99:6: warning: ‘int vector<int>::vect_size’ [-Wreorder]
../src/vector.h:108:1: warning: when initialized here [-Wreorder]
Finished building: ../src/bag_test.cpp
Building target: ADS
Invoking: GCC C++ Linker
g++ -o "ADS" ./src/bag_test.o
Finished building target: ADS
**** Build Finished ****