Issue compiling c++ source - c++

I have a problem compiling a C++ program and I tried to find the issue and solve it but currently I wasn't able to find the source of the problem. I will appreciate if someone give me a hand :)
The error given is: (compiling under Centos 6.3 with gcc 4.4.7)
In file included from /home/server/Sources/MOP/MistCore/src/server/scripts/PrecompiledHeaders/ScriptPCH.h:25,
from /home/server/Sources/MOP/MistCore/src/server/game/Anticheat/AnticheatMgr.h:7,
from /home/server/Sources/MOP/MistCore/src/server/game/Anticheat/AnticheatData.h:4,
from /home/server/Sources/MOP/MistCore/src/server/game/Anticheat/AnticheatData.cpp:1:
/home/server/Sources/MOP/MistCore/src/server/game/Spells/SpellScript.h: In constructor ‘AuraScript::AuraScript()’:
/home/server/Sources/MOP/MistCore/src/server/game/Spells/SpellScript.h:619: error: no matching function for call to ‘std::shared_ptr<Aura>::shared_ptr(NULL)’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/shared_ptr.h:1263: note: candidates are: std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Tp>&&) [with _Tp = Aura]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/shared_ptr.h:1238: note: std::shared_ptr<_Tp>::shared_ptr() [with _Tp = Aura]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/shared_ptr.h:1236: note: std::shared_ptr<Aura>::shared_ptr(const std::shared_ptr<Aura>&)
make[2]: *** [src/server/game/CMakeFiles/game.dir/Anticheat/AnticheatData.cpp.o] Error 1
make[1]: *** [src/server/game/CMakeFiles/game.dir/all] Error 2
make: *** [all] Error 2
Files:
SpellScript.cpp: http://pastebin.com/Cam59CWt
SpellScript.h: http://pastebin.com/XYp6pSf9
Yeah, it's a long piece of code.

According to this site, std::shared_ptr was introduced in C++11.
Compiling C++11 with GCC requires it's version 4.7 or later.
Note that MistCore is based on the TrinityCore, that instead of using a C++11 specific define named AuraPtr uses a simple Aura* pointer. Reverting this to the original state should work just as it used to in the original project.
You can simply edit /src/server/game/SharedPtrs/SharedPtrs.h and undo the need of std::shared_ptr by replacing the defines with simple pointers. No guarantee that it will solve all problems though. Exemple.

You can specifi the flag using -std=c++11

Related

how to change source code in opencv?

I am trying to change the opencv svm predict function by passing an extra variable called std::pair & ,so that I can get the class label as well as decision function value from that function. I have change the source code in /home/rakib/opencv-2.4.9/modules/ml/src/svm.cpp and also add the function declaration in header file. The problem is that when I rebuild opencv I got the following error.
Scanning dependencies of target opencv_python
[ 75%] Building CXX object modules/python/CMakeFiles/opencv_python.dir/src2/cv2.cpp.o
In file included from /home/rakib/opencv-2.4.9/modules/python/src2/cv2.cpp:1129:0:
/home/rakib/opencv-2.4.9/build/modules/python/pyopencv_generated_types.h: In function ‘PyObject* pyopencv_CvSVM_predict(PyObject*, PyObject*, PyObject*)’:
/home/rakib/opencv-2.4.9/build/modules/python/pyopencv_generated_types.h:4878:5: error: ‘pair_double_and_double’ was not declared in this scope
pair_double_and_double labConCount;
^
/home/rakib/opencv-2.4.9/build/modules/python/pyopencv_generated_types.h:4878:28: error: expected ‘;’ before ‘labConCount’
pair_double_and_double labConCount;
^
/home/rakib/opencv-2.4.9/build/modules/python/pyopencv_generated_types.h:4885:40: error: ‘labConCount’ was not declared in this scope
pyopencv_to(pyobj_labConCount, labConCount, ArgInfo("labConCount", 0)) &&
^
make[2]: *** [modules/python/CMakeFiles/opencv_python.dir/src2/cv2.cpp.o] Error 1
make[1]: *** [modules/python/CMakeFiles/opencv_python.dir/all] Error 2
make: *** [all] Error 2
Though I want to change the c++ code of opencv but it some how related to python opencv interface so far I understood.
So any help to fix this problem is greatly appreciated.
If you change the source and would like to see the change in python as well, you'll also need to regenerate the python bindings.
See here for more details.
The problem is solved by using cmake -D BUILD_NEW_PYTHON_SUPPORT=OFF

