CMakeLists.txt
project(aaa)
add_library(aaa SHARED aaa.cpp)
add_executable(bbb bbb.cpp)
target_link_libraries(bbb aaa)
aaa.h
#pragma once
#ifndef AAA_AAA_H
#define AAA_AAA_H
#endif
#ifdef BUILD_AAA_DLL
#define IO_AAA_DLL __declspec(export)
#else
#define IO_AAA_DLL __declspec(import)
#endif
IO_AAA_DLL class father
{
public:
void hello(void);
double sum(double a, double b);
};
aaa.cpp
#define BUILD_AAA_DLL
#include "aaa.h"
#include <iostream>
using namespace std;
IO_AAA_DLL void father::hello(void)
{
cout << "Hello from dll.class!n" << endl;
}
IO_AAA_DLL double father::sum(double a, double b)
{
return a + b;
}
bbb.cpp
#include "aaa.h"
#pragma comment(a, "C:UsersPerelman.CLion2016.1systemcmakegeneratedaaa-4d5bae384d5bae38Debuglibaaa.a")
#include <iostream>
using namespace std;
int main()
{
father child;
child.hello();
cout << child.sum(10, 20) << endl;
return 0;
}
原文链接: https://www.cnblogs.com/blog-3123958139/p/5580855.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/235126
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!