Starting with wxWidgets and C++ - c++

I am trying to understand how wxWidgets actually works. I want to build a C++ GUI app on OSX 10.11.1 just to learn C++.
Now I got wxWidgets from https://www.wxwidgets.org/downloads/ and I got the Linux/OSX version.
I extracted the source and run ./configure && make && make install as I saw from one question in here.
It seemed to have gone on for a while then I got this:
`In file included from ./include/wx/variant.h:401:
./include/wx/any.h:611:5: warning: expression with side effects will be evaluated despite being used as an operand to 'typeid' [-Wpotentially-evaluated-expression]
WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplVariantData)
^
./include/wx/any.h:167:25: note: expanded from macro 'WX_DECLARE_ANY_VALUE_TYPE'
return wxTypeId(*sm_instance.get()) == wxTypeId(*otherType); \
^
./include/wx/typeinfo.h:84:47: note: expanded from macro 'wxTypeId'
#define wxTypeId(OBJ) wxTypeIdentifier(typeid(OBJ).name())
^
./src/osx/webview_webkit.mm:381:37: warning: incompatible pointer types sending 'WebViewLoadDelegate *' to parameter of type 'id<WebFrameLoadDelegate>' [-Wincompatible-pointer-types]
[m_webView setFrameLoadDelegate:loadDelegate];
^~~~~~~~~~~~
./src/osx/webview_webkit.mm:387:34: warning: incompatible pointer types sending 'WebViewPolicyDelegate *' to parameter of type 'id<WebPolicyDelegate>' [-Wincompatible-pointer-types]
[m_webView setPolicyDelegate:policyDelegate];
^~~~~~~~~~~~~~
./src/osx/webview_webkit.mm:392:30: warning: incompatible pointer types sending 'WebViewUIDelegate *' to parameter of type 'id<WKUIDelegate> _Nullable' [-Wincompatible-pointer-types]
[m_webView setUIDelegate:uiDelegate];
^~~~~~~~~~
./src/osx/webview_webkit.mm:464:34: warning: 'WKPreferences' may not respond to 'setUsesPageCache:'
[[m_webView preferences] setUsesPageCache:NO];
~~~~~~~~~~~~~~~~~~~~~~~ ^
./src/osx/webview_webkit.mm:466:34: warning: 'WKPreferences' may not respond to 'setUsesPageCache:'
[[m_webView preferences] setUsesPageCache:YES];
~~~~~~~~~~~~~~~~~~~~~~~ ^
./src/osx/webview_webkit.mm:936:25: error: cannot initialize a variable of type 'WebBackForwardList *' with an rvalue of type 'WKBackForwardList *'
WebBackForwardList* history = [m_webView backForwardList];
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/osx/webview_webkit.mm:954:25: error: cannot initialize a variable of type 'WebBackForwardList *' with an rvalue of type 'WKBackForwardList *'
WebBackForwardList* history = [m_webView backForwardList];
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 warnings and 2 errors generated.
make: *** [webviewdll_osx_webview_webkit.o] Error 1`
and it failed.
I have no idea how to fix it.
Is there an easier alternative I can use?
Also another question that I do not seem to get:
1 - It says it is cross platform. I thought by saying that then there would be 1 source folder that will compile differently on each platform, and not have source code for each platform.
2 - Also, where does it install? will it become part of my os libraries and I would be able to just use it in any c++ program I write?
3 - How can I then move my program to another OSX machine? Will I have to build a self-contained app (like in Java) or will that machine need to have the same wxWidgets version as my machine on which the program was developed?

There are many questions there, it would probably be better to ask each one separately, but let me try to briefly address all of them.
The problem you see is due to an incompatible changes in OS X SDK since the last wxWidgets release, as you could have found out if you searched wxTrac and found this bug. As you can also see there, it's fixed since quite some time, so all you need to do is to get the latest version from GitHub. Alternatively, you can build with older SDK but this is not recommended.
Next:
It is cross-platform because you can write a single version of code that compiles and works on multiple platforms. It's obviously impossible to avoid platform-specific code completely, wxWidgets just encapsulates it for you, so that you don't have to write it.
It installs under /usr/local by default as any Unix library, but this can be changed using --prefix option when running configure.
You should include wxWidgets libraries with your program. The simplest way to do it is to link to them statically. Slightly more involved is to put the shared libraries in your application bundle.