Compiling QTermWidget

I've tried to compile this custom QT widget to provide a terminal that I can embed into my application. I've compiled/installed the build tools for the program that I needed before Cmake would complete, but the make step is throwing errors that google hasn't been too helpful on:
[ 50%] Building CXX object CMakeFiles/qtermwidget5.dir/lib/kpty.cpp.o
/Users/a7c/qtermwidget/qtermwidget-master/lib/kpty.cpp:506:26: error: no member named 'ut_name' in 'utmpx'
strncpy(l_struct.ut_name, user, sizeof(l_struct.ut_name));
~~~~~~~~ ^
/Users/a7c/qtermwidget/qtermwidget-master/lib/kpty.cpp:506:57: error: no member named 'ut_name' in 'utmpx'
strncpy(l_struct.ut_name, user, sizeof(l_struct.ut_name));
~~~~~~~~ ^
/Users/a7c/qtermwidget/qtermwidget-master/lib/kpty.cpp:617:20: error: no member named 'ut_name' in 'utmpx'
memset(ut->ut_name, 0, sizeof(*ut->ut_name));
~~ ^
/Users/a7c/qtermwidget/qtermwidget-master/lib/kpty.cpp:617:44: error: no member named 'ut_name' in 'utmpx'
memset(ut->ut_name, 0, sizeof(*ut->ut_name));
~~ ^
4 errors generated.
make[2]: *** [CMakeFiles/qtermwidget5.dir/lib/kpty.cpp.o] Error 1
make[1]: *** [CMakeFiles/qtermwidget5.dir/all] Error 2
make: *** [all] Error 2
Does anyone have a solution to this problem?
And as an extension, how exactly does one effectively include a custom widget as to be usable in QT Creator?
http://pubs.opengroup.org/onlinepubs/7908799/xsh/utmpx.h.html
It looks like it doesn't include ut_name in the stock version of utmpx.h.
If you look at this version of it:
https://code.woboq.org/kde/include/bits/utmp.h.html
They have a "backwards compatibility hack" in there:
87 /* Backwards compatibility hacks. */
88 #define ut_name ut_user
You may want to upgrade that library that includes that header. Or just insert that #define in your code. And as a good github citizen, if it works, you should do a pull request and/or submit an issue about it so that the next person using that library doesn't run into the same issue.
Hope that helps.
I don't know why the problem happened, since according to all the files I checked everything was named properly.
Adding #define ut_user ut_name to kpty.h solved the problem though.

Unexpected behavior of make -I [duplicate]

I've tried to compile this custom QT widget to provide a terminal that I can embed into my application. I've compiled/installed the build tools for the program that I needed before Cmake would complete, but the make step is throwing errors that google hasn't been too helpful on:
[ 50%] Building CXX object CMakeFiles/qtermwidget5.dir/lib/kpty.cpp.o
/Users/a7c/qtermwidget/qtermwidget-master/lib/kpty.cpp:506:26: error: no member named 'ut_name' in 'utmpx'
strncpy(l_struct.ut_name, user, sizeof(l_struct.ut_name));
~~~~~~~~ ^
/Users/a7c/qtermwidget/qtermwidget-master/lib/kpty.cpp:506:57: error: no member named 'ut_name' in 'utmpx'
strncpy(l_struct.ut_name, user, sizeof(l_struct.ut_name));
~~~~~~~~ ^
/Users/a7c/qtermwidget/qtermwidget-master/lib/kpty.cpp:617:20: error: no member named 'ut_name' in 'utmpx'
memset(ut->ut_name, 0, sizeof(*ut->ut_name));
~~ ^
/Users/a7c/qtermwidget/qtermwidget-master/lib/kpty.cpp:617:44: error: no member named 'ut_name' in 'utmpx'
memset(ut->ut_name, 0, sizeof(*ut->ut_name));
~~ ^
4 errors generated.
make[2]: *** [CMakeFiles/qtermwidget5.dir/lib/kpty.cpp.o] Error 1
make[1]: *** [CMakeFiles/qtermwidget5.dir/all] Error 2
make: *** [all] Error 2
Does anyone have a solution to this problem?
And as an extension, how exactly does one effectively include a custom widget as to be usable in QT Creator?
http://pubs.opengroup.org/onlinepubs/7908799/xsh/utmpx.h.html
It looks like it doesn't include ut_name in the stock version of utmpx.h.
If you look at this version of it:
https://code.woboq.org/kde/include/bits/utmp.h.html
They have a "backwards compatibility hack" in there:
87 /* Backwards compatibility hacks. */
88 #define ut_name ut_user
You may want to upgrade that library that includes that header. Or just insert that #define in your code. And as a good github citizen, if it works, you should do a pull request and/or submit an issue about it so that the next person using that library doesn't run into the same issue.
Hope that helps.
I don't know why the problem happened, since according to all the files I checked everything was named properly.
Adding #define ut_user ut_name to kpty.h solved the problem though.

