Windows/opengl glext.h build issue - c++

So I'm trying to bring a c++ project using Qt and OpenGL written and compiled on a Linux machine over to my Windows 7 machine at home, but I'm running into some difficulty. First I learned that some gl things (like GL_TEXTURE0) were no longer defined because gl.h doesn't define them for windows. Also, the glext.h that I have does not define some functions like glActiveTexture. Both of these issues I found could be solved by bringing in a newer glext.h.
My most immediate issue seems to be that I'm not bringing it in correctly. If I do:
#define GL_GLEXT_LEGACY //should prevent old glext.h from being included
#define GL_GLEXT_PROTOTYPES //should make glActiveTexture be defined
#include <qgl.h>
#include "glext.h" //local up-to-date glext.h
#include <QGLShaderProgram>
then make tells me that I have undefined references to glActiveTexture. If I include QGLShaderProgram before glext.h, then I still have that problem, but make also warns me that I am redefining quite a few things that are defined in both QGLShaderProgram and glext, so I know the latter file is being included. Any help would really be appreciated.

You are on a right path, but like Nick Meyer wrote, you need to get pointers to the functions at runtime.
There is a nice and clean example already in Qt installation directory, at least since 4.6. Check "Boxes" from "demos"-directory. There is glextensions.h/cpp that takes care of those required functions in Qt-way, using Qt's QGLContext etc.

If you're lazy like me, just hop over to
http://glew.sourceforge.net
and use that, no need to fiddle around with different header files and manually retrieving function pointers. It's as simple as
/* in every source file using OpenGL */
#include <GL/glew.h>
and
/* for each OpenGL context */
if( createGLContext(...) == SUCCESSFULL )
glewInit()

If you're using Qt you should probably use qmake - and just add
QT += opengl
to your qmake project file.

Related

Creating a Windows shortcut (shell link) in C++

I want to programmatically create a Windows shortcut (.lnk file) to a folder. To do this, I tried this code snippet. However, I get the compilation error C2371 'WebBrowser': redefinition; different basic types in C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um\exdisp.h line 2367.
Is there a C++17 std::filesystem API for this? If not, how can I fix the compilation error from above? Even with cleaned up includes, the error persists:
#include <Windows.h>
#include <shlguid.h>
#include <shobjidl_core.h>
Using the mklink command yields:
The device does not support symbolic links.
So that doesn't work either, maybe because this is an external SSD.
What else could I try?
The first answer you linked to is the correct way. And it does not rely on WebBrowser at all. It will probably help to define some of the NO_XXX macros before including windows.h.
In my version of ShlGuid.h which is slightly older than yours, I see
#ifndef NO_SHDOCVW_GUIDS
#ifndef GUID_DEFS_ONLY
#include <exdisp.h>
#include <shldisp.h>
#endif
so you can use NO_SHDOCVW_GUIDS to excise the troublesome header that you weren't wanting anyway.
If you wanted support for WebBrowser and the kitchen sink, another fix might be moving #include <windows.h> after ShlGuid.h, as shown e.g. here: https://stackoverflow.com/a/73422757/103167
Links are something that differ a fair amount from filesystem to filesystem, so difficult to standardize. Shell links (.lnk files) are filesystem-independent, but only work on MS Windows (completely non-portable) which also is a strike against finding support in a standard API.

Boost / Netbeans: Recursive Includes Related to BSD on Linux Mint 17.2

I have a C++ project in Netbeans on my Linux Mint 17.2 machine. I'm using the GCC 5 toolchain (e.g. g++ 5.3.0), Netbeans 8.1, and Boost 1.61.0.
I'm encountering a weird warning in my project that shows up all over the place. For instance, in my main.cpp, I #include <iostream> at the very top, and that line gets a warning. (I see this warning happen for the first file I include in every file, so it is not an issue with iostream etc.).
The warning is that there is a recursive #include in boost. Specifically, Netbeans complains that <boost/predef/os/bsd/free.h> includes <boost/predef/os/bsd.h> and that <boost/predef/os/bsd.h> includes <boost/predef/os/bsd/free.h>. For the record, this appears to be true - does anyone know why there is this recursive include in boost, and if it is really supposed to be there?
The bigger issue is that my system is not BSD, so I don't know why I'm getting these warnings from the BSD headers, which shouldn't be included or active/defined. I tried printing BOOST_PLATFORM_CONFIG from my main.cpp, and it prints out the path to boost's Linux config header, as expected - not the BSD config header. And, my program compiles and runs fine, so I'm assuming it's never actually using the BSD headers. Which means that the fact that these BSD headers are giving me warnings might be a Netbeans problem, not a boost problem.
Does anyone have any ideas on how to narrow down and fix this issue with these strange recursive include warnings?
I was having the same problem. The issue is with the boost predef/os/bsd.h header. It #includes 5 files in the #else block for the #ifndef BOOST_PREDEF_OS_BSD_H guard. This means that this header file is not guarded against recursion if any of those 5 files also includes bsd.h (which they do).
My solution was to edit the predef/os/bsd.h file and add a recursion guard in the #else block - so, starting at around line 94 my predef/os/bsd.h file now looks like:
#ifndef BOOST_PREDEF_OS_BSD_H_PREVENT_RECURSION <-- ADD THIS
#define BOOST_PREDEF_OS_BSD_H_PREVENT_RECURSION <-- ADD THIS
#include <boost/predef/os/bsd/bsdi.h>
#include <boost/predef/os/bsd/dragonfly.h>
#include <boost/predef/os/bsd/free.h>
#include <boost/predef/os/bsd/open.h>
#include <boost/predef/os/bsd/net.h>
#endif <-- ADD THIS
And now netbeans code assistance is happy and my code still links and compiles without error.
The rough way: comment
#include <boost/predef/os/bsd.h>
Everywhere (should be inside the following headers)
predef/os.h
predef/other/endian.h

