gpt4 book ai didi

c++ - 如何在C++类中调用静态库函数?

转载 作者:搜寻专家 更新时间:2023-10-31 01:26:39 24 4
gpt4 key购买 nike

<分区>

我的类的头文件定义为:

namespace mip {
class CustomStatic {
public:
static const char* GetVersion();
};
}

类文件定义为:

#include "CustomStatic.h"

namespace mip {
static const char* GetVersion() {
return "hello";
}
}

我正在从我的主类访问这个静态函数

#include "CustomStatic.h"

#include <iostream>

using std::cout;
using mip::CustomStatic;

int main() {
const char *msg = mip::CustomStatic::GetVersion();
cout << "Version " << msg << "\n";
}

当我尝试使用-编译它时

g++ -std=c++11 -I CustomStatic.h  MainApp.cpp CustomStatic.cpp

我得到的错误是:

Undefined symbols for architecture x86_64:
"mip::CustomStatic::GetVersion()", referenced from: _main in MainApp-feb286.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com