如何在C 类中调用静态库功能
How to call static library function in a C++ class?
我有一个类,其标题文件定义为:
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
我的错误是:
架构的未定义符号x86_64:
" mip :: customstatic :: getversion()",从: _ main在mainapp-feb286.o ld中:符号(s)架构x86_64 clang:错误:链接命令失败,出口代码失败 1(使用-v查看调用)
您的静态功能在CPP文件中未正确实现...
您需要做
之类的事情//.h
namespace mip
{
class CustomStatic
{
public:
static const char* GetVersion();
};
}
//.cpp -> note that no static keyword is required...
namespace mip
{
const char* CustomStatic::GetVersion()
{
return "hello";
}
}
//use
int main(int argc, char *argv[])
{
const char* msg{mip::CustomStatic::GetVersion()};
cout << "Version " << msg << "n";
}
相关文章:
- 如何在 c++ 中异步调用静态方法?
- 从另一个标头中的标头调用静态方法
- LNK2019 在文件中调用静态成员的方法时出错.cpp
- 为什么我不能像这样在静态成员函数中调用静态成员变量?
- Windows 是否可以调用静态库中的 WinMain 函数C++
- 从另一个动态链接库项目调用静态库函数
- 生成模板实例列表并对其调用静态函数
- 从静态方法调用静态函数指针
- 调用静态方法,收到错误:LNK2019
- 从线程内的对象调用静态方法
- 通过指针调用静态成员函数
- 调用静态记录器的格式日志方法
- 如何在C 类中调用静态库功能
- 从应用程序调用静态库时,QT创建者什么都不会发生
- Visual 2015 C++编译器:使用对象调用静态成员不会导致编译器错误
- 在不存在的对象上调用静态成员函数
- 未调用静态全局结构的析构函数
- C 调用静态方法
- 无法在不同类上编译代码调用静态功能
- C 从虚拟函数调用静态函数