Hello World from cython wiki not working - c++

I'm trying to follow this tutorial from Cython: http://docs.cython.org/docs/tutorial.html#the-basics-of-cython and I'm having a problem.
The files are very simple. I have a helloworld.pyx:
print "Hello World"
and a setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("helloworld", ["helloworld.pyx"])]
)
and I compile it with the standard command:
python setup.py build_ext --inplace
I got the following error:
running build
running build_ext
building 'helloworld' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c helloworld.c -o build/temp.linux-x86_64-2.6/helloworld.o
helloworld.c:4:20: error: Python.h: No such file or directory
helloworld.c:5:26: error: structmember.h: No such file or directory
helloworld.c:34: error: expected specifier-qualifier-list before ‘PyObject’
helloworld.c:121: error: expected specifier-qualifier-list before ‘PyObject’
helloworld.c:139: error: expected ‘)’ before ‘*’ token
helloworld.c:140: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__pyx_PyInt_AsLongLong’
helloworld.c:141: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__pyx_PyInt_AsUnsignedLongLong’
helloworld.c:142: error: expected ‘)’ before ‘*’ token
helloworld.c:147: error: expected ‘)’ before ‘*’ token
helloworld.c:148: error: expected ‘)’ before ‘*’ token
helloworld.c:149: error: expected ‘)’ before ‘*’ token
helloworld.c:150: error: expected ‘)’ before ‘*’ token
helloworld.c:151: error: expected ‘)’ before ‘*’ token
helloworld.c:152: error: expected ‘)’ before ‘*’ token
helloworld.c:153: error: expected ‘)’ before ‘*’ token
helloworld.c:154: error: expected ‘)’ before ‘*’ token
helloworld.c:155: error: expected ‘)’ before ‘*’ token
helloworld.c:156: error: expected ‘)’ before ‘*’ token
helloworld.c:157: error: expected ‘)’ before ‘*’ token
helloworld.c:172: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:173: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:174: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:181: error: expected ‘)’ before ‘*’ token
helloworld.c:198: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:200: error: array type has incomplete element type
helloworld.c:221: error: ‘__pyx_kp_1’ undeclared here (not in a function)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:221: warning: excess elements in struct initializer
helloworld.c:221: warning: (near initialization for ‘__pyx_string_tab[0]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:222: warning: excess elements in struct initializer
helloworld.c:222: warning: (near initialization for ‘__pyx_string_tab[1]’)
helloworld.c:237: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘inithelloworld’
helloworld.c:238: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘inithelloworld’
helloworld.c:305: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
helloworld.c:313: error: expected ‘)’ before ‘*’ token
helloworld.c:379:21: error: compile.h: No such file or directory
helloworld.c:380:25: error: frameobject.h: No such file or directory
helloworld.c:381:23: error: traceback.h: No such file or directory
helloworld.c: In function ‘__Pyx_AddTraceback’:
helloworld.c:384: error: ‘PyObject’ undeclared (first use in this function)
helloworld.c:384: error: (Each undeclared identifier is reported only once
helloworld.c:384: error: for each function it appears in.)
helloworld.c:384: error: ‘py_srcfile’ undeclared (first use in this function)
helloworld.c:385: error: ‘py_funcname’ undeclared (first use in this function)
helloworld.c:386: error: ‘py_globals’ undeclared (first use in this function)
helloworld.c:387: error: ‘empty_string’ undeclared (first use in this function)
helloworld.c:388: error: ‘PyCodeObject’ undeclared (first use in this function)
helloworld.c:388: error: ‘py_code’ undeclared (first use in this function)
helloworld.c:389: error: ‘PyFrameObject’ undeclared (first use in this function)
helloworld.c:389: error: ‘py_frame’ undeclared (first use in this function)
helloworld.c:392: warning: implicit declaration of function ‘PyString_FromString’
helloworld.c:399: warning: implicit declaration of function ‘PyString_FromFormat’
helloworld.c:412: warning: implicit declaration of function ‘PyModule_GetDict’
helloworld.c:412: error: ‘__pyx_m’ undeclared (first use in this function)
helloworld.c:415: warning: implicit declaration of function ‘PyString_FromStringAndSize’
helloworld.c:420: warning: implicit declaration of function ‘PyCode_New’
helloworld.c:429: error: ‘__pyx_empty_tuple’ undeclared (first use in this function)
helloworld.c:440: warning: implicit declaration of function ‘PyFrame_New’
helloworld.c:441: warning: implicit declaration of function ‘PyThreadState_GET’
helloworld.c:448: warning: implicit declaration of function ‘PyTraceBack_Here’
helloworld.c:450: warning: implicit declaration of function ‘Py_XDECREF’
helloworld.c: In function ‘__Pyx_InitStrings’:
helloworld.c:458: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c:460: error: ‘__Pyx_StringTabEntry’ has no member named ‘is_unicode’
helloworld.c:460: error: ‘__Pyx_StringTabEntry’ has no member named ‘is_identifier’
helloworld.c:461: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c:461: warning: implicit declaration of function ‘PyUnicode_DecodeUTF8’
helloworld.c:461: error: ‘__Pyx_StringTabEntry’ has no member named ‘s’
helloworld.c:461: error: ‘__Pyx_StringTabEntry’ has no member named ‘n’
helloworld.c:461: error: ‘NULL’ undeclared (first use in this function)
helloworld.c:462: error: ‘__Pyx_StringTabEntry’ has no member named ‘intern’
helloworld.c:463: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c:463: warning: implicit declaration of function ‘PyString_InternFromString’
helloworld.c:463: error: ‘__Pyx_StringTabEntry’ has no member named ‘s’
helloworld.c:465: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c:465: error: ‘__Pyx_StringTabEntry’ has no member named ‘s’
helloworld.c:465: error: ‘__Pyx_StringTabEntry’ has no member named ‘n’
helloworld.c:476: error: ‘__Pyx_StringTabEntry’ has no member named ‘p’
helloworld.c: At top level:
helloworld.c:485: error: expected ‘)’ before ‘*’ token
helloworld.c:494: error: expected ‘)’ before ‘*’ token
helloworld.c:500: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__pyx_PyInt_AsLongLong’
helloworld.c:516: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__pyx_PyInt_AsUnsignedLongLong’
helloworld.c:538: error: expected ‘)’ before ‘*’ token
helloworld.c:553: error: expected ‘)’ before ‘*’ token
helloworld.c:568: error: expected ‘)’ before ‘*’ token
helloworld.c:583: error: expected ‘)’ before ‘*’ token
helloworld.c:598: error: expected ‘)’ before ‘*’ token
helloworld.c:613: error: expected ‘)’ before ‘*’ token
helloworld.c:628: error: expected ‘)’ before ‘*’ token
helloworld.c:643: error: expected ‘)’ before ‘*’ token
helloworld.c:658: error: expected ‘)’ before ‘*’ token
helloworld.c:673: error: expected ‘)’ before ‘*’ token
helloworld.c:688: error: expected ‘)’ before ‘*’ token
error: command 'gcc' failed with exit status 1
I have python and cython installed from Ubuntu 9.04 repositories. I can't figure why the compiler can't find Python.h.
I tried doing:
cython helloworld.pyx
and then compiling the result manually with gcc:
gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.5 -o helloworld.so helloworld.c
and got the same exact error message.
Any clues?

