Linking errors in a fresh project going by the instructions in FAQ #4413

Closed
opened 2021-08-10 10:46:44 +00:00 by ghost · 4 comments
ghost commented 2021-08-10 10:46:44 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

Version: 1.8.3
Branch: just grabbed the Releases source

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_win32.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Using GLFW 3.34 and the newest version of GL3W.
Compiler: default Visual Studio Community 2019 compiler, C++17
Operating System: Windows 10 21H1

My Issue/Question:

Just dropping the necessary source and header files into a project causes a lot of linking errors to pop up.
The files are compiled as per the build output:

Build started...
1>------ Build started: Project: XXX, Configuration: Debug x64 ------
1>entrypoint.cpp
1>imgui.cpp
1>imgui_demo.cpp
1>imgui_draw.cpp
1>imgui_impl_glfw.cpp
1>imgui_impl_opengl3.cpp
1>imgui_impl_win32.cpp
1>Generating Code...
1>context.c
1>egl_context.c
1>gl3w.c
1>init.c
1>input.c
1>monitor.c
1>osmesa_context.c
1>wgl_context.c
1>win32_init.c
1>win32_joystick.c
1>win32_monitor.c
1>win32_thread.c
1>win32_time.c
1>win32_window.c
1>window.c
1>xkb_unicode.c
1>Generating Code...
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>imgui.obj : error LNK2019: unresolved external symbol "void __cdecl ImGui::Separator(void)" (?Separator@ImGui@@YAXXZ) referenced in function "void __cdecl ImGui::ShowMetricsWindow(bool *)" (?ShowMetricsWindow@ImGui@@YAXPEA_N@Z)
1>imgui_demo.obj : error LNK2001: unresolved external symbol "void __cdecl ImGui::Separator(void)" (?Separator@ImGui@@YAXXZ)
1>imgui.obj : error LNK2019: unresolved external symbol "void __cdecl ImGui::Dummy(struct ImVec2 const &)" (?Dummy@ImGui@@YAXAEBUImVec2@@@Z) referenced in function "void __cdecl RenderViewportsThumbnails(void)" (?RenderViewportsThumbnails@@YAXXZ)
1>imgui_demo.obj : error LNK2001: unresolved external symbol "void __cdecl ImGui::Dummy(struct ImVec2 const &)" (?Dummy@ImGui@@YAXAEBUImVec2@@@Z)
// [...] more linking errors

The files are included in the project as per screenshot below.

Screenshots/Video

obraz

