0

Here is the complete error:

Undefined symbols for architecture arm64:
  "ug::UgWindow::UgWindow(int, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      _main in main.cpp.o
  "ug::UgWindow::~UgWindow()", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [untitled-game] Error 1
make[1]: *** [CMakeFiles/untitled-game.dir/all] Error 2
make: *** [all] Error 2

I am using cmake to build my files, i have created a UgWindow hpp file and cpp file to define its functionality here is the hpp file and cpp file.

HPP

#pragma once

#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>

#include <string>

namespace ug {
    
    class UgWindow{
        public:
            UgWindow(int w, int h, std::string name);
            ~UgWindow();

            bool shouldClose(){ return glfwWindowShouldClose(window); }
        private:
            void initWindow();

            const int width;
            const int height;
            std::string windowName;
            GLFWwindow *window;
    };
}

here is the cpp file:

#include "ug_window.hpp"

namespace ug {

UgWindow::UgWindow(int w, int h,  std::string name): width{w}, height{h}, windowName{name} {
    initWindow();
} 

UgWindow::~UgWindow() {
    glfwDestroyWindow(window);
    glfwTerminate();
}

void UgWindow::initWindow() {
    glfwInit();

    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

    window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr);
}

}

I am trying to use vulkan with glfw and glm, im a noob with c++ and have absolutely no idea how to fix this or what the problem is.

Also this is my cmake file:

project(untitled-game)
cmake_minimum_required(VERSION 3.22.4)


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++17  " )

add_executable(${PROJECT_NAME} main.cpp)

find_package(Vulkan REQUIRED)
find_package(glfw3 3.3 REQUIRED)

if (VULKAN_FOUND)
    message(STATUS "Found Vulkan, Including and Linking now")
    include_directories(${Vulkan_INCLUDE_DIRS})
    target_link_libraries (${PROJECT_NAME} ${Vulkan_LIBRARIES} glfw)
endif (VULKAN_FOUND)

Jherico
  • 28,584
  • 8
  • 61
  • 87
Blank
  • 271
  • 2
  • 12

1 Answers1

2
add_executable(${PROJECT_NAME} main.cpp)

Here you say that the executable program is to be built from the main.cpp source file, and only the main.cpp source file.

You need to list all your source files:

add_executable(${PROJECT_NAME} main.cpp ug_window.cpp)
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thanks iv been sitting on this error for 2 days, most things make no sense to me yet. – Blank Feb 16 '23 at 07:51
  • 1
    @Blank Google is always your friend with weird c++ errors, I'm an experienced user and still occasionally resort to Google when something obscure comes up. For this one see https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – Alan Birtles Feb 16 '23 at 09:47