Is GLM compataible with GLload and GCC - c++

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.

Related

Starting with wxWidgets and 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.

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.

Compile in c++14

So in my CSE course we are given a header file to use right now for our programs that we're writing.
Unfortunately I can't get terminal to compile using that header, it gives quite a few errors (compiling with just 'g++'). Also, when I'm at my university and I'm using PuTTY I get the same errors while using this header. However, I don't get the errors when I compile with 'g++ -std=c++14'.
I've tried compiling with this command on terminal on my mac, but it says it doesn't recognize the c++14 part.
dhcp-10-202-147-243:hw1pr1 Admin$ g++ -std=c++14 hw1pr1.cpp
error: invalid value 'c++14' in '-std=c++14'
Any help on how I could get this to work would be greatly appreciated. Hopefully this all made some sort of sense.
Here's the error I get when I compile with the header file I'm talking about in terminal with just g++.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ext/hash_map:212:5: warning:
Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>
[-W#warnings]
# warning Use of the header <ext/hash_map> is deprecated. Migrate to ...
^
In file included from read_first_name.cpp:1:
./std_lib_facilities_4.h:43:20: error: no matching function for call to object
of type 'hash<char *>'
return hash<char*>()(s.c_str());
^~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ext/__hash:39:12: note:
candidate function not viable: 1st argument ('const value_type *'
(aka 'const char *')) would lose const qualifier
size_t operator()(char *__c) const _NOEXCEPT
^
In file included from read_first_name.cpp:1:
./std_lib_facilities_4.h:112:8: warning: comparison of unsigned expression < 0
is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
./std_lib_facilities_4.h:118:8: warning: comparison of unsigned expression < 0
is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
3 warnings and 1 error generated.
This error doesn't happen and the program will compile fully when I use PuTTY and 'g++ std=c++14'
There's lots of change between C++ standards, so what is valid in one revision need not be in another.
g++ defaults to -std=gnu++98 for C++, which is the decades old C++98-standard enhanced with GNU extensions (most of which are conformant).
Choose the proper revision: -std=c++1y -pedantic is a very close approximation to C++14.
What changes introduced in C++14 can potentially break a program written in C++11?
Looking at what you say you're having to use and the name format of that .cpp file, I think I'm in the same class. A year later, looks like, but here's my solution for archive's sake:
The std_lib_facilities.h header comes with the Bjarne Stroustrup textbook, "Programming: Principles and Practices Using C++". For those unaware, Bjarne Stroustrup invented C++ (he has a pretty good idea what he's talking about). Incidentally, the book is a fantastic way to learn C++, if one takes the time to actually read it. The std_lib_facilities.h header is just a convenient header file for beginners in C++, containing links to all the major standard libraries used in the textbook, as well as some helper functions that help account for potential mistakes or errors, or are just convenient for learning (such as an error() function that handles simple exception throwing for the student, or adding an "out of bounds" check for vectors). It's ultimately just a way to allow students to hop right into code without having to learn specifics about the header.
Stroustrup keeps updated with C++ and thus includes several libraries that require the c++11 standard. The CSCE department wants its students (at least in this early class) to connect to the department's Unix system and compile from there, in order to avoid confusion with downloading and updating compilers.
I happened to already have had a couple C++ classes beforehand, and thus already had g++ set up on my Ubuntu laptop. I avoided including the std_lib_facilities for as long as possible since I was getting the same error as Topic Creator Joe, where g++ didn't recognize the "c++11" part (manually including the required libraries worked fine until we had to use a class from the textbook that used one of the header's helper functions) . Eventually, I found a help topic online that advised me simply to update my g++ compiler to 4.7 or higher, since 4.6 and lower doesn't have support for C++11 (or, of course, C++14). It was oddly rather involved compared to updates one might be used to on Mac or Windows, and I doubt the exact process would apply, but that is (was?) likely the problem: it's just an older version of g++, and it needs an update to compile C++11 and later. I recommend searching for ways to update g++/gcc for Mac.
Should, y'know, anyone else with this problem stumble upon this and not have their problem solved yet.

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.