Related

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.

OSX What does "error: cannot convert 'const std::__cxx11::basic_string<char>" mean?

I am compiling a friend's code on my machine, and I keep getting hit with this error:
$ mpic++ dummy_file_name.cpp
dummy_file_name.cpp: In member function 'bool dummy_name1::dummy_name2::python_convert(const StringMultiArray&, PyObject**)':
dummy_file_name.cpp:430:55:error: cannot convert 'const std::__cxx11::basic_string<char>' to 'const char*' for argument '1' to 'PyObject* PyString_FromString(const char*)'
PyList_SetItem(*dst, i, PyString_FromString(src[i]));
What does this mean? How can I diagnose or treat this issue? I am using the mpic++ compiler. I have tried googling this error but I have not found any fruitful information.
Here is how I built my environment:
brew reinstall gcc --without-multilib
export HOMEBREW_CC=gcc-5
export HOMEBREW_CXX=g++-5
brew install openmpi --build-form-source
brew install llvm --with-clang
It's saying it can't convert const std::__cxx11::basic_string<char> AKA const std::string to const char*. This is a proper error for the compiler to report. As stated above you could fix this by using c_str(), but that would be an awful hack, and maybe violate some component's open source license.
As to why you are getting this error, it may be a mixup with the standard standard c++ libraries. You appear to be using gcc for openmpi and llvm for the link step which is very odd. In addition, you are forcing c++11 for gcc, but not for llvm.
Where did you get these build instructions? You may want to lookup an updated set of instructions.

C++ : Unit testing using Google Mock with Code::Blocks, MinGW and C++11

I've been trying to learn unit testing on my own following along a book.
Code in the book use the C++11 standard and have a line like this:
auto variable = function(parameter);
When I first compiled it I got this warning:
warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
No biggie, I could fix that by checking the following box in the Project->Build options... menu:
[ ] Have g++ follow the C++ 11 ISO C++ language standard [-std=c++11]
Now, however, I get new errors related to Google Mock in the gtest-port.h :
| | In function 'int testing::internal::posix::StrCaseCmp(const char*, const char*)':
|1719| error: '_stricmp' was not declared in this scope
| | In function 'char* testing::internal::posix::StrDup(const char*)':
|1721| error: '_strdup' was not declared in this scope
| | In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':|
|1779| error: 'fdopen' was not declared in this scope
Searching for this problem yielded little for me but I did try and define the target OS as it was a suggested solution in case it was not correctly identified automatically. Adding GTEST_OS_WINDOWS=1 and/or GTEST_OS_WINDOWS_DESKTOP=1 in the projects defines changed nothing.
I realize this is easily fixed in this instance by just providing the correct type instead of using auto but I'd like to find a solution for this if possible. Replacing auto and not having the -std=c++11 option checked makes the code work as intended so the library works.
I'm using Code::Blocks 13.12 , MinGW/g++ 4.8.1-4 and Google Mock 1.7 in Windows.
Thanks for reading =)
The answer here lies in the functions which are missing declarations: _stricmp, _strdup and fdopen. The first two are Microsoft versions of the POSIX functions stricmp and strdup. Note that you are specifying the use of the C++11 ISO standard which does not contain items in the POSIX standard. By specifying --std=gnu++11 you are telling the compiler to accept a hybrid of C++11 and POSIX along with GNU extensions.
Interestingly I cannot replicate this with GCC 4.8.2 on Linux so there is the possibility that something else is going on in the Google Mock headers when compiling on Windows.
Answering for anyone still facing the same issue:
The source of this issue might be in your CMakeLists file.
Set your compiler flags to -std=gnu++ instead of -std=c++
One way to do it would be to include
set(CMAKE_CXX_FLAGS "-std=gnu++0x")
to your CMakeLists file.

