c++ - 将 C++ 类及其派生类放在特定部分

标签 c++ linker g++ ld linker-scripts

我的链接描述文件中有一个部分设置,我想将特定 C++ 类的所有代码以及从该部分派(dispatch)生的所有其他类放在该部分中。这可能吗?

我已经试过了,但收到警告:

class Test __attribute__ ((section ("ss"), aligned(0x40)));

class Test {
public:
    void Foo(int a) {
        printf("Hello\n");
    }        
};

警告:

test.cpp:19:7: warning: attribute ignored in declaration of ‘class Test’ [-Wattributes]
 class Test __attribute__ ((section ("ss"), aligned(0x40)));

最佳答案

不幸的是,您必须将 section 属性应用于类中的每个单独方法,例如:

class Test {
public:
    __attribute__ ((section ("ss"), aligned(0x40))) void Foo(int a) {
        printf("Hello\n");
    }        
};

关于c++ - 将 C++ 类及其派生类放在特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57600013/

相关文章:

android - 需要关于使用 const 参数覆盖函数的警告

c++ - 了解 C++ vtable 和 RTTI

c++ - 每次制作都会创建预编译头?

c++ - 使用C++将时间戳转换为格式化的日期时间

C++ 继承 - 如何使用指向基类对象的指针访问子方法

c++ - 单一来源项目结构的缺点是什么?

C++定义的?宏?在 header 中可见但在实现中丢失(链接器报告外部未解决)

Swift 测试链接器错误

c++ - Mingw64-w64 属性(格式)和 <cinttypes> header

c++ - 如何让 CLion 将 .c 文件识别为 C++(而不是普通的 C)