This question has already been answered:

Created the simplest scene in opengl (everything works). I decided to push it into the class began to jump error

undefined reference to `WinMain @ 16 '

enter image description here

Here is the code:

main.h

#ifndef MAIN_H #define MAIN_H #include <QCoreApplication> #include <QTextStream> #include <QTextCodec> #include <cstdio> //бСспСчиваСт Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΉ Π²Π²ΠΎΠ΄Π°/Π²Ρ‹Π²ΠΎΠ΄ (printf) #include <glew.h> // ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ пСрвая Π³Ρ€Π°Ρ„ΠΈΡ‡ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ° #include <GL/gl.h> #include <glfw3.h> // Ρ€ΡƒΡΠΈΡˆΡŒ QTextStream outStream(stdout); class MainWindow { //Π³Π»ΠΎΠ±Π°Π»ΡŒΠ½Ρ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ const char* APP_TITLE; //const int glfwWindowHint(); const int gWindowWidth = 800; const int gWindowHeight = 600; GLFWwindow* gWindow; public: int start(); void glfw_onFramebufferSize(GLFWwindow* window, int width, int height); bool initOpenGL(); private: }; #endif // MAIN_H 

main.cpp

 #include "main.h" //int main(int argc, char *argv[]) int MainWindow::start() { APP_TITLE = "Π¨Π°ΡˆΠ΅Ρ‡ΠΊΠΈ"; gWindow = NULL; // QCoreApplication a(argc, argv); // return a.exec(); outStream.setCodec(QTextCodec::codecForName("cp866")); if (!initOpenGL()) { // An error occured outStream << QString("GLFW инициализация ΠΏΡ€ΠΎΠ²Π°Π»ΠΈΠ»Π°ΡΡŒ") << flush; return -1; } while (!glfwWindowShouldClose(gWindow)) { // Poll for and process events glfwPollEvents(); outStream <<QString("%1").arg(glfwGetTime()); glfwSwapBuffers(gWindow); } glfwTerminate(); return 0; } //----------------------------------------------------------------------------- // Initialize GLFW and OpenGL //----------------------------------------------------------------------------- bool MainWindow::initOpenGL() { //инициализация GLFW if(!glfwInit()) { // outStream << QString("GLFW инициализация ΠΏΡ€ΠΎΠ²Π°Π»ΠΈΠ»Π°ΡΡŒ") << flush; return false; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_CORE_PROFILE); // ΠΏΡ€ΠΎΠ²Π΅Ρ€ Π»ΠΈΠ±ΠΎ Ρ€Π°Π·ΠΊΠΎΠΌΠ΅Π½Ρ‚ΠΈ Π²Π΅Ρ€Ρ… /* forward compatible with newer versions of OpenGL as they become available but not backward compatible (it will not run on devices that do not support OpenGL 3.3 */ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Create an OpenGL 3.3 core, forward compatible context window gWindow = glfwCreateWindow(gWindowWidth, gWindowHeight, APP_TITLE, NULL, NULL); if(gWindow == NULL) { outStream << QString("ошбика создания GLFW ΠΎΠΊΠ½Π°") << flush; glfwTerminate(); return false; } // Make the window's context the current one glfwMakeContextCurrent(gWindow); // INitialize GLEW glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { outStream << QString("GLEW инициализация ΠΏΡ€ΠΎΠ²Π°Π»ΠΈΠ»Π°ΡΡŒ") << flush; return false; } return true; } //----------------------------------------------------------------------------- // Is called when the window is resized //----------------------------------------------------------------------------- void MainWindow::glfw_onFramebufferSize(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); } 

What am I doing wrong ?? Why jumped error ??

Reported as a duplicate by participants aleksandr barakin , AnT c ++ Dec 27 '18 at 15:37 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Do you have a main function in main.cpp? Is there anyway in the project? - vegorov
  • one
  • In particular, the answer @AnT - cpp questions
  • one
    It is necessary to set the entry point to the program, otherwise from which piece will this program run? - VTT

1 answer 1

Thanks @VTT, everything worked

added code to main.cpp

 int main() { MainWindow w; w.start(); return 0 ; } 

enter image description here