make fails with error "cannot convert ‘std::istream {aka std::basic_istream<char>}’ to ‘bool’ in return"

I'm trying to compile libgtextutils (required by the fastxtoolkit) from source. The './configure' command runs nicely, however subsequent 'make' command produces an error that I cannot resolve.
text_line_reader.cpp: In member function ‘bool TextLineReader::next_line()’:
text_line_reader.cpp:47:9: error: cannot convert ‘std::istream {aka std::basic_istream<char>}’ to ‘bool’ in return
return input_stream ;
^~~~~~~~~~~~
make[3]: *** [text_line_reader.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
I'm on a Mac, OSX 10.11.6 (Intel)
Any suggestions that might solve this are highly appreciated.
See the Porting to GCC 6 guide, which documents this as one of the changes you must deal with due to GCC 6 defaulting to C++14 mode instead of C++03 mode:
Cannot convert 'std::ostream' to 'bool'
As of C++11, iostream classes are no longer implicitly convertible to void* so it is no longer valid to do something like:
bool valid(std::ostream& os) { return os; }
Such code must be changed to convert the iostream object to bool explicitly, e.g. return (bool)os; or return static_cast<bool>(os);
Another option is to explicitly use -std=c++03 in your compiler flags to compile in C++03 mode, but it's better to fix the code. The fixes given above will make the code compatible with any C++ version.
This is because of using a newer version of gcc compiler (C++11).
Use static_cast<bool>() to resolve the issue.
example: change
success = move_group.move();
to
success = static_cast<bool>(move_group.move());
Based on the answers of both Muthanna and Jonathan, for anyone with absolutely no knowledge of C++ but wanting to install fastx-toolkit on *unix and coming across these challenging responses, the answer is to run this after unpacking the source code:
cd libgtextutils-0.7
sed -i '47s/input_stream/static_cast<bool>(input_stream)/' src/gtextutils/text_line_reader.cpp
./configure
make
make install
This makes the change that the other, clearly far more knowledgeable, respondents suggest making, without having to understand a word that they're talking about. This should make it work for those of us who are just trying to get some old software to install and aren't looking to learn how to write C++ (just yet...)
Another option is to override the C++ flags in the make command:
make CXXFLAGS='-std=c++03 -O1'
As noted above, fastx will also have a compilation error but it will compile if you pass it
make CXXFLAGS=-O1.

Cross compiler error: reference 'm_memoryManager' cannot be decalred 'mutable' [-fpermissive]

I am compiling for Arm11 and use xalanc. I get a bunch of these:
In file included from /xx/include/xalanc/DOMSupport/DOMServices.hpp:39:0,
from /xx/include/xalanc/XPath/XObject.hpp:39:43,
from xy/MYxpath.cpp:7:
/...xx/include/xalanc/PlatformSupport/XSLException.hpp:199:29: error : reference 'm_memoryManager' cannot be decalred 'mutable' [-fpermissive]
make: *** [MyPath/MYxpath.arm-bcm2708hardfp-linux-gnueabi-gcc.Release.32.0] Error 1
Any idea?
EDIT_ Using gcc 4.7
This seems to be a a bug/configuration issue. You need to modify Xerces_autoconf_config.hpp to workaround it.