Is GLM compataible with GLload and GCC

I am currently getting my OpenGL 'framework' set up, and have settled on using GLload, mostly for the extension loading, but it has the added benefit of proving a proper 'gl' name space. As such, al gl* functions are instead used as gl::* for example:
glUniformMatrix4fv(...) // instead of this
gl::UniformMatrix4fv(...) // use this
I also want to make use of glm, which from my understanding, should be as simple as include glm/glm.hpp and ensure I tell my compiler where to find this. But it seems that it may not be compatible directly with glload, for I get the following errors when I try compile with it.
In file included from glm/glm/fwd.hpp:32:0,
from glm/glm/glm.hpp:91,
from src/main.cpp:3:
glm/glm/core/type_int.hpp:220:2: error: redefinition of ‘struct glm::detail::is_int<long int>’
glm/glm/core/type_int.hpp:219:2: error: previous definition of ‘struct glm::detail::is_int<long int>’
glm/glm/core/type_int.hpp:250:2: error: redefinition of ‘struct glm::detail::is_uint<long unsigned int>’
glm/glm/core/type_int.hpp:249:2: error: previous definition of ‘struct glm::detail::is_uint<long unsigned int>’
From looking at type_int.hpp you can see that it using a macro, first to with 'signed long' and 'unsigned long' respectively, then with 'highp_int_t' and 'highp_uint_t' (causing this error). These two redefining types are 'int64' and 'uint64', which exact types are dependent on compiler. As I am using GCC I believe means I should see these types as 'signed long long' and 'usigned long long'.
If I do comment out these two lines, everything seems to compile just fine. Of course, I am sure sooner or later it will turn out I broke something by doing so.
Looking up similar questions took me to this answer, that basically says glm does not support being built with -std=C++11, which for me is not acceptable; but this answer is nearly two years old, and glm's site does claim full C++11 compatibility.
And for reference, I am using gcc version 4.7.3, glm version 0.9.5 (as pulled from the github repo), glload from version 0.4.4 of glsdk (I have removed all other 'modules' of the glsdk, leaving me justglload).
Ok, it seems to be a problem with using version 0.9.5 of GLM.
Thankfully I had used a git submodule, so I was able to test with version 0.9.4 handy enough. It seems that version 0.9.4 is working just fine for me.

C++ Redis hiredis compiler error?

Thanks to someone on this site, I was able to use a sample C++ source file.
https://gist.github.com/1893378
When I compile this, I get a bunch of strange compiler errors:
/home/.../workspace/redis-hiredis-3c46b13/pipelineTest.cpp: In function ‘void redisTop(redisContext*)’:
/home/.../workspace/redis-hiredis-3c46b13/pipelineTest.cpp:142:32: error: invalid conversion from ‘void*’ to ‘redisReply*’
/home/../workspace/redis-hiredis-3c46b13/pipelineTest.cpp:162:25: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long int’
/home/=.../workspace/redis-hiredis-3c46b13/pipelineTest.cpp: In function ‘int main(int, char**)’:
I realize I may be out of synch with hiredis libray but I am using the latest one. Any ideas how to properly build this C++ program?
Also, I am looking for a complete C++ tutorial of pipeline with Redis. Here is a really good example in Java:
http://www.cafebabe.me/2011/05/redis-pipelines-and-transactions.html
Is there no example tutorial like this for C++?
Thanks either way
Actually, it is a C program, not C++. The C++ compiler is usually more pedantic that a C compiler, and it complains. Minor adaptations are needed to compile with a C++ compiler.
I did them, and put the file online again:
https://gist.github.com/1893378
It now compiles fine with g++ 3.4 and 4.3
AFAIK, there is no C++ tutorial for Redis. I think the best way to deal with Redis in C++ is to develop your own wrapping classes on top of hiredis. It is not that hard.
Just cast redisCommand to redisReply
reply = (redisReply *)redisCommand(context, "PING");
This is a C program. You have to build it with a C compiler.