Looks like you're missing some package like python_dev or the like -- Debian and derivatives (including Ubuntu) have long preferred to isolate everything that could possibly be of "developer"'s use from the parts of a package that are for "everybody"... a philosophical stance I could debate against (and have debated against, without much practical success, in mahy fora), but one that, sadly, can't just be ignored:-(

Oh damn... forget it...
I forgot to install the dev packages.
Duh. Stupid. Sorry guys.

Related

Getting errors when using ImGui with OpenGL

I have some code working in OpenGL and now I would like to use ImGui to make a GUI for my application.
When I tried to copy a one line code of ImGui to my project ImGui::CreateContext(); by including some of the header files of ImGui, it lasted by a hundred errors (due maybe to linking).
I'm working with Ubuntu 18 and I use a Makefile to compile the whole project
Some of the errors that I got when including imgui.h:
imgui/imgui.h:153:39: error: unknown type name ‘ImGuiInputTextCallbackData’; did you mean ‘ImGuiInputTextFlags’?
typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data);
^~~~~~~~~~~~~~~~~~~~~~~~~~
ImGuiInputTextFlags
imgui/imgui.h:154:35: error: unknown type name ‘ImGuiSizeCallbackData’
typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data);
^~~~~~~~~~~~~~~~~~~~~
imgui/imgui.h:179:5: error: expected specifier-qualifier-list before ‘ImVec2’
ImVec2() { x = y = 0.0f; }
^~~~~~
imgui/imgui.h:192:5: error: expected specifier-qualifier-list before ‘ImVec4’
ImVec4() { x = y = z = w = 0.0f; }
^~~~~~
imgui/imgui.h:204:1: error: unknown type name ‘namespace’; did you mean ‘isspace’?
namespace ImGui
^~~~~~~~~
isspace
imgui/imgui.h:205:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
{
^
In file included from window.c:23:0:
imgui/imgui.h:1200:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘new’
inline void* operator new(size_t, ImNewDummy, void* ptr) { return ptr; }
^~~
imgui/imgui.h:1201:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘delete’
inline void operator delete(void*, ImNewDummy, void*) {} // This is only required so we can use the symmetrical new()
^~~~~~
imgui/imgui.h:1206:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
template<typename T> void IM_DELETE(T* p) { if (p) { p->~T(); ImGui::MemFree(p); } }
^
imgui/imgui.h:1217:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
template<typename T>
^
imgui/imgui.h:1280:5: error: unknown type name ‘ImVec2’
ImVec2 WindowPadding; // Padding within a window.
When I run some examples that are provided, they work perfectly. However, when trying to merge my project with a single line of code of imgui, it ends up with the errors shown above.
Looking at the kind of errors you are getting, it seems to me that you are trying to compile your program with a C compiler. However, ImGui is written in C++.
For, example:
imgui/imgui.h:204:1: error: unknown type name ‘namespace’; did you mean ‘isspace’?
namespace ImGui
^~~~~~~~~
namespace is a C++ reserved keyword and your compiler doesn't seem to recognize it as such.
Since you mentioned that you are using MakeFile, try to find in that file what compiler you are using. If it says gcc, replace it by g++. If it's using clang, replace it by clang++.

Why does the following code work on online ide(gcc 7.2.0) but gives error on ubuntu?

When I run the following code on ubuntu(gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4)):
#include<iostream>
#include<vector>
#include<list>
using namespace std;
int main(){
vector <int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
v.push_back(5);
list<int> temp;
for(auto i:v){
cout<<i<<" ";
temp.push_back(i);
}
for(auto i:temp){
cout<<i<<" ";
}
}
I get the following errors:
try.cpp: In function ‘int main()’:
try.cpp:13:10: error: ‘i’ does not name a type
for(auto i:v){
^
try.cpp:17:1: error: expected ‘;’ before ‘for’
for(auto i:temp){
^
try.cpp:17:1: error: expected primary-expression before ‘for’
try.cpp:17:1: error: expected ‘;’ before ‘for’
try.cpp:17:1: error: expected primary-expression before ‘for’
try.cpp:17:1: error: expected ‘)’ before ‘for’
try.cpp:17:10: error: ‘i’ does not name a type
for(auto i:temp){
^
try.cpp:20:1: error: expected ‘;’ before ‘}’ token
}
^
try.cpp:20:1: error: expected primary-expression before ‘}’ token
try.cpp:20:1: error: expected ‘;’ before ‘}’ token
try.cpp:20:1: error: expected primary-expression before ‘}’ token
try.cpp:20:1: error: expected ‘)’ before ‘}’ token
try.cpp:20:1: error: expected primary-expression before ‘}’ token
But when I run the code on online ide I works fine.
What is the problem with the code?
The link for code on online ide:No errors
Your code uses some of the C++11 features such as range based loops and auto specifier but you don't compile for the C++11 standard. You need to enable the C++11 support by including the -std=c++11 flag when compiling:
g++ -std=c++11 -o try try.cpp
The online compiler has this enabled by using the -std=gnu++1z flag.

