I'm trying to run this .cpp file in Codeblocks (only change is adding #include for windows.h to beginning).
It uses OpenGL, GLUT, and GLUI. I think I've gotten OpenGL and GLUT to work in Codeblocks but GLUI is still giving me some issues. At first, I downloaded GLUI from here and copied glui.h into C:\Program Files (x86)\CodeBlocks\MinGW\include\GL.
I was getting an error around line 455:
void control_cb( int control ){
if (control == 5){
GLUI_Master.close_all();
(...)
};
which stated there was an undefined reference to GLUI_Master.
I then realized that the GitHub repository also had a GLUI header file so I deleted the other header file and copied this new one into the same place as above.
I was able to get a little further now, getting an error around line 508:
void createSettingsMenu(){
(...)
new GLUI_Button( settings, "Update", 5,control_cb);
//settings->set_main_gfx_window(mainWindow);
(...)
};
which stated there was no matching function for call to:
GLUI_Button::GLUI_Button(GLUI*&, const char [7], int, void(&) (int)).
I'm not sure what this means, but it also says
**note: candidate: GLUI_Button::GLUI_Button()
note: candidate expects 0 arguments, 4 provided**
around line 847:
GLUI_Button( void ) {
sprintf( name, "Button: %p", this );
type = GLUI_CONTROL_BUTTON;
h = GLUI_BUTTON_SIZE;
w = 100;
alignment = GLUI_ALIGN_CENTER;
can_activate = true;
};
I'm assuming this is related to the error but I'm not sure how to fix this -- I thought this error was surely caused by an issue in setting up GLUI with Codeblocks.
Related
I have a problem with making a program that uses winbgim.h header file. It is a simple program that makes just one simple circle. I am currently learning about winbgim and graphics.h libraries. I downloaded it, I downloaded the library and included it in Codeblocks following this and it works properly.
But when I try to use it, another code pops out and on the 302nd line it stands "error: redefinition of "int right". I am making this in a console file in Codeblocks IDE.
Can anyone help? Here is my code:
#include <iostream>
#include <winbgim.h>
#include <cstdlib>
using namespace std;
int main()
{
int gdriver = 9;
int gmode = 2;
initgraph(&gdriver,&gmode, "");
setbkcolor(WHITE);
setcolor(BLACK);
cleardevice();
circle(320,240,180);
getch();
closegraph();
return 0;
}
I don't know whether it suits this forum or not but I just wanted to tell (the world) something. I recently decided to try out WinBGIm library, so I downloaded the package and after setting up all the compiler and linker settings, ran my simple "Hello World" Code. But I got the following message from my compiler (MinGW, CodeBlocks IDE).
d:\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\graphics.h|302|error:
redefinition of 'int right'|
d:\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\graphics.h|302|error:
'int right' previously declared here|
||=== Build finished: 2 errors,
0 warnings ===|
After having googled the problem I found out nothing (If you don't count a suggestion to use CodeBlocks-EP as a Solution).
As I was taking a look at the header files, I found the problem (yeah!!!)
The problem was with the function printimage.
The original declaration was
//The original declaration. Note that there are two "right" variables
void printimage(
const char* title=NULL,
double width_inches=7, double border_left_inches=0.75, double border_top_inches=0.75,
int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX,
bool active=true, HWND hwnd=NULL
);
So what I did is that, I simply changed one of the "right" (the later former one) variable to "top". That's it.
//The corrected code
void printimage(
const char* title=NULL,
double width_inches=7, double border_left_inches=0.75, double border_top_inches=0.75,
int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
bool active=true, HWND hwnd=NULL
);
I did the same thing as #Puneet suggested, just change the name of one of the variables named "right".
The thing that I want to add is that you can't change the name within codeblocks (at least I couldn't do it, the changes were ignored). So I suggest you save your code file/s, close the IDE, and open the "graphics.h" file with a text editor, change the name, save, and you are all set.
You can find your MinGW directory by opening a new codeblocks project, right click in the <iostream> and select something like open file, which will open the header in a new codeblocks "tab", right click the tab and click open containing folder. Thats it.
The debugger in Visual Studio 2010 is recently pointing at the wrong lines and/or skipping lines and I have no idea why this is. This is a CUDA project and only happens in CUDA files. I've noticed the following:
It always happens at the same part of the program.
The lines it points to are always the same, i.e. not random.
Putting extra code after the culprit lines changes which lines it points to.
It only happens in .cu-files. Moving the code to a .cpp-file does not recreate the problem.
What I have tried:
Clean and rebuilt the solution.
Install SP1 for MSVC10 and do all possible updates via Windows Updates
Set the compiler to not use optimizations in debug mode for both C/C++ and CUDA C/C++
Manually delete all created files and then rebuild from the solution folder.
Deleting the folder C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
Recreating the solution only using the source files.
Disabling my extensions.
I've managed to reduce the code to the following which might reproduce the problem. Mind that this code has to be inside a .cu-file and most probably needs to be compiled with the cuda compiler for C/C++. Including boost is not really necessary, but this example does show what problems I'm having. A shorter example is at the back.
#include <boost/numeric/ublas/matrix.hpp>
using boost::numeric::ublas::matrix;
struct foo {
foo() : mat(NULL) {}
matrix<float>* mat;
};
bool func(foo *data) {
bool status; // <- skipped line
status = false;
if (status) {
std::cout << "test\n";
return (status); // <- error reported here
}
int size = data->mat->size1(); // instead of here
return status;
}
int main(int args, char* argv[]) {
func(NULL); // force error by passing NULL pointer
return 0;
}
Does anyone have any idea how to solve this or how this could be happening? It's pretty annoying having to debug this way.
Shorter example only showing the skipping lines. No external libraries necessary.
bool func() {
bool status; // <- skipped line
status = false;
return status;
}
int main(int args, char* argv[]) {
func();
return 0;
}
Since the program only contains CPU instructions and variable declarations of types that have no construction contain no instructions, the debugger will not stop there. It just executes instructions and then uses the debugging information that the compiler provided to find the relevant line of source code.
I'm facing an interesting problem: I had an MFC application project in Visual C++ 6.0. Since there are many changes either in MFC or in C++ standard, I wanted to port my application to Visual Studio 2010. It was fine, but I am facing a warning now, which I can't handle.
The header file has the following class definition:
template <class T>
class foo : public CObject
{
// ...
// other stuff
// ...
private:
CTypedPtrMap<CMapWordToPtr, const long, T*> oElementMap;
void some_stuff();
}
In the source file there is:
template <class T>
void foo::some_stuff()
{
// ...
// other stuff
// ...
int nIndex = 0;
// ...
// other stuff
// ...
oElementMap.RemoveKey(nIndex);
}
When I try to compile this, I get the following warnings:
Warning 1 warning C4244: 'argument' : conversion from 'const long' to
'WORD', possible loss of data c:\programme\microsoft visual studio
10.0\vc\atlmfc\include\afxtempl.h 2066
It comes definetly from the above mentioned "RemoveKey" line: if I just simply comment out that line, I won't get this warning.
I know, the main problem is, that CTypedPtrMap object uses const long as key type, but CMapWordToPtr would have WORD (unsigned short) instead of it. But the fact is: I need const long as key type, since I am processing regulary about 1 million data entries in this map, so with unsigned short the class would not be capable to do it's job furthermore.
I tried to nest either the "RemoveKey" line or the include of stdafx.h into the following expressions, but neither worked:
#pragma warning (disable: 4244)
// expression
#pragma warning (default: 4244)
Please share me any ideas about this issue, how could I resolve this warning WITHOUT changing the container's oElementMap definition and behaviour, and WITHOUT supress/disable this warning globally in the project settings as well as WITHOUT changing the afxtempl.h file supplied by VS2010.
Thanks for help:
Andrew
I've replaced it's definition to: CMap<long, long&, T*, T*&> oElementMap;. I was not sure it is the "long-counterpart" of the old map definition, therefore I did several test to compare them.
The solution was finally this.
I'm using a library that unfortunately, it appears the developer no longer works on or replies to issues in his Git repository. The library is used to drive HT1632C LED matrix drivers, and while it works in 0022/0023, it does not work in Arduino 1.0. When compiled, my Sketch gives the following error:
In file included from Final_code__1_0compatible.cpp:7:
C:\arduino-1.0\libraries\ht1632c/ht1632c.h:182: error: conflicting return type specified for 'virtual void ht1632c::write(uint8_t)'
C:\arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'
Referencing this site: http://arduino.cc/forum/index.php?topic=82450.0, I found a comment from someone who had the same compilation errors I did (but with another library). It looks like their fix was to replace something with "size_t"
Line 200: size_t write(uint8_t); //changed to resolve conflict with print.h
The conflicting lines in the library's .h and .cpp files look to be:
.h:
void write(uint8_t chr);
.cpp:
void ht1632c::write(uint8_t chr)
{
byte x, y;
if (chr == '\n') {
//y_cur += font_height;
} else {
//x_cur += putchar(x_cur, y_cur, chr, GREEN, PROPORTIONAL);
//x_cur = 0;
//y_cur = 0;
}
//sendframe();
}
I'm not a C/C++ expert, but am I correct, in that if I change the .h to be "size_t write(uint8_t chr)" and the .cpp to be "size_t ht1632c::write(uint8_t chr)" that this will work?
I tried doing it, and it compiles, but I don't know if I replace the word "void" with "size_t", or if I need to replace the "uint8_t" with "size_t".
so,
size_t ht1632c::write(uint8_t chr)
is the right function change. You should also add a
return 1;
right after the
sendframe();
line. write is expected to return the number of characters successfully written, as you don't have any way in the code as pasted to determine if there is an error in the writing, you should just say it worked.
Hey, i'm really trying to get TinyXML to at least read a file but it says "main.cpp:8: error: ‘TiXMLDocument’ was not declared in this scope"
This is the code im using:
TiXMLDocument("demo.xml");
Ideally i want to read able to read files and output the XML so i also tried this code i found online in a tutorial
#include <iostream>
#include "tinyxml.h"
#include "tinystr.h"
void dump_to_stdout(const char* pFilename)
{
TiXmlDocument doc(pFilename);
bool loadOkay = doc.LoadFile();
if (loadOkay)
{
printf("\n%s:\n", pFilename);
dump_to_stdout( &doc ); // defined later in the tutorial
}
else
{
printf("Failed to load file \"%s\"\n", pFilename);
}
}
int main(void)
{
dump_to_stdout("demo.xml");
return 0;
}
And the errors I'm getting now are:
main.cpp: In function ‘void dump_to_stdout(const char*)’:
main.cpp:13: error: cannot convert ‘TiXmlDocument*’ to ‘const char*’ for argument ‘1’ to ‘void dump_to_stdout(const char*)’
If it helps im on a mac, ive tried compiling in terminal as well as textmate. I also tried to compile the cpp files for TinyXML separately before compiling main.cpp and i have no idea why i cant print out demo.xml let alone read it.
It's called TiXmlDocument, not TiXMLDocument
You can't call a function that you haven't declared yet. Since you're trying to call an undeclared overload of dump_to_stdout, the compiler assumes you want to call the version that takes const char * and fails.
dump_to_stdout( &doc ); // defined later in the tutorial
Here's your problem.
dump_to_stdout takes a const char* which TiXmlDocument is definitely not.
You're already in that function, so assuming the file loads you'll have infinite recursion.
It doesn't matter that you've got one defined later that takes a TiXmlDocument. At this point, the only dump_to_stdout that exists is the one you're in, hence the error. Forward declare the one you want before this function, e.g: void dump_to_stdout(TiXmlDocument*);