Я читаю эту страницу.
Я следую ответу шаг за шагом, чтобы проверить, а также добавить
Код: Выделить всё
-fvisibility=hidden
Код: Выделить всё
//rectangle.h
#pragma once
#include
class Rectangle {
int width, height;
public:
void set_values (int,int);
int area();
};
std::shared_ptr __attribute__((visibility("default"))) get_rectangle();
Код: Выделить всё
//rectangle.cpp
#include "rectangle.h"
int Rectangle::area() {return width*height;}
void Rectangle::set_values (int x, int y) {
width = x;
height = y;
}
std::shared_ptr __attribute__((visibility("default"))) get_rectangle() {
return std::make_shared();
}
Код: Выделить всё
//main.cpp
#include "../rectangle/rectangle.h"
int main() {
auto rectangle = get_rectangle();
rectangle->set_values(2, 3);
rectangle->area();
return 0;
}
Код: Выделить всё
undefined reference to `Rectangle::set_values(int, int)'
undefined reference to `Rectangle::area()'
Код: Выделить всё
//changed rectangle.h
#pragma once
#include
class Rectangle {
int width, height;
public:
virtual void set_values (int,int);
virtual int area();
};
std::shared_ptr __attribute__((visibility("default"))) get_rectangle();
Код: Выделить всё
Use
Код: Выделить всё
librectangle.so
Код: Выделить всё
nm -C librectangle.so | grep Rectangle

Код: Выделить всё
nm -C librectangle.so | grep area

Код: Выделить всё
nm -C librectangle.so | grep set_values

обе демо добавляют
Код: Выделить всё
-visibility=hidden
Источник: https://stackoverflow.com/questions/781 ... ncorrectly