Compiling mathgl sample c++

I have installed mathgl, using:
sudo apt-get install mathgl
sudo apt-get install libmgl-dev
When i tried to compile a sample c++ program from here
#include <mgl2/qt.h>
int sample(mglGraph *gr)
{
gr->Rotate(60,40);
gr->Box();
return 0;
}
//-----------------------------------------------------
int main(int argc,char **argv)
{
mglQT gr(sample,"MathGL examples");
return gr.Run();
}
using gcc sample.cpp -lmgl-qt -lmgl
i get compiler errors at mathgl functions.
lefteris#lefteris-ubuntu:~/Documents/C++/Numerical$ gcc sample.cpp -lmgl-qt -lmgl
In file included from /usr/include/mgl2/abstract.h:27:0,
from /usr/include/mgl2/qt.h:22,
from sample.cpp:1:
/usr/include/mgl2/type.h:42:20: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglPoint(mglPoint &&d):x(d.x),y(d.y),z(d.z),c(d.c) {}
^
/usr/include/mgl2/type.h:42:23: error: invalid constructor; you probably meant ‘mglPoint (const mglPoint&)’
mglPoint(mglPoint &&d):x(d.x),y(d.y),z(d.z),c(d.c) {}
^
/usr/include/mgl2/type.h:117:20: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglColor(mglColor &&d):r(d.r),g(d.g),b(d.b),a(d.a) {}
^
/usr/include/mgl2/type.h:117:23: error: invalid constructor; you probably meant ‘mglColor (const mglColor&)’
mglColor(mglColor &&d):r(d.r),g(d.g),b(d.b),a(d.a) {}
^
In file included from /usr/include/mgl2/mgl_cf.h:24:0,
from /usr/include/mgl2/mgl.h:23,
from /usr/include/mgl2/wnd.h:23,
from /usr/include/mgl2/qt.h:36,
from sample.cpp:1:
/usr/include/mgl2/data.h:49:18: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglData(mglData &&d):nx(d.nx),ny(d.ny),nz(d.nz),a(d.a),id(d.id),link(d.link)
^
/usr/include/mgl2/data.h:49:21: error: invalid constructor; you probably meant ‘mglData (const mglData&)’
mglData(mglData &&d):nx(d.nx),ny(d.ny),nz(d.nz),a(d.a),id(d.id),link(d.link)
^
/usr/include/mgl2/data.h:570:18: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglExpr(mglExpr &&d):ex(d.ex) { d.ex=0; }
^
/usr/include/mgl2/data.h:570:21: error: invalid constructor; you probably meant ‘mglExpr (const mglExpr&)’
mglExpr(mglExpr &&d):ex(d.ex) { d.ex=0; }
^
/usr/include/mgl2/data.h:601:20: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglDataV(mglDataV &&d):nx(d.nx),ny(d.ny),nz(d.nz),di(d.di),dj(d.dj),dk(d.dk),a0(d.a0)
^
/usr/include/mgl2/data.h:601:23: error: invalid constructor; you probably meant ‘mglDataV (const mglDataV&)’
mglDataV(mglDataV &&d):nx(d.nx),ny(d.ny),nz(d.nz),di(d.di),dj(d.dj),dk(d.dk),a0(d.a0)
^
/usr/include/mgl2/data.h:667:20: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglDataW(mglDataW &&d):nx(d.nx),ny(d.ny),nz(d.nz),di(d.di),dj(d.dj),dk(d.dk)
^
/usr/include/mgl2/data.h:667:23: error: invalid constructor; you probably meant ‘mglDataW (const mglDataW&)’
mglDataW(mglDataW &&d):nx(d.nx),ny(d.ny),nz(d.nz),di(d.di),dj(d.dj),dk(d.dk)
^
/usr/include/mgl2/data.h:741:20: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglDataF(mglDataF &&d):nx(d.nx),ny(d.ny),nz(d.nz), str(d.str), v1(d.v1),v2(d.v2), ex(d.ex), dx(d.dx),dy(d.dy),dz(d.dz), dfunc(d.dfunc),par(d.par)
^
/usr/include/mgl2/data.h:741:23: error: invalid constructor; you probably meant ‘mglDataF (const mglDataF&)’
mglDataF(mglDataF &&d):nx(d.nx),ny(d.ny),nz(d.nz), str(d.str), v1(d.v1),v2(d.v2), ex(d.ex), dx(d.dx),dy(d.dy),dz(d.dz), dfunc(d.dfunc),par(d.par)
^
/usr/include/mgl2/data.h:846:20: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglDataT(mglDataT &&d):dat(d.dat),ind(d.ind)
^
/usr/include/mgl2/data.h:846:23: error: invalid constructor; you probably meant ‘mglDataT (const mglDataT&)’
mglDataT(mglDataT &&d):dat(d.dat),ind(d.ind)
^
/usr/include/mgl2/data.h:893:20: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglDataR(mglDataR &&d):dat(d.dat),ind(d.ind)
^
/usr/include/mgl2/data.h:893:23: error: invalid constructor; you probably meant ‘mglDataR (const mglDataR&)’
mglDataR(mglDataR &&d):dat(d.dat),ind(d.ind)
^
In file included from /usr/include/mgl2/mgl_cf.h:25:0,
from /usr/include/mgl2/mgl.h:23,
from /usr/include/mgl2/wnd.h:23,
from /usr/include/mgl2/qt.h:36,
from sample.cpp:1:
/usr/include/mgl2/datac.h:50:20: error: expected ‘,’ or ‘...’ before ‘&&’ token
mglDataC(mglDataC &&d):nx(d.nx),ny(d.ny),nz(d.nz),a(d.a),id(d.id),link(d.link)
^
/usr/include/mgl2/datac.h:50:23: error: invalid constructor; you probably meant ‘mglDataC (const mglDataC&)’
mglDataC(mglDataC &&d):nx(d.nx),ny(d.ny),nz(d.nz),a(d.a),id(d.id),link(d.link)
^
i tried running the python sample, and it worked fine.
Does anyone know how to fix this problem?

