c++ VS代码结构arm64的未定义符号

bmp9r5qi  于 2023-02-17  发布在  其他
关注(0)|答案(1)|浏览(136)

下面是完整的错误:

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

我正在使用cmake来构建我的文件,我已经创建了一个UgWindow hpp文件和cpp文件来定义它的功能这里是hpp文件和cpp文件。
高压泵

#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;
    };
}

下面是cpp文件:

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

}

我正在尝试使用vulkan与glfw和glm,我是一个noob与c++和完全不知道如何修复这个或什么问题。
这也是我的cmake文件:

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

fcg9iug31#

add_executable(${PROJECT_NAME} main.cpp)

这里您说可执行程序将从main.cpp源文件构建,并且 * 仅 * main.cpp源文件。
您需要列出所有源文件:

add_executable(${PROJECT_NAME} main.cpp ug_window.cpp)

相关问题