Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VS code Undefined symbols for architecture arm64

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#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)

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading