如何在不同的静态库中拥有函数的声明和定义
How to have the declaration and the definition of a function in different static libraries
我想让这件事发生。在一个静态库中声明函数,并在另一个静态库中声明函数的定义。下面是一个示例:
在利巴·
// Foo.h
class Foo
{
public:
void Bar() const;
};
在LibB.a
// FooPlatformSpecific.h
inline void Foo::Bar() const
{
}
然后在 LibC.dylib 中
// Myfile.cpp
#include "Liba/Foo.h"
void useTheFunction()
{
Foo foo;
foo.Bar();
}
我需要使 Bar 内联一些评论,这样它就不会生成重复的符号。现在我的问题是它没有链接它给了我一个未定义的符号。
一种解决方案是使 Bar 定义不内联,而是在 LibB.a 的 cpp 中,但这会阻碍编译器的内联可能性。
有没有办法解决这个问题?
这是行不通的,因为声明驻留在标头中,而定义驻留在库中。所以它们已经分开了,如果你在 .h
中声明并在 .cpp
中实现.
相关文章:
- 在函数中拥有函数原型的目的是什么?
- 谁拥有作为指向 Windows API 函数的指针传递的值?
- 是否可以获取成员函数模板参数的拥有对象?
- 拥有"受保护的非虚拟析构函数"与"受保护虚拟析构构函数"有什么好处
- 在C++中,有没有一种方法可以让我在不传递参数的情况下拥有一个函数
- C++ shared_ptr调用拥有对象的解构函数
- 使用 lambda/std::function 删除拥有该函数的对象
- C++移动拥有指针成员的构造函数
- 迫使QbyTearray将通过的C风格阵列拥有其构造函数
- 拥有这个未使用的函数 Init 有什么意义
- 如何有效地传递 std::vector<cv::P oint3f> 的子向量作为参数(不拥有函数)
- 拥有一个没有构造函数的类是否有意义
- 为什么在派生最多的类的初始值设定项列表中显式调用虚拟基类构造函数的规则,而较老的祖先已经拥有它?
- 获得错误C 即使拥有所有构造函数,也没有匹配功能
- 将类的实例传递给另一个构造函数,该构造函数将其对象添加到所传递实例所拥有的列表中
- 如何在不同的静态库中拥有函数的声明和定义
- 有没有可能拥有C++模板函数,它接受任何类型T的集合
- 拥有特定于实例的io_service、解析器等可以 VS 在每个函数中创建它们
- 我怎样才能在 C++ 中拥有一组函数
- 如何在类中拥有函数指针