目录结构
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(ce)
add_library(k1 SHARED "./account_dir/Account.cpp" "./account_dir/Account.h")
add_executable(exe1 "./test_account/test_account.cpp")
target_include_directories(exe1 PUBLIC "./account_dir")
target_link_libraries(exe1 k1)
创建2个同级目录:test_account、account_dir、
test_account.cpp 执行文件
#include <iostream>
#include "Account.h"
int main()
{
Account alice_account;
std::cout << "test Account 的main函数" << std::endl;
return 0;
}
Account.cpp 库文件
#include "Account.h"
#include <iostream>
Account::Account()
{
std::cout << "构造函数Account::Account()" << std::endl;
}
Account::~Account()
{
std::cout << "析构函数Account::~Account()" << std::endl;
}
Account.h 库文件
#ifndef Account_H
#define Account_H
class Account
{
private:
public:
Account();
~Account();
};
#endif