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
    评论
回答: 在CodeBlocks环境下创建动态链接库的步骤如下:首先,创建一个C工程,并在工程中添加动态链接库的头文件trydll.h。然后,将生成的动态链接库文件libDynamic library.a、Dynamic library.dll、libDynamic library.def文件复制到工程的\bin\Debug\目录下。接下来,编写代码并进行编译。代码示例如下: #include <stdio.h> #include <stdlib.h> #include "trydll.h" int main() { hello(); printf("Hello world!\n"); return 0; } 编译并执行代码后,可以实现链接动态库的方法。另外,还可以通过在CodeBlocks的项目设置中添加动态库文件的路径来实现链接。但是,如果这种方法没有成功,可能需要进一步检查设置是否正确。希望对您有所帮助。 #### 引用[.reference_title] - *1* [动态链接库codeblocks)](https://blog.csdn.net/weixin_43519121/article/details/104930285)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [codeblocks中创建和调用动态链接库(dll)](https://blog.csdn.net/KlD1412/article/details/51628424)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [codeblocks添加动态链接库](https://blog.csdn.net/u011561690/article/details/40866185)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值