Getting GLEW to compile in Code::Blocks - c++

I'm wanting to get into and learn OpenGL in C++ and am using Code::Blocks. I was able to get freeglut to work, along with several online examples (as well as the example that ships with CB).
However, when I try to include GLEW for some tutorials I'm following, I get the following compiler errors:
obj\Debug\main.o||In function `RenderSceneCB':|
C:\C Programs\OpenGL Test\main.cpp|12|undefined reference to `_imp____glewEnableVertexAttribArray'|
C:\C Programs\OpenGL Test\main.cpp|13|undefined reference to `_imp____glewBindBuffer'|
C:\C Programs\OpenGL Test\main.cpp|14|undefined reference to `_imp____glewVertexAttribPointer'|
C:\C Programs\OpenGL Test\main.cpp|18|undefined reference to `_imp____glewDisableVertexAttribArray'|
obj\Debug\main.o||In function `CreateVertexBuffer':|
C:\C Programs\OpenGL Test\main.cpp|34|undefined reference to `_imp____glewGenBuffers'|
C:\C Programs\OpenGL Test\main.cpp|35|undefined reference to `_imp____glewBindBuffer'|
C:\C Programs\OpenGL Test\main.cpp|36|undefined reference to `_imp____glewBufferData'|
||=== Build finished: 7 errors, 0 warnings (0 minutes, 0 seconds) ===|
No matter what I do, what suggestions I try, what other files I try to link, I keep getting these same errors. I had someone else try the code and they said it worked just fine but didn't have any ideas as to what's wrong with my GLEW setup.
Anyone with any ideas, throw them my way.
I'm using Windows 7, Code::Blocks 12.11, and downloaded Ming32 binaries for GLEW 1.9.0.
My linker setting is set up in this order:
glew32
freeglut
opengl32
glu32
winmm
gdi32

You have problem in linker setting. You have to link
glew32s.lib
Not only glew32.lib you must link glew32s.lib also .Be sure that it must be at the top of the list of linker.
While writting code don't forget to define
#define GLEW_STATIC
At the top of source file.

I was struggling getting a GLEW example to work yesterday from
https://open.gl/introduction
I am working my way through those tutorials and find setting up the environment is always the hardest part. I also use Code:Blocks w/ MinGW and wanted to get into OpenGL.
Below you will find a quick summary for building GLEW and SFML yourself and also how to setup a project that uses both...
What after many frustrations worked for me was to download "glew-1.13.0.zip"
(the Source ZIP, I had to build GLEW myself)
Copy zip file content to C:\ (this path should now work: C:\glew-1.13.0\build\cmake)
You will have to buld GLEW for Code:Blocks w/ MinGW
I got myself CMake (google it)
Copy zip file content to C:\
(C:\CMake3.2.0\bin) and run cmake-gui.exe
In CMake find:
Where is the source code:
C:\glew-1.13.0\build\cmake
Where to build the binaries:
C:\glew-1.13.0\ownbuild
Click Configure (Pick your compiler in my case "CodeBlocks - MinGW Makefiles")
Click Generate (leave the settings alone, just press the button)
Now open C:\glew-1.13.0\ownbuild\glew.cbp in Code:Blocks and build all (shortcut is Ctrl+F9 in CodeBlocks :D )
After the build was a success your GLEW is built and ready for your environment
///////// START - SFML SIDE TRIP
Since i am a fan of SFML and the abvoe mentioend tutorial supports it you might want to build and use sfml also
sfml 2-3-2 (google it)
instal oal (oalinst.exe) from openal.software.informer.com/3.0/
In CMake:
Where is the source code:
C:/SFML-2.3.2
Where to build the binaries:
C:/SFML-2.3.2/build
check SFML_BUILD_EXAMPLES
3.
codeblocks:
-build "all"
//////// END - SFML SIDE TRIP
Now you want to use GLEW
Create a new console application in code:blocks
(I called it "GLEW_sample")
right click on that and choose build options
Now link in CB as follows:
LINKER SETTINGS:
(I don't like to keep relative paths)
*add all the SFML libs as usual
C:\SFML-2.3.2\build\lib\
*add OPENGL.dll from system32 folder
C:\Windows\System32\opengl32.dll
*add GLEW libs
C:\glew-1.13.0\ownbuild\lib\
SEARCH DIRECTORIES:
COMPILER:
C:\SFML-2.3.2\include
C:\glew-1.13.0\include
LINKER:
C:\SFML-2.3.2\build\lib
C:\glew-1.13.0\ownbuild\bin
This is the source code from the above mentioned tutorial
https://open.gl/content/code/c2_color_triangle.txt
just replace the code in your console application with it and you are good to go.
Now you have built GLEW and SFML w/ Cmake and created a project with working source code. Compile it and enjoy

Related

Integrating wxWidgets into Existing XCode Project

There are many tutorials about setting up a new XCode project for use with wxWidgets, but I need to integrate it with a large existing XCode C++ project.
The wxWidgets setup process is unclear to me. I built wxWidgets in XCode with the included wxcocoa.xcodeproj file. But when I include all the header files and the libwx_osx_cocoa.dylib library to my existing XCode project, I get all these errors within the wxWidgets header files like Use of undeclared identifier 'wxApp' and No matching constructor for initialization of 'wxEvent' as if it's missing files, but I've included all the header files and compiled library. I tried building wxWidgets in the terminal and get the same errors. I tried make install to actually install wxWidgets on my system. I tried running this command wx-config --cxxflags --libs all in the terminal. I tried adding wx-config --cxxflags and wx-config --libs all to the compiler and linker flags in my XCode project. None of these had any effect.
The irony is that I'm trying to use wxWidgets library to make the GUI process easier, but instead I've spent two days pulling my hair out trying to get my C++ XCode project to compile. Does anyone know what I'm doing wrong?
EDIT: The problem seems to be XCode. I've downloaded the wxWidgets Hello World sample program at the bottom of this page. I can build this program without issue in the terminal, but when I put it into a new XCode project, it won't build. How can I get XCode to build this simple program?
cx-config output:
XCode project settings:
EDIT 2: I exported the Build Log out of XCode and saw that the actual build command uses clang. When I successfully compile Hello World in the terminal, I use clang++. When I try the same command with clang, it doesn't work. Perhaps this is the issue, since clang only links C libraries and the errors XCode is giving me relate to not being able to find standard C++ functions.
EDIT 3: Wow I hate XCode. I got my Hello World program to compile by accident. The solution was putting the wxWidgets compiler flags in the Targets Build Settings, whereas before, I had it in the Project Build Settings. I assumed the Targets would inherit the Project settings, but I guess not!
EDIT 4: I got my complicated XCode project to compile with the wxWidgets libraries by taking all the search paths & flags and moving them from the Project Build Settings to the Targets Build Settings. What a nightmare! Glad it's over
#WaddleDee72
,
I suggest doing following:
Delete wxWidgets directory.
Unpack wxWidgets into i.e. ~/wxWidgets.
Open Terminal.
In the Terminal
4a. cd ~/wxWidgets
4b. mkdir buildOSX
4c. cd buildOSX
4d. ../configure --enable-debug
4e. make -j5
After successful build
wx-config --cxxflags
wx-config --libs
Use the output of 2 commands above and put the values where they belong in XCode project.
If you get any issues - let us know.
Thank you.

How to link against GLFW on Windows

I am looking to learn how to use OpenGL with C++, and I am following the tutorial at open.gl. I am at this part in the tutorial, and I am using GLFW. I tried following the instructions to build GLFW,
After you've downloaded the GLFW binaries package from the website or
compiled the library yourself, you'll find the headers in the include
folder and the libraries for your compiler in one of the lib folders.
-Add the appropriate lib folder to your library path and link with GLFW.
-Add the include folder to your include path.
I downloaded it, and moved the include folder into my MinGW include folder, but I was unsure where to find the lib folder, how to add it to my library path, or how to link it with OpenGL. This was not explained in the tutorial, and I could not find any instruction online about what this meant or how to do it. I proceeded without doing the other two steps, and when attempting to run the test code from the tutorial:
#include <GLFW/glfw3.h>
#include <thread>
int main()
{
glfwInit();
std::this_thread::sleep_for(std::chrono::seconds(1));
glfwTerminate();
}
I received this error:
In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\thread:35:0,
from D:\Files\Documents\Programming\opengl_tut.cpp:2:
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
I added -std=c++11 to my compiler flags, and I received this error:
D:\Files\Documents\Programming\opengl_tut.cpp: In function 'int main()':
D:\Files\Documents\Programming\opengl_tut.cpp:7:10: error: 'std::this_thread' has not been declared
std::this_thread::sleep_for(std::chrono::seconds(1));
Thinking the problem might just be with std::this_thread, I removed that line from my program, and ran it to see if initializing and terminating GLFW would return any errors. I got this:
C:\Users\Brett\AppData\Local\Temp\ccCJrDGj.o:opengl_tut.cpp:(.text+0xc): undefined reference to `glfwInit'
C:\Users\Brett\AppData\Local\Temp\ccCJrDGj.o:opengl_tut.cpp:(.text+0x11): undefined reference to `glfwTerminate'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\Brett\AppData\Local\Temp\ccCJrDGj.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
I think this may be because of the fact that I skipped earlier parts of the tutorials.
TL;DR
Tried to follow tutorial to use OpenGL
Couldn't figure out how to link GLFW
Couldn't find lib folder
Got errors relating to std::this_thread
Got error relating to GLFW
EDIT
I found some info on the GLFW site saying to use Cmake. I downloaded it and tried using it to build from the downloaded files. It made a new folder, but I'm not sure what to do with it.
First, it's easy to do such config in Visual Studio, just NuGet, and search glfw, install, Visual Studi/NuGet will handle everything like set proper Include path, Additional Library path, add additional library files
Second, it looks like your link issue, try to add these to your gcc cmd line
g++ -o example.exe example.o -L. -lexample_dll
Third, check the glfw library you downloaded, use MinGW-w64 lib files. Also remember distinguish the static and dynamic libs
It looks like you've downloaded the source files. This will require building (using CMake). You should go download the precompiled binaries. To do this, go back to glfw.org and instead of hitting the download button on the home page, go to the download tab in the top right and under "Windows pre-compiled binaries" select the 32 or 64 bit version and click download. See the attached image
Then, when you extract from the .zip folder you should find in it several folders - the include folder, as well folders with names beginning with "lib" (like lib-mingw, lib-mingw-w64, lib-vc2010, lib-vc2012, etc). You only need one of them, which depends on the compiler you're using - minGW or Visual C++ (vc). Choose the appropriate folder and inside you should find .lib and .dll files.
Now, whenever you compile your OpenGL program, you must tell the compiler (the linker, really) to link those files to your program's object files. You do this by using the proper compiler command line arguments. You can read about doing that in MinGW here: http://mingw.org/wiki/Specify_the_libraries_for_the_linker_to_use
For that tutorial you'll probably only need to link glfw3.lib (for MSVC) or libglfw3.a (for MinGW). If you're using GLEW, you'll probably just need glew32.lib and glew32.dll (the latter is found in the "bin" folder not the "lib" folder).
Hope that helps answer your question.

compiler error with windows 8 sfml and codeblocks

Trying to pick up a 2D library, SFML was my choice.
But, I can't get it to link properly.
When I try to build and run it I get the following error:
the procedure entry point gxx personality v0 could not be located in the dynamic link library sfml-graphics-d-2.dll
btw IDE is Code::Blocks 12.11 and compiler is MinGW(default)
I've extracted the library to c:\SFML-2.0
I've set the compiler search directories for compiler to C:\SFML-2.0\include
and Linker: C:\SFML-2.0\lib
And in the project that I've started I've added in the linker settings-> link libraries:
Debug:
sfml-graphics-d
sfml-window-d
sfml-system-d
Release:
sfml-graphics
sfml-window
sfml-system
I've also copied the dll files from C:\sfml-2.0\bin to the location of the project.
I've tried using the static linking without success.
watched some sfml tutorials and followed them, googled but nothing seems to work for me.
Also reinstalled code::blocks.
Ideas?
You need to use the correct SFML package. Errors with gxx_personality_v0 usually indicate a runtime library mismatch. If you're really using Code::Blocks 12.11 with the compiler they ship with, then you'll have the TDM 4.7.1 compiler, which uses the SJLJ exception model. Thus the matching compiler from the SFML download page would be GCC 4.7 TDM (SJLJ) - 32 bits.
Keep in mind that there's a newer Code::Blocks version (13.12), which uses a newer version of TDM, but for which SFML doesn't provide binaries/pre-compiled packages, thus you'd have to build SFML yourself.
While the TDM compiler is easy to install, I wouldn't recommend it, since it breaks the standard way of using GCC-like compilers. Instead you might want to look at Stephan T. Lavavej's build over at nuwen.net or go with MinGW Builds - for each you'll have to recompile SFML.
If you still get the error, I fixed mine by:
In the Compiler settings dialog:
In the left-hand menu, verify Global compiler settings is selected,
Select the Toolchain executables tab,
Select the Additional Paths tab, and
Press the Add button, find the bin folder of SFML (C:\CodeBlocks\sfml\bin), and add it without keeping relative paths.

develop vtk in codeblocks

I installed vtk in debian6.0.6 successfully, I build a static lib. I run the examples and everything is ok.
But I want to develop in codeblocks. So I created a project in codeblocks, copy the code "cone.cxx" into my project, I set the include path and linkers. But there are compile errors like "undefined reference to...", I guess that is because it can not find the interfaces in the static lib.
I guess I need some #defines before compile my project. I can see the pre_defines in visual studio2008, but I can not get it in codeblocks because the codeblocks project use its makefile defaultly. Can I get a solution if I don't want to write a makefile?

Bullet Physics, CMake->CodeBlocks - MinGW: Doesn't find GL/glut.h?

Statistics...
My System: Windows Vista 64 bit
Library: Bullet Physics v2.78
Makefile Generator: CMake
Build system: MinGW command line, MinGW + CodeBlocks
Makefiles were implemented by command line and through CMake-generated Code::Blocks project
In both cases, the build fails near 30%. NOTE: I did have to switch the build executable in the Code::Blocks project from make.exe to mingw32-make.exe
First Failure: Demos\OpenGL\GLDebugFont.cpp -> GL/glut.h: No such file or directory
Second Failure (after commenting out the #include from the first) -> Demos/OpenGL/GlutStuff.h: same error
These failures happen when I build command-line OR through the generated C::B project.
Why can't it find GL/glut.h? "bullet-2.78\Glut\GL\glut.h" exists. Maybe there's a way I can tell it to find glut there?
NOTE: During the CMake makefile generation, CMake did tell me that "You are using the obsolete GLU package, please use OpenGL instead." It continued as normal with the Makefile generation. Maybe I need to define some environment variables? Maybe I need to configure something in Windows that CMake is looking for?
I would add a compiler search path in bullet-2.78/Glut, but Code::Blocks doesn't allow that if you're using a custom makefile (like a CMake-generated one).
UPDATE: I have been able to build the library itself, by building specific targets in the Code::Blocks project. However, I have been unable to build any of the demos or the benchmark test, since they all use OpenGL (and apparently glut.h). I would still like to compile those.