Code-sense in embedXcode doesn't hightlight syntax for the library I've included

Code-sense mostly works-- all of the core Arduino types are hightlighted properly. But no types
referencing the FastLED library are.
My code compiles fine. And, syntax is hightlighted properly in FastLED.h
How can I make use of code-sense in xCode for Arduino libraries?
At the top of my .ino file, I do this
// Core library for code-sense
#include "Wiring.h"
#include "Arduino.h"
// Include application, user and local libraries
#include "LocalLibrary.h"
#include "FastLED.h"
I am running XCode 5.1 on OSX 10.9.2 with embedXcode+ (professional) release 136. I checked out the FastLED_2.1 branch, as master does not support Teensy 3.1, the board I am using.
Solved. It appears that NO libraries listed in USER_LIBS_LIST confer the benefits to code-sense to your main ino file. However, once I moved the FastLED from
/Users/justin/Documents/Arduino/Libraries
to
/Applications/Arduino.app/Contents/Resources/Java/libraries
and restarted XCode, everything works great.
It seems the table for libraries reached an overflow.
WARNING Overflow reached

Installing PNGwriter library in codeblocks

I'm trying to setup pngwriter library in codeblocks for c++. I've used this tutorial (http://www.neuron-hub.com/2011/06/setting-up-pngwriter-with-code.html) but something isn't working. I'm almost a beginner at c++, and those library installs are killing me.
When I build it like it says in tutorial, in codeblocks opens another tab called ft2build.h and says
#ifndef __FT2_BUILD_UNIX_H__
#define __FT2_BUILD_UNIX_H__
/* `<prefix>/include/freetype2' must be in your current inclusion path */
#include <freetype/config/ftheader.h>
#endif /* __FT2_BUILD_UNIX_H__ */
/* END */
so the question is does anybody know what the problem is here? Tutorial is simple and I repeated it at least 20 times and the result is the same.
You must include ..\include\freetype2\ into the path where Codeblocks searches for necessary headers.

compiling a C++ class in Xcode: error during compilation: stl vector

I have a C++ class that compiles fine on linux with gcc and on widows in visual studio.
boid.h:
#ifndef BOID_CLASS_HEADER_DEFINES_H
#define BOID_CLASS_HEADER_DEFINES_H
#include "defines.h"
class Boid {
public:
// Initialize the boid with random position, heading direction and color
Boid(float SceneRadius,float NormalVel);
.....
protected:
...
};
#endif
and in boid.cpp:
#include "Boid.h"
// Initialize the boid with random position, heading direction and color
Boid::Boid(float SceneRadius,float NormalVel)
{
....
}
However, I get the following error when I compile this code in Xcode:
Compiling Boid.h: "error: vector: No such file or directory"
Any ideas? I thought you could take C/C++ code and compile it in Xcode without issues?
Thanks
EDIT: Added defines.h (also added #endif to sample, but that was in the original code)
EDIT 2: I am getting a different error after a commenting out a couple of includes there were empty: the vector error above.
#ifndef BOID_NAV_DEFINES_H
#define BOID_NAV_DEFINES_H
#include <stdlib.h>
#include <vector>
#include "Vector3d.h"
#include "Point3d.h"
#include "win_layer.h"
#endif
Are you including the C++ header in a .m file?
.m files are treated as .c files with Objective-C extensions.
.mm files are treated as .cpp files with Objective-C extensions, then it's called Objective-C++
Just rename any .m file to .mm, right-click or ctrl-click and select rename on the file in Xcode.
Without changing any .m to .mm or anything like that, if you click your project, click tagets->build settings
go all the way down to "LLVM GCC 4.2 - Languages" (new xcode says "Apple LLVM compiler 4.2") you will see Compile Sources As change that value to Objective-C++;
I hope this will help.
After updating xCode to version 10, I have had issues including < map > and < vector > libraries. Found an easy solution by changing the C++ library type in the project's build settings (target's Build Settings):
C++ Standard Library: libc++ (LLVM C++ standard library with C++ 11 support)
Compiled without any problem.
Make sure you're compiling it as C++. Right click the file in XCode and select Get Info and make sure that File Type is set to sourcecode.cpp.cpp for the implementation files.
Assuming you're talking about the OS X XCode, that uses gcc to do the actual compiling. So there should be no difference between that and Linux, other than maybe different versions of gcc.
First thing that jumps out at me here is that you've typed "boid.h" as the name of the file, but you're including "Boid.h". Assuming that's not a typo, I would expect that to cause trouble on both Linux and OS X....
Edited to answer the new question: Hmmm... vector is definitely part of Xcode: /Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.0.0/vector on my machine.
Further thought: If you port the source and makefiles from the Linux build over to the Mac, you can probably just compile it from the command line exactly like you do on Linux....
Definitely, something in defines.h is affecting the class definition.
This issue had two errors:
one of my includes had a typo which caused a compile error
the vector not found error was fixed by the .m files to .mm
Not sure if you forgot to paste, but you have an unterminated #ifndef
What's inside defines.h ?
Edit: You seem to have found the solution. One more remark:
#include <stdlib.h>
For C++, please:
#include <cstdlib>
:D