Standalone, minimal, complete and verifiable example: (see https://github.com/ocornut/imgui/issues/2261)

#pragma once

// Macros
#define DIE(x) { fprintf(stderr, x); exit(EXIT_FAILURE); }

// ImGui stuff
#include <GL/gl3w.h>
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>

// Normal includes
#include <filesystem>
#include <fstream>

namespace fs = std::filesystem;
using ofs = std::ofstream;
using ifs = std::ifstream;
using std::string;

const string optFile = "options.json", modDir = "mods", assetDir = "assets";

static void glfw_error_callback(int error, const char* description)
{
	fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}

int main(int argc, char** argv)
{
	// Init GLFW
	glfwSetErrorCallback(glfw_error_callback);
	if (!glfwInit()) DIE("Failed to initialize GLFW!\n");

	GLFWwindow* window = glfwCreateWindow(1280, 720, "XXX", NULL, NULL);
	if (window == NULL) DIE("Failed to initialize GLFW window!\n");

	glfwMakeContextCurrent(window);
	glfwSwapInterval(1); // Enable vsync

	// Init OpenGL loader
	if (gl3wInit()) DIE("Failed to initialize OpenGL loader!\n");

	// Init ImGui
	IMGUI_CHECKVERSION();
	ImGui::CreateContext();
	ImGuiIO& io = ImGui::GetIO(); (void)io;
	io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable keyboard
	ImGui::StyleColorsDark();

	// Setup renderer backends
	const char* glsl_version = "#version 330 core";
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	ImGui_ImplGlfw_InitForOpenGL(window, true);
	ImGui_ImplOpenGL3_Init(glsl_version);

	// Create directories and files necessary for running the app
	if (!fs::exists(assetDir)) fs::create_directory(assetDir);
	if (!fs::exists(modDir)) fs::create_directory(modDir);
	if (!fs::exists(optFile)) ofs(optFile) << "sample options file";

	// Draw
	while (!glfwWindowShouldClose(window))
	{
		// Clear colour
		static ImVec4 clear_color = ImVec4(113.f / 255.f, 54.f / 255.f, 138.f / 255.f, 255.f / 255.f);

		// Poll and handle events (inputs, window resize, etc.)
		glfwPollEvents();

		// Begin frame
		ImGui_ImplOpenGL3_NewFrame();
		ImGui_ImplGlfw_NewFrame();
		ImGui::NewFrame();

		// Render demo window
		ImGui::ShowDemoWindow();

		// Render
		ImGui::Render();
		int display_w, display_h;
		glfwGetFramebufferSize(window, &display_w, &display_h);
		glViewport(0, 0, display_w, display_h);
		glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
		glClear(GL_COLOR_BUFFER_BIT);
		ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

		glfwSwapBuffers(window);
	}

	// Cleanup
	ImGui_ImplOpenGL3_Shutdown();
	ImGui_ImplGlfw_Shutdown();
	ImGui::DestroyContext();

	glfwDestroyWindow(window);
	glfwTerminate();

	return EXIT_SUCCESS;
}
**Version/Branch of Dear ImGui:** Version: 1.8.3 Branch: just grabbed the Releases source **Back-end/Renderer/Compiler/OS** Back-ends: imgui_impl_win32.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp Using GLFW 3.34 and the newest version of GL3W. Compiler: default Visual Studio Community 2019 compiler, C++17 Operating System: Windows 10 21H1 **My Issue/Question:** Just dropping the necessary source and header files into a project causes a lot of linking errors to pop up. The files are compiled as per the build output: ``` Build started... 1>------ Build started: Project: XXX, Configuration: Debug x64 ------ 1>entrypoint.cpp 1>imgui.cpp 1>imgui_demo.cpp 1>imgui_draw.cpp 1>imgui_impl_glfw.cpp 1>imgui_impl_opengl3.cpp 1>imgui_impl_win32.cpp 1>Generating Code... 1>context.c 1>egl_context.c 1>gl3w.c 1>init.c 1>input.c 1>monitor.c 1>osmesa_context.c 1>wgl_context.c 1>win32_init.c 1>win32_joystick.c 1>win32_monitor.c 1>win32_thread.c 1>win32_time.c 1>win32_window.c 1>window.c 1>xkb_unicode.c 1>Generating Code... 1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library 1>imgui.obj : error LNK2019: unresolved external symbol "void __cdecl ImGui::Separator(void)" (?Separator@ImGui@@YAXXZ) referenced in function "void __cdecl ImGui::ShowMetricsWindow(bool *)" (?ShowMetricsWindow@ImGui@@YAXPEA_N@Z) 1>imgui_demo.obj : error LNK2001: unresolved external symbol "void __cdecl ImGui::Separator(void)" (?Separator@ImGui@@YAXXZ) 1>imgui.obj : error LNK2019: unresolved external symbol "void __cdecl ImGui::Dummy(struct ImVec2 const &)" (?Dummy@ImGui@@YAXAEBUImVec2@@@Z) referenced in function "void __cdecl RenderViewportsThumbnails(void)" (?RenderViewportsThumbnails@@YAXXZ) 1>imgui_demo.obj : error LNK2001: unresolved external symbol "void __cdecl ImGui::Dummy(struct ImVec2 const &)" (?Dummy@ImGui@@YAXAEBUImVec2@@@Z) // [...] more linking errors ``` The files are included in the project as per screenshot below. **Screenshots/Video** ![obraz](https://user-images.githubusercontent.com/41419822/128853565-eb2031e5-626a-4bfd-8610-0b52e351320b.png) **Standalone, minimal, complete and verifiable example:** _(see https://github.com/ocornut/imgui/issues/2261)_ ```cpp #pragma once // Macros #define DIE(x) { fprintf(stderr, x); exit(EXIT_FAILURE); } // ImGui stuff #include <GL/gl3w.h> #include <GLFW/glfw3.h> #include <imgui.h> #include <imgui_impl_glfw.h> #include <imgui_impl_opengl3.h> // Normal includes #include <filesystem> #include <fstream> namespace fs = std::filesystem; using ofs = std::ofstream; using ifs = std::ifstream; using std::string; const string optFile = "options.json", modDir = "mods", assetDir = "assets"; static void glfw_error_callback(int error, const char* description) { fprintf(stderr, "Glfw Error %d: %s\n", error, description); } int main(int argc, char** argv) { // Init GLFW glfwSetErrorCallback(glfw_error_callback); if (!glfwInit()) DIE("Failed to initialize GLFW!\n"); GLFWwindow* window = glfwCreateWindow(1280, 720, "XXX", NULL, NULL); if (window == NULL) DIE("Failed to initialize GLFW window!\n"); glfwMakeContextCurrent(window); glfwSwapInterval(1); // Enable vsync // Init OpenGL loader if (gl3wInit()) DIE("Failed to initialize OpenGL loader!\n"); // Init ImGui IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable keyboard ImGui::StyleColorsDark(); // Setup renderer backends const char* glsl_version = "#version 330 core"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init(glsl_version); // Create directories and files necessary for running the app if (!fs::exists(assetDir)) fs::create_directory(assetDir); if (!fs::exists(modDir)) fs::create_directory(modDir); if (!fs::exists(optFile)) ofs(optFile) << "sample options file"; // Draw while (!glfwWindowShouldClose(window)) { // Clear colour static ImVec4 clear_color = ImVec4(113.f / 255.f, 54.f / 255.f, 138.f / 255.f, 255.f / 255.f); // Poll and handle events (inputs, window resize, etc.) glfwPollEvents(); // Begin frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); // Render demo window ImGui::ShowDemoWindow(); // Render ImGui::Render(); int display_w, display_h; glfwGetFramebufferSize(window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); glfwSwapBuffers(window); } // Cleanup ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); glfwDestroyWindow(window); glfwTerminate(); return EXIT_SUCCESS; } ```
ghost commented 2021-08-10 10:48:26 +00:00 (Migrated from github.com)

Note: also tried suggestions in #4328, none of them worked.

Note: also tried suggestions in #4328, none of them worked.
ocornut commented 2021-08-10 10:55:40 +00:00 (Migrated from github.com)

Just dropping the necessary source and header files into a project causes a lot of linking errors

Beware of not using erroneous statements that perpetuate convincing yourself that you didn't make a mistake.
Learning to debug programs is about making sure your assumption are valid.

You state "just dropping the necessary source [...] files" and yet you did NOT drop the necessary source files.

  1. Look in the imgui/ folder and it should be obvious that you omitted files from the list you provided.
  2. Alternatively, you can use "Find in Files" and search for the missing symbols in the codebase (e.g. ImGui::Separator() listed in the log extract you provided) and realize those symbols are implemented in source files that you have omitted.
> Just dropping the necessary source and header files into a project causes a lot of linking errors Beware of not using erroneous statements that perpetuate convincing yourself that you didn't make a mistake. Learning to debug programs is about making sure your assumption are valid. You state "just dropping the necessary source [...] files" and yet you did NOT drop the necessary source files. 1. Look in the imgui/ folder and it should be obvious that you omitted files from the list you provided. 2. Alternatively, you can use "Find in Files" and search for the missing symbols in the codebase (e.g. `ImGui::Separator()` listed in the log extract you provided) and realize those symbols are implemented in source files that you have omitted.
ghost commented 2021-08-10 11:07:50 +00:00 (Migrated from github.com)

Beware of not using erroneous statements that perpetuate convincing yourself that you didn't make a mistake.
Learning to debug programs is about making sure your assumption are valid.

You state "just dropping the necessary source [...] files" and yet you did NOT drop the necessary source files.

Rude, considering there is only one mention of what are considered "necessary files" in the main README which I only just found and there's literally nothing about that in the FAQ (which SHOULD actually be the first place to go to for this), only to "go to several other files which don't mention anything". A direct line "drop all the files in the root ImGui directory to your project file" would have helped a lot, especially to somewhat dense people like me.

Anyway, resolved by dropping in the other two files (imgui_tables.cpp, imgui_widgets.cpp).

>Beware of not using erroneous statements that perpetuate convincing yourself that you didn't make a mistake. >Learning to debug programs is about making sure your assumption are valid. > >You state "just dropping the necessary source [...] files" and yet you did NOT drop the necessary source files. Rude, considering there is only one mention of what are considered "necessary files" in the main README which I only just found and there's literally nothing about that in the FAQ (which SHOULD actually be the first place to go to for this), only to "go to several other files which don't mention anything". A direct line "drop all the files in the root ImGui directory to your project file" would have helped a lot, especially to somewhat dense people like me. Anyway, resolved by dropping in the other two files (imgui_tables.cpp, imgui_widgets.cpp).
ocornut commented 2021-08-10 12:41:38 +00:00 (Migrated from github.com)

There are 22 examples applications (including vsproj, Makefiles, cmakefile, batch files) all linking in *.cpp files.

You are right the README mention "They are ALL the files in the root folder of the repository" following by a partial list of files made this ambiguous of some sort (changed it now with c7529c8e). It is also programming literacy to be able to solve issues like that. Linking errors are the most asked C++ questions for any library, and as those questions come often to us (you have noticed this is issue number 4413) we get impatient and frustrated about it.

There are 22 examples applications (including vsproj, Makefiles, cmakefile, batch files) all linking in *.cpp files. You are right the README mention "They are ALL the files in the root folder of the repository" following by a **partial** list of files made this ambiguous of some sort (changed it now with c7529c8e). It is also programming literacy to be able to solve issues like that. Linking errors are the most asked C++ questions for any library, and as those questions come often to us (you have noticed this is issue number 4413) we get impatient and frustrated about it.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#4413
No description provided.