DevC++实现项目中多文件生成可执行文件、获取动态库文件句柄

在DevC++中新建项目consol application生成一个项目。
编写以下程序:

//main.cpp
#include 
#include "func1.h"
#include "func2.h"
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) 
{
	func1();
	func2();
	return 0;
}
//func1.h
#pragma once


void func1();
//func1.cpp
#include 
#include "func1.h" 
using namespace std;

void func1()
{
	cout<<"hello world ????"<<endl;
}
//func2.h
#pragma once


void func2();
//func2.cpp
#include 
#include "func2.h" 
using namespace std;

void func2()
{
	cout<<"hello world !!!!"<<endl;
}

最后在main.cpp中编译就可以把这个项目中的几个文件链接生成可执行文件了。


获取动态库文件句柄

#include 
#include 
#include  
using namespace std;


int main(){
    const char *p = "./SMBA.so";
    void *handle = dlopen(p, RTLD_LAZY);
    if (!handle) {
        cout << dlerror() << endl;
        return 1;
    }
    cout<<"success"<<endl;
}

你可能感兴趣的:(课程设计/实践)