I am trying to write some openGL code in visual studio 2012. I've looked over the internet to try and get this set up properly, and I can't seem to solve this.
#include <gl\GL.h>
#include <gl\GLU.h>
#include <gl\glut.h>
int main(int argc, char**argv){
glutInit(&argc, argv);
}
The glutInit line does not work, saying glutInit is not defined. Can someone please walk me through how to set this up properly in VS 2012? I've done things like this before in 2010, and would really like to just start working on my project.
You add the glut directory to the VC++ directories, here:
Then you need to add the name of the library under the Additional Dependencies:
Related
im having trouble running my console app with the following format.I've looked through dozens of websites and stack overflow questions and non of them were useful.please help me figure this out:
#include "stdafx.h"
#include <iostream
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
}
cannot open source file "stdafx.h"
identifier "_TCHAR" is undefine.
it's a console project and it does'nt create those stdafx.h and stdafx.cpp files.
I have found the answer to this problem on my own.
from the beginning the problem was the version of visual studio .
so apart from the unreadable and unclear form of debugging the vs2012 does,the thing is in vs2012 this form of "int _tmain(int argc, _TCHAR* argv[])" is accepted but in vs2019 this is completely prohibited so as "#include "stdafx.h".
So the key is to know what form you should use for c++ programming in different Visual Studio versions.
Replace _TCHAR with char, and _tmain with main.
_TCHAR is not part of the C++ language, it's an obsolete feature of the Windows API that should not be used today.
You can also remove #include "stdafx.h", it's a common convention when using the Microsoft Visual Studio compiler but it's not required. You may also need to turn off the precompiled headers option in your project.
The file included in the error message is "libpng16-16.dll", I am using SDL2_Image version 2.0.4 with Visual C++ on Windows. No matter what I do, the message stays. i tried swapping out all libpng16-16.dll files with my version i got. I also tried including it into the system32 folder. Nothing works. I can initialize SDL2_Image for other formats, but as soon as i try to initialize it for png, it throws this message. all the time. Found few cases of this happening to others, but their way of fixing it doesn't work for me. at all. i am upset pls help. Here's my current code real quick:
#include "SDL.h"
#include "SDL_image.h"
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
IMG_Init(IMG_INIT_PNG);
SDL_Quit();
return 0;
}
I have installed Qt Creator with the msvc2017_64 binary. I also installed the Qt add-in for VS2017. I can create a QtGuiApplication without any problems, but when i try to compile it, many errors appear. I listed them here, on pastebin, because I cannot add this many characters to Stackoverflow. I'm sorry for that.
Do I need any essential packages for this? I installed C++ for VS2017 ofc. I also included the QtPath in the Qt VS Tools menu.
I did not edit the files since project creation and compiling fails due to errors.
EDIT: This problem is solved here. But not only the Errors form Pastebin exist, also the one following in the QtGuiApplication.h
QtGuiApplication.h: (Errors marked as comments)
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication1.h" //This could not be found
class QtGuiApplication1 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication1(QWidget *parent = Q_NULLPTR);
private:
Ui::QtGuiApplication1Class ui; //Ui namespace does not exist
};
QtApplication.cpp:
#include "stdafx.h"
#include "QtGuiApplication1.h"
QtGuiApplication1::QtGuiApplication1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
main.cpp:
#include "stdafx.h"
#include "QtGuiApplication1.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtGuiApplication1 w;
w.show();
return a.exec();
}
I solved this problem myself!
The Qt add-in creates the Project with the Windowns 8.1 SDK, you need to retarget it to the Win 10 SDK to get the compile Errors from the QtGuiApplication.h away. Even if the 8.1 SDK is installed. Seems like a bug.
The solution was quite simple to me, just unload and then reload the solution from Solution Explorer!
This will clear all c++ compiler errors! Don't know why ...
Okay. So I've got a simple question. If I ask it in the wrong place, please correct me. What I want to ask is, why Visual Studio gives me this:
#include "stdafx.h"
int main()
{
return 0;
}
everytime I create a new project? (I know I can select Empty Project, and add mine .cpp file by myself, but I'm just curious. It says #include <stdio.h> and #include <tchar.h>. So what is it for? Are you all using it or something?
And P.S - why there is no (int argc, char** argv) in main declaration? (on my coding course in college I've learned that there may be _tmain(int argc, _TCHAR* argv), when creating something in VS)
Okay. So I've got a simple question. If I ask it in the wrong place, please correct me. What I want to ask is, why Visual Studio gives me this:
...
Well, it depends a bit on the project type you've been choosing from the wizard. Looks like the standard template for a console project.
#include "stdafx.h"
is prepended for any type of translation unit by the wizard. It supports the precompiled header optimizaton mechanism.
why there is no (int argc, char** argv) in main declaration?
Because the template provides the minimum for a valid main() entry routine definition.
When creating a new Win32 project, Visual Studio automatically adds a precompiled header "stdafx.h" to your project, even if you unchecked the 'Empty Project' checkbox.
If you want to disable this, go to your project configuration properties -> C/C++ -> Precompiled Headers and select 'Not Using Precompiled Headers'.
Working with precompiled headers see: https://stackoverflow.com/a/4726838.
And P.S. look at -> https://stackoverflow.com/a/4207223
The precompiled header is for speeding up compile times by compiling the contents of your most frequently included headers only once and then reusing the compile results. You can change its name if you want.
The following is my environment:
Eclipse IDE for C/C++ Developers(Juno)
Qt 4.8.3
Qt Eclipse Integration v1.6.1
mingw(20120426)
When I create a Qt console project, I just can't use C library functions, such as exit(int) or atoi(string).
The error message is such like Function 'exit' could not be resolved.
I have included stdlib.h, but still can't work.
I don't know if there is some relation with index.
20121109 Update
Thanks for give me help!
atoi is just a example!
Although I write program in c++, but sometimes I want use C library, so I tag it c++.
The following is what I include
C:/MinGW/include
C:/MinGW/lib/gcc/mingw32/4.6.2/include
C:/MinGW/lib/gcc/mingw32/4.6.2/include/c++
C:/MinGW/lib/gcc/mingw32/4.6.2/include/c++/backward
C:/MinGW/lib/gcc/mingw32/4.6.2/include/c++/mingw32
C:/MinGW/lib/gcc/mingw32/4.6.2/include-fixed
Others are Qt library.
And the following is main.
#include <QtCore>
#include <QCoreApplication>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
std::exit(0);
QCoreApplication a(argc, argv);
return a.exec();
}
I try this way but still get error message Function 'exit' could not be resolved.
Thanks a lot!
First of all, use C++ headers style. For stdlib.h :
#include <cstdlib>
Then, I guess you're not bringing namespace information. Either write :
using namespace std;
(even if I don't recommend it) or
using std::exit using std::atoi;
or use fully qualified names :
std::exit(-1);
Finally, why do you need such functions like atoi ?
I had a similar case which I was able to solve by moving #include <cstdlib> to the top of the list of header includes. This means that one of the other header files had a dependency on something in the cstdlib. This is not really good practice but they're all system header files and trying to correct them would make the code less portable between similar development systems.
I use Eclipse C++ Kepler. This is what I did and it worked for me:
right-click in editor's screen>Run As>Local C/C++ Application.