I am trying to run my main.cpp file in CLion on Macos m1, where I have the ImGui repository cloned to. I opened my main.cpp file inside the ImGui-master. Wrote my application in main.cpp and built a CMakeLists.txt from the file. I looked through and made sure the necessary files were included built it annnddddddd...There is an error linking several (a large number of them actually) glfw functions to my main.cpp file.
Here is my main.cpp file:
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#define GL_SILENCE_DEPRECATION
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <GLES2/gl2.h>
#endif
#include <GLFW/glfw3.h> // Will drag system OpenGL headers
#if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)
#pragma comment(lib, "legacy_stdio_definitions")
#endif
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
#ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#endif
static void glfw_error_callback(int error, const char* description)
{
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
}
// Main code
int main(int, char**)
{
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit())
return 1;
// Decide GL+GLSL versions
#if defined(IMGUI_IMPL_OPENGL_ES2)
// GL ES 2.0 + GLSL 100
const char* glsl_version = "#version 100";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
#elif defined(__APPLE__)
// GL 3.2 + GLSL 150
const char* glsl_version = "#version 150";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
#else
// GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only
#endif
// Create window with graphics context
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", nullptr, nullptr);
if (window == nullptr)
return 1;
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
// Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
#ifdef __EMSCRIPTEN__
// For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file.
// You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
io.IniFilename = nullptr;
EMSCRIPTEN_MAINLOOP_BEGIN
#else
while (!glfwWindowShouldClose(window))
#endif
{
glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
{
static float f = 0.0f;
static int counter = 0;
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
ImGui::Checkbox("Another Window", &show_another_window);
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::End();
}
// 3. Show another simple window.
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
ImGui::End();
}
// Rendering
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);
}
#ifdef __EMSCRIPTEN__
EMSCRIPTEN_MAINLOOP_END;
#endif
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
This is the CMakeLists.txt file:
cmake_minimum_required(VERSION 3.26)
project(imgui_master_2)
set(CMAKE_CXX_STANDARD 14)
include_directories(.)
include_directories(backends)
include_directories(examples/libs/glfw)
include_directories(examples/libs/glfw/include)
include_directories(examples/libs/glfw/include/GLFW)
add_executable(imgui_master_2
backends/imgui_impl_glfw.cpp
backends/imgui_impl_glfw.h
backends/imgui_impl_opengl3.cpp
backends/imgui_impl_opengl3.h
examples/example_glfw_opengl3/main.cpp
examples/libs/emscripten/emscripten_mainloop_stub.h
examples/libs/glfw/include/GLFW/glfw3.h
examples/libs/glfw/include/GLFW/glfw3native.h
misc/cpp/imgui_stdlib.cpp
misc/cpp/imgui_stdlib.h
imconfig.h
imgui.cpp
imgui.h
imgui_demo.cpp
imgui_draw.cpp
imgui_internal.h
imgui_tables.cpp
imgui_widgets.cpp
imstb_rectpack.h
imstb_textedit.h
imstb_truetype.h
main.cpp)
This is what the console spit back to me:
ld: Undefined symbols:
_glClear, referenced from:
_main in main.cpp.o
_glClearColor, referenced from:
_main in main.cpp.o
_glViewport, referenced from:
_main in main.cpp.o
_glfwCreateStandardCursor, referenced from:
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
...
_glfwCreateWindow, referenced from:
_main in main.cpp.o
_glfwDestroyCursor, referenced from:
ImGui_ImplGlfw_Shutdown() in imgui_impl_glfw.cpp.o
_glfwDestroyWindow, referenced from:
_main in main.cpp.o
_glfwGetClipboardString, referenced from:
ImGui_ImplGlfw_GetClipboardText(void*) in imgui_impl_glfw.cpp.o
_glfwGetCocoaWindow, referenced from:
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
_glfwGetCursorPos, referenced from:
ImGui_ImplGlfw_UpdateMouseData() in imgui_impl_glfw.cpp.o
_glfwGetFramebufferSize, referenced from:
ImGui_ImplGlfw_NewFrame() in imgui_impl_glfw.cpp.o
_main in main.cpp.o
_glfwGetInputMode, referenced from:
ImGui_ImplGlfw_UpdateMouseCursor() in imgui_impl_glfw.cpp.o
_glfwGetJoystickAxes, referenced from:
ImGui_ImplGlfw_UpdateGamepads() in imgui_impl_glfw.cpp.o
_glfwGetJoystickButtons, referenced from:
ImGui_ImplGlfw_UpdateGamepads() in imgui_impl_glfw.cpp.o
_glfwGetKey, referenced from:
ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow*) in imgui_impl_glfw.cpp.o
...
_glfwGetKeyName, referenced from:
ImGui_ImplGlfw_TranslateUntranslatedKey(int, int) in imgui_impl_glfw.cpp.o
_glfwGetTime, referenced from:
ImGui_ImplGlfw_NewFrame() in imgui_impl_glfw.cpp.o
_glfwGetWindowAttrib, referenced from:
ImGui_ImplGlfw_UpdateMouseData() in imgui_impl_glfw.cpp.o
_glfwGetWindowSize, referenced from:
ImGui_ImplGlfw_NewFrame() in imgui_impl_glfw.cpp.o
_glfwInit, referenced from:
_main in main.cpp.o
_glfwMakeContextCurrent, referenced from:
_main in main.cpp.o
_glfwPollEvents, referenced from:
_main in main.cpp.o
_glfwSetCharCallback, referenced from:
ImGui_ImplGlfw_InstallCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
_glfwSetClipboardString, referenced from:
ImGui_ImplGlfw_SetClipboardText(void*, char const*) in imgui_impl_glfw.cpp.o
_glfwSetCursor, referenced from:
ImGui_ImplGlfw_UpdateMouseCursor() in imgui_impl_glfw.cpp.o
_glfwSetCursorEnterCallback, referenced from:
ImGui_ImplGlfw_InstallCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
_glfwSetCursorPos, referenced from:
ImGui_ImplGlfw_UpdateMouseData() in imgui_impl_glfw.cpp.o
_glfwSetCursorPosCallback, referenced from:
ImGui_ImplGlfw_InstallCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
_glfwSetErrorCallback, referenced from:
ImGui_ImplGlfw_TranslateUntranslatedKey(int, int) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_TranslateUntranslatedKey(int, int) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_Init(GLFWwindow*, bool, GlfwClientApi) in imgui_impl_glfw.cpp.o
_main in main.cpp.o
_glfwSetInputMode, referenced from:
ImGui_ImplGlfw_UpdateMouseCursor() in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_UpdateMouseCursor() in imgui_impl_glfw.cpp.o
_glfwSetKeyCallback, referenced from:
ImGui_ImplGlfw_InstallCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
_glfwSetMonitorCallback, referenced from:
ImGui_ImplGlfw_InstallCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
_glfwSetMouseButtonCallback, referenced from:
ImGui_ImplGlfw_InstallCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
_glfwSetScrollCallback, referenced from:
ImGui_ImplGlfw_InstallCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
_glfwSetWindowFocusCallback, referenced from:
ImGui_ImplGlfw_InstallCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow*) in imgui_impl_glfw.cpp.o
_glfwSwapBuffers, referenced from:
_main in main.cpp.o
_glfwSwapInterval, referenced from:
_main in main.cpp.o
_glfwTerminate, referenced from:
_main in main.cpp.o
_glfwWindowHint, referenced from:
_main in main.cpp.o
_main in main.cpp.o
_main in main.cpp.o
_main in main.cpp.o
_glfwWindowShouldClose, referenced from:
_main in main.cpp.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I tried un-including directories that weren't required in the cmakelists file, as well as combing through all the included files to make sure there weren't any undefined functions but I wasn't able to find anything that stood out. I used the list of undefined symbols and traced back through the code to see if I could find anywhere there could be an error but once again found nothing. Im newer to using make for compiling projects so any help in that department too would be greatly appreciated!