【发布时间】:2021-06-09 03:50:17
【问题描述】:
我无法得到比我所拥有的更小的可复制示例。主要是因为我无法调试这个问题,它看起来完全是随机的,而且我并没有始终如一地得到错误,有时它会编译,有时它不会。我已经恢复到出现错误的时候,所以我可以复制代码,但从那以后,我没有收到错误。基本上,除了修复所有链接器警告之外,我没有其他想法。我记得它主要与这个警告LNK4042 object specified more than once; extras ignored in main.obj 有关。还有另一个我不明白的警告,我有一个名为GLEW 的库的二进制文件,但静态链接它会调用链接器警告LNK4099 PDB 'vc120.pdb' was not found with 'glew32s.lib(glew.obj)' or at '\SolutionDir\Debug\vc120.pdb'; linking object as if no debug info
这些警告的修复方法是什么?希望能阻止我随机出现错误,当我更改它编译的一件事,然后将其还原回来,它仍然可以编译。
这是代码,main.h
#pragma once
#ifndef MAIN_H
#define MAIN_H
#include <GL/glew.h> // Initialize with glewInit()
#ifndef GLFW_INCLUDE_NONE
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
#endif // GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include "ImGui/imgui.h"
#include "ImGui/implot.h"
#include "ImGui/imgui_impl_glfw.h"
#include "ImGui/imgui_impl_opengl3.h"
#include <iostream> //std::string
class Main ///Singleton
{
public:
Main(const Main&) = delete;
Main(Main&&) = delete;
Main& operator=(const Main&) = delete;
Main& operator=(Main&&) = delete;
private:
Main();
static Main& Get_Instance();
friend int main(int argc, char* argv[]);
static void Mainloop();
static void Init();
static void Free();
GLFWwindow* m_Window = nullptr;
std::string m_GLSL_Version = "";
int m_Window_Width = 1280;
int m_Window_Height = 720;
};
#endif // MAIN_H
和main.cpp
#include "main.h"
Main::Main()
{
}
Main& Main::Get_Instance()
{
static Main instance;
return instance;
}
void Main::Init()
{
// Setup window
Get_Instance(); //Init constructor
if (!glfwInit()) {
std::cout << "Could not initialize GLFW" << std::endl;
std::cin.get();
exit(EXIT_FAILURE);
}
Get_Instance().m_GLSL_Version = "#version 460";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
// Create window with graphics context
Get_Instance().m_Window = glfwCreateWindow(Get_Instance().m_Window_Width, Get_Instance().m_Window_Height, "Program", NULL, NULL);
if (Get_Instance().m_Window == NULL) {
std::cout << "Could not create GLFW window" << std::endl;
std::cin.get();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(Get_Instance().m_Window);
glfwSwapInterval(0); // vsync
if (glewInit() != GLEW_OK)
{
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
std::cin.get();
exit(EXIT_FAILURE);
}
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImPlot::CreateContext();
// Setup Dear ImGui style
ImGui::StyleColorsClassic();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(Get_Instance().m_Window, true);
ImGui_ImplOpenGL3_Init(Get_Instance().m_GLSL_Version.c_str());
}
void Main::Mainloop()
{
// Main loop
while (!glfwWindowShouldClose(Get_Instance().m_Window))
{
//Events
glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui::Text("%.3f", ImGui::GetIO().Framerate);
// Rendering
ImGui::Render();
glfwGetFramebufferSize(Get_Instance().m_Window, &Get_Instance().m_Window_Width, &Get_Instance().m_Window_Height);
glViewport(0, 0, Get_Instance().m_Window_Width, Get_Instance().m_Window_Height);
glClearColor(0.45f, 0.55f, 0.60f, 1.00f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(Get_Instance().m_Window);
}
}
void Main::Free()
{
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImPlot::DestroyContext();
ImGui::DestroyContext();
glfwDestroyWindow(Get_Instance().m_Window);
glfwTerminate();
}
int main(int argc, char* argv[])
{
Main::Init();
Main::Mainloop();
Main::Free();
return 0;
}
编辑:又发生了,这里是错误:
Error LNK1561 entry point must be defined
Warning LNK4042 object specified more than once; extras ignored (THIS IS IN MY main.obj file, its the only linker issue that references my actual files, the rest reference either 'LINK' or 'libucrt.lib(something here)'
Error LNK2005 __cexit already defined in ucrtd.lib(ucrtbased.dll)
Error LNK2005 __crt_atexit already defined in ucrtd.lib(ucrtbased.dll)
Error LNK2005 __crt_at_quick_exit already defined in ucrtd.lib(ucrtbased.dll)
Error LNK2005 __execute_onexit_table already defined in ucrtd.lib(ucrtbased.dll)
Error LNK2005 __initialize_narrow_environment already defined in ucrtd.lib(ucrtbased.dll)
Error LNK2005 __initialize_onexit_table already defined in ucrtd.lib(ucrtbased.dll)
Error LNK2005 __register_onexit_function already defined in ucrtd.lib(ucrtbased.dll)
Error LNK2005 __seh_filter_dll already defined in ucrtd.lib(ucrtbased.dll)
【问题讨论】:
-
如果您希望有一种从 C++ 获取向量的好方法,那么没有,ODBC C++ API 是非常低级的。如果您需要高级 API,请使用工具包或框架,如 Qt 或 .Net 框架。
-
如果您使用的是 Visual Studio,我建议您将 C++/CLI 与 .Net 一起使用,那里有很多很棒的教程,并且使用 .Net 5/.Net 核心,它可以是跨平台的。然后,您可以使用 OdbcDataReader 从托管的 ODBC 连接中读取数据。
-
显示您用于编译的确切设置,显示确切的错误消息。
-
@BDL 我得到它再次给我错误。我编辑了这个问题。另外,当我清理解决方案并重建时,错误消失了,但是这样做需要一段时间,所以我想以最佳方式摆脱它
-
随机发生的错误很难追踪。首先,我会确保在链接期间您有足够的可用内存和磁盘空间。这可能导致各种奇怪的行为。第二:请重命名您的 Main 类。第三:为什么你的主班是单身?这不是必需的。合并这些更改并查看您的链接器错误是否仍然存在
标签: c++ opengl linker glfw glew