Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created March 11, 2019 08:28
Show Gist options
  • Save kaityo256/a77e0645858abbda73d34cbb94125d72 to your computer and use it in GitHub Desktop.
Save kaityo256/a77e0645858abbda73d34cbb94125d72 to your computer and use it in GitHub Desktop.
weak attribute
#include "test.hpp"
int main(){
}
#include "test.hpp"
#pragma once
#include <iostream>
struct Hoge {
Hoge() {
std::cout << "Hoge" << std::endl;
}
};
__attribute__((weak)) Hoge h;
@kaityo256
Copy link
Author

$ g++ -c main.cpp
$ g++ -c sub.cpp
$ g++ main.o sub.o
$ ./a.out
Hoge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment