codeblocks 下 添加动态链接库

手动创建:

(1)file->new->project->dynamic link library;

名字:dynamiclib

将工程自动生成的main.cpp文件删除,自动添加一个.c文件(trydll.c) 将main.h 文件删除 创建一个trydll.h文件:

trydll.c:

#include <stdio.h>
#include <string.h>

#include "trydll.h"

void hello(){
    printf("hello\n");
    printf("xd");
}

trydll.h:

#ifndef __TRYDLL_H__INCLUDED
#define __TRYDLL_H__INCLUDED

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus
extern "C"
{
#endif

void DLL_EXPORT hello();

#ifdef __cplusplus
}
#endif

#endif // __trydll_H__

将工程编译,生成:

\dynamiclib\bin\Debug下:


测试:

创建一个c工程,实现上面动态库的调用:

将trydll.h文件添加进去 并且将上面的:
文件 添加到新的trydll工程下的 \bin\Debug\目录下。
编译-->执行......:

#include <stdio.h>
#include <stdlib.h>

#include "trydll.h"

int main()
{
    hello();
    printf("Hello world!\n");
    return 0;
}
结果:


可以简单的实现:链接动态库的方法。

还有就是在:project-->build options->Debug->linker settings 添加(生成动态库那个路径下的文件):


但是 此方法 我没有实现成功,还望大神们指点。
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值