Weird opencv compilation error

So all I am trying to do is compile my program with opencv-2.3 . This is all under the assumtion that I installed everything correctly.
My Main is super simple:
#include <iostream>
#include <opencv/cv.h>
int main(int argv, char** argc){
std::cout << "Hello World" << std::endl;
return 0;
}
My MakeFile is super simple.
g++ main.cpp `pkg-config opencv --cflags --libs`
And the error is really confusing:
make
g++ main.cpp \
`pkg-config opencv --cflags --libs`
In file included from /usr/include/c++/4.6/bits/stl_algo.h:62:0,
from /usr/include/c++/4.6/algorithm:63,
from /usr/local/include/opencv2/core/core.hpp:56,
from /usr/local/include/opencv/cv.h:64,
from main.cpp:8:
/usr/include/c++/4.6/bits/algorithmfwd.h:358:41: error: macro "max" passed 3 arguments, but takes just 2
/usr/include/c++/4.6/bits/algorithmfwd.h:369:41: error: macro "min" passed 3 arguments, but takes just 2
In file included from /usr/include/c++/4.6/bits/stl_algo.h:62:0,
from /usr/include/c++/4.6/algorithm:63,
from /usr/local/include/opencv2/core/core.hpp:56,
from /usr/local/include/opencv/cv.h:64,
from main.cpp:8:
/usr/include/c++/4.6/bits/algorithmfwd.h:354:5: error: expected unqualified-id before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:354:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:354:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:354:5: error: expected initializer before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:358:5: error: template declaration of ‘const _Tp& std::max’
/usr/include/c++/4.6/bits/algorithmfwd.h:365:5: error: expected unqualified-id before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:365:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:365:5: error: expected ‘)’ before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:365:5: error: expected initializer before ‘const’
/usr/include/c++/4.6/bits/algorithmfwd.h:369:5: error: template declaration of ‘const _Tp& std::min’
In file included from /usr/include/c++/4.6/algorithm:63:0,
from /usr/local/include/opencv2/core/core.hpp:56,
from /usr/local/include/opencv/cv.h:64,
from main.cpp:8:
/usr/include/c++/4.6/bits/stl_algo.h: In function ‘void std::__merge_sort_loop(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _Distance)’:
/usr/include/c++/4.6/bits/stl_algo.h:3285:26: error: expected unqualified-id before ‘(’ token
/usr/include/c++/4.6/bits/stl_algo.h: In function ‘void std::__merge_sort_loop(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _Distance, _Compare)’:
/usr/include/c++/4.6/bits/stl_algo.h:3308:26: error: expected unqualified-id before ‘(’ token
In file included from /usr/local/include/opencv2/core/core.hpp:59:0,
from /usr/local/include/opencv/cv.h:64,
from main.cpp:8:
/usr/include/c++/4.6/complex: In function ‘_Tp std::__complex_abs(const std::complex<_Tp>&)’:`
/usr/include/c++/4.6/complex:571:28: error: expected unqualified-id before ‘(’ token
In file included from /usr/include/c++/4.6/vector:65:0,
from /usr/local/include/opencv2/core/core.hpp:63,
from /usr/local/include/opencv/cv.h:64,
from main.cpp:8:
/usr/include/c++/4.6/bits/stl_vector.h: In member function ‘std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::_M_check_len(std::vector<_Tp, _Alloc>::size_type, const char*) const’:
/usr/include/c++/4.6/bits/stl_vector.h:1244:40: error: expected unqualified-id before ‘(’ token
In file included from /usr/include/c++/4.6/vector:66:0,
from /usr/local/include/opencv2/core/core.hpp:63,
from /usr/local/include/opencv/cv.h:64,
from main.cpp:8:
/usr/include/c++/4.6/bits/stl_bvector.h: In member function ‘std::vector<bool, _Alloc>::size_type std::vector<bool, _Alloc>::_M_check_len(std::vector<bool, _Alloc>::size_type, const char*) const’:
/usr/include/c++/4.6/bits/stl_bvector.h:1026:45: error: expected unqualified-id before ‘(’ token
Now when I hit pkg-config --cflags --libs opencv in the terminal I get the correct place where all the libs and the .hpp and other files. So I have no idea what is going on here.
Thanks for the help!!
It might be caused by using the old, C headers. The new ones are located in <opencv2/opencv.hpp> if I remember correctly.

Numerical Recipes v3.0 and pthread library in C++11

If I compile the following code with the command g++ -std=c++11 Threads.cpp -lpthread -I../Libs/nr30, where nr30 is the library provided by http://www.nr.com/, I obtain no errors:
#include <chrono>
#include <thread>
int main(void) {
/* ... Sadly, No further code in here was added... */
}
while if I add the #include "nr3.h" header in the same code as above, I obtain the following error:
In file included from /usr/include/c++/4.7/memory:76:0,
from /usr/include/c++/4.7/thread:40,
from random_test.cpp:34:
/usr/include/c++/4.7/ext/concurrence.h:73:5: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/ext/concurrence.h:72:5: error: looser throw specifier for ‘virtual const char* __gnu_cxx::__concurrence_lock_error::what() const’
In file included from /usr/include/c++/4.7/ios:40:0,
from /usr/include/c++/4.7/istream:40,
from /usr/include/c++/4.7/fstream:40,
from ../Libs/nr30/nr3.h:10,
from random_test.cpp:29:
/usr/include/c++/4.7/exception:70:25: error: overriding ‘virtual const char* std::exception::what() const noexcept (true)’
In file included from /usr/include/c++/4.7/memory:76:0,
from /usr/include/c++/4.7/thread:40,
from random_test.cpp:34:
/usr/include/c++/4.7/ext/concurrence.h: In member function ‘virtual const char* __gnu_cxx::__concurrence_lock_error::what() const’:
/usr/include/c++/4.7/ext/concurrence.h:72:18: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/ext/concurrence.h: At global scope:
/usr/include/c++/4.7/ext/concurrence.h:81:5: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/ext/concurrence.h:80:5: error: looser throw specifier for ‘virtual const char* __gnu_cxx::__concurrence_unlock_error::what() const’
In file included from /usr/include/c++/4.7/ios:40:0,
from /usr/include/c++/4.7/istream:40,
from /usr/include/c++/4.7/fstream:40,
from ../Libs/nr30/nr3.h:10,
from random_test.cpp:29:
/usr/include/c++/4.7/exception:70:25: error: overriding ‘virtual const char* std::exception::what() const noexcept (true)’
In file included from /usr/include/c++/4.7/memory:76:0,
from /usr/include/c++/4.7/thread:40,
from random_test.cpp:34:
/usr/include/c++/4.7/ext/concurrence.h: In member function ‘virtual const char* __gnu_cxx::__concurrence_unlock_error::what() const’:
/usr/include/c++/4.7/ext/concurrence.h:80:18: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/ext/concurrence.h: At global scope:
/usr/include/c++/4.7/ext/concurrence.h:89:5: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/ext/concurrence.h:88:5: error: looser throw specifier for ‘virtual const char* __gnu_cxx::__concurrence_broadcast_error::what() const’
In file included from /usr/include/c++/4.7/ios:40:0,
from /usr/include/c++/4.7/istream:40,
from /usr/include/c++/4.7/fstream:40,
from ../Libs/nr30/nr3.h:10,
from random_test.cpp:29:
/usr/include/c++/4.7/exception:70:25: error: overriding ‘virtual const char* std::exception::what() const noexcept (true)’
In file included from /usr/include/c++/4.7/memory:76:0,
from /usr/include/c++/4.7/thread:40,
from random_test.cpp:34:
/usr/include/c++/4.7/ext/concurrence.h: In member function ‘virtual const char* __gnu_cxx::__concurrence_broadcast_error::what() const’:
/usr/include/c++/4.7/ext/concurrence.h:88:18: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/ext/concurrence.h: At global scope:
/usr/include/c++/4.7/ext/concurrence.h:97:5: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/ext/concurrence.h:96:5: error: looser throw specifier for ‘virtual const char* __gnu_cxx::__concurrence_wait_error::what() const’
In file included from /usr/include/c++/4.7/ios:40:0,
from /usr/include/c++/4.7/istream:40,
from /usr/include/c++/4.7/fstream:40,
from ../Libs/nr30/nr3.h:10,
from random_test.cpp:29:
/usr/include/c++/4.7/exception:70:25: error: overriding ‘virtual const char* std::exception::what() const noexcept (true)’
In file included from /usr/include/c++/4.7/memory:76:0,
from /usr/include/c++/4.7/thread:40,
from random_test.cpp:34:
/usr/include/c++/4.7/ext/concurrence.h: In member function ‘virtual const char* __gnu_cxx::__concurrence_wait_error::what() const’:
/usr/include/c++/4.7/ext/concurrence.h:96:18: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/ext/concurrence.h: At global scope:
/usr/include/c++/4.7/ext/concurrence.h:309:5: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/ext/concurrence.h: In destructor ‘__gnu_cxx::__scoped_lock::~__scoped_lock()’:
/usr/include/c++/4.7/ext/concurrence.h:308:22: error: expected primary-expression before ‘,’ token
In file included from /usr/include/c++/4.7/memory:84:0,
from /usr/include/c++/4.7/thread:40,
from random_test.cpp:34:
/usr/include/c++/4.7/backward/auto_ptr.h: At global scope:
/usr/include/c++/4.7/backward/auto_ptr.h:90:12: error: invalid use of non-static data member ‘std::auto_ptr<_Tp>::_M_ptr’
/usr/include/c++/4.7/backward/auto_ptr.h:103:49: error: from this location
/usr/include/c++/4.7/backward/auto_ptr.h:103:56: error: ‘__p’ was not declared in this scope
/usr/include/c++/4.7/backward/auto_ptr.h:103:59: error: expected ‘;’ at end of member declaration
/usr/include/c++/4.7/backward/auto_ptr.h:103:61: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/backward/auto_ptr.h:90:12: error: invalid use of non-static data member ‘std::auto_ptr<_Tp>::_M_ptr’
/usr/include/c++/4.7/backward/auto_ptr.h:112:41: error: from this location
/usr/include/c++/4.7/backward/auto_ptr.h:112:48: error: ‘__a’ was not declared in this scope
/usr/include/c++/4.7/backward/auto_ptr.h:112:61: error: expected ‘;’ at end of member declaration
/usr/include/c++/4.7/backward/auto_ptr.h:112:63: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/backward/auto_ptr.h:90:12: error: invalid use of non-static data member ‘std::auto_ptr<_Tp>::_M_ptr’
/usr/include/c++/4.7/backward/auto_ptr.h:125:49: error: from this location
/usr/include/c++/4.7/backward/auto_ptr.h:125:56: error: ‘__a’ was not declared in this scope
/usr/include/c++/4.7/backward/auto_ptr.h:125:69: error: expected ‘;’ at end of member declaration
/usr/include/c++/4.7/backward/auto_ptr.h:125:71: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/backward/auto_ptr.h:137:7: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/backward/auto_ptr.h:155:9: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/backward/auto_ptr.h:182:7: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/backward/auto_ptr.h:195:7: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/backward/auto_ptr.h:211:27: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/backward/auto_ptr.h:226:7: error: expected unqualified-id before ‘{’ token
/usr/include/c++/4.7/backward/auto_ptr.h:241:7: error: expected unqualified-id before ‘{’ token
random_test.cpp:126:1: error: expected ‘}’ at end of input
In file included from /usr/include/c++/4.7/memory:84:0,
from /usr/include/c++/4.7/thread:40,
from random_test.cpp:34:
/usr/include/c++/4.7/backward/auto_ptr.h: In constructor ‘std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp>::element_type*)’:
/usr/include/c++/4.7/backward/auto_ptr.h:103:39: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: In copy constructor ‘std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp>&)’:
/usr/include/c++/4.7/backward/auto_ptr.h:112:31: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: In constructor ‘std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp1>&)’:
/usr/include/c++/4.7/backward/auto_ptr.h:125:39: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: In member function ‘std::auto_ptr<_Tp>& std::auto_ptr<_Tp>::operator=(std::auto_ptr<_Tp>&)’:
/usr/include/c++/4.7/backward/auto_ptr.h:136:32: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: In member function ‘std::auto_ptr<_Tp>& std::auto_ptr<_Tp>::operator=(std::auto_ptr<_Tp1>&)’:
/usr/include/c++/4.7/backward/auto_ptr.h:154:40: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: In member function ‘std::auto_ptr<_Tp>::element_type& std::auto_ptr<_Tp>::operator*() const’:
/usr/include/c++/4.7/backward/auto_ptr.h:181:25: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: In member function ‘std::auto_ptr<_Tp>::element_type* std::auto_ptr<_Tp>::operator->() const’:
/usr/include/c++/4.7/backward/auto_ptr.h:194:26: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: In member function ‘std::auto_ptr<_Tp>::element_type* std::auto_ptr<_Tp>::get() const’:
/usr/include/c++/4.7/backward/auto_ptr.h:211:19: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: In member function ‘std::auto_ptr<_Tp>::element_type* std::auto_ptr<_Tp>::release()’:
/usr/include/c++/4.7/backward/auto_ptr.h:225:17: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: In member function ‘void std::auto_ptr<_Tp>::reset(std::auto_ptr<_Tp>::element_type*)’:
/usr/include/c++/4.7/backward/auto_ptr.h:240:36: error: expected primary-expression before ‘,’ token
/usr/include/c++/4.7/backward/auto_ptr.h: At global scope:
/usr/include/c++/4.7/backward/auto_ptr.h:240:36: error: expected unqualified-id at end of input
/usr/include/c++/4.7/backward/auto_ptr.h:240:36: error: expected ‘}’ at end of input
make: *** [rtest] Error 1
Did you encounter the same problem? Thank you for any advice.
It looks like the authors of this library are defining their own exception classes and they forgot to mark the what() method as noexcept when the code is compiled with C++11 (or they are deriving from deprecated exception classes, e.g. TR1). This reproduces the problem:
#include <stdexcept>
struct my_exception : std::exception
{
const char* what() const { return "what"; }
};
int main()
{
}
and this fixes it:
#include <stdexcept>
struct my_exception : std::exception
{
const char* what() const noexcept { return "what"; }
// ^^^^^^^^
};
int main()
{
}
This means you either have to patch the library yourself (if you have access to the full source code) or you send them a bug report.
(you should still consider using -pthread instead of -lpthread, it's much cleaner and avoids further bugs)