Существует динамический код библиотеки, структурированный следующим образом: < /p>
cmakelists.txt:
Код: Выделить всё
cmake_minimum_required(VERSION 3.24)
project(foo)
set(CMAKE_CXX_STANDARD 17)
add_library(foo SHARED library.cpp)
target_compile_definitions(foo PRIVATE MYLIB_EXPORTS)
Код: Выделить всё
#pragma once
#ifdef _WIN32
#ifdef MYLIB_EXPORTS
#define MYLIB_API __declspec(dllexport)
#else
#define MYLIB_API __declspec(dllimport)
#endif
#else
#define MYLIB_API
#endif
#include
class Foo {
public:
int a = 123;
void say_hello();
};
extern "C" MYLIB_API void say_hello_wrapper() {
Foo obj;
obj.say_hello();
}
Код: Выделить всё
#include
#include "library.h"
void Foo::say_hello() {
std::cout
Strong> clectists.txt:[/b]> >
Подробнее здесь: [url]https://stackoverflow.com/questions/79584475/import-export-of-functions-from-a-shared-library-with-implicit-linking-c[/url]