日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Ubuntu下CodeBlocks的安装、配置及静态库动态库的简单使用举例

發(fā)布時間:2023/11/27 生活经验 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Ubuntu下CodeBlocks的安装、配置及静态库动态库的简单使用举例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1、? 從Ubuntu Software Center中搜索Code::Blocks并安裝;

2、? 在第一次啟動時選擇GNU GCC Compiler作為默認的編譯器;

3、? 生成靜態(tài)庫并調(diào)用操作步驟,代碼同?http://blog.csdn.net/fengbingchun/article/details/17994489

3.1、New file ->Project… -> 選中Static library, -> Go -> Next: Project title:test_lib, Folder to create project in: /home/spring/CodeBlocks/ ,Project filename: test_lib.cbp, Resulting filename: /home/spring/CodeBlocks/test_lib/test_lib.cbp , Next->: Compiler: GNU GCC Compiler ,選中Create”Debug”configuration和Create”Release”configuration,其它默認, ->Finish;

3.2、將上面提到的include和src兩個文件夾復制到與test_lib.cbp同一目錄下;

3.3、改寫src包括的相關(guān)文件,如#include“add.h”改為#include ”../include/add.h”等,移除工程中生成的main.c文件,并將src和include的文件全部加載到此工程中;

3.4、打開此工程屬性設(shè)置 ->Build targets:Debug下,Output filename改為libtest_lib[linux_dbg_32].a, Release下,Output filename改為libtest_lib[linux_rel_32].a,編譯即可生成相應(yīng)的靜態(tài)庫;

3.5、新建一個控制臺工程,工程名為CallStaticLibrary,其它默認,此工程main.cpp文件內(nèi)容為:

#include "../test_lib/include/hybrid.h"
#include <iostream>using namespace std;int main(int argc, char* argv[])
{int a=10, b=200, c=-34, d=92;int result = CalHybrid(a, b, c, d);cout<<result<<endl;return 0;
}

3.6、把靜態(tài)庫文件鏈接到CallStaticLibrary工程中,選中工程,build options -> Debug(Release) ?-> Linker settings -> Add -> ../test_lib/libtest_lib[linux_dbg_32].a (../test_lib/libtest_lib[linux_rel_32].a),運行結(jié)果為 -6256 正確;

4、? 生成動態(tài)庫并調(diào)用操作步驟:

4.1、Newfile ->Project… -> 選中Shared library, -> Go -> Next -> C++ -> Next: Project title:test_bin, Folder to create project in: /home/spring/CodeBlocks/ ,Project filename: test_bin.cbp , Resulting filename:/home/spring/CodeBlocks/test_lib/test_bin.cbp , Next ->: Compiler: GNU GCCCompiler ,選中Create”Debug”configuration和Create”Release”configuration,其它默認, ->Finish;

4.2、將上面用過的include和src兩個文件夾復制到與test_bin.cbp同一目錄下;

4.3、移除工程中生成的main.cpp文件,并將src和include的文件全部加載到此工程中,選中工程 ->Add files.. -> 選擇所需文件;

4.4、打開此工程屬性設(shè)置 ->Build targets:Debug下,Output filename改為bin/Debug/libtest_bin[linux_dbg_32].so, Release下,Outputfilename改為bin/Release/libtest_bin[linux_rel_32].so ,編譯即可生成相應(yīng)的動態(tài)庫;

4.5、新建一個控制臺工程,工程名為CallDynamicLibrary,其它默認,此工程main.cpp文件內(nèi)容為與3.5相似,只把#include"../test_lib/include/hybrid.h"改為#include "../test_bin/include/hybrid.h"即可;

4.6、把動態(tài)庫文件鏈接到CallDynamicLibrary工程中,選中工程,build options -> Debug(Release)? -> Linker settings -> Add -> ../test_bin/bin/Debug/libtest_bin[linux_dbg_32].so (../test_bin/bin/Release/libtest_bin[linux_rel_32].so),運行結(jié)果為 -6256 正確。

總結(jié)

以上是生活随笔為你收集整理的Ubuntu下CodeBlocks的安装、配置及静态库动态库的简单使用举例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

歡迎分享!

轉(zhuǎn)載請說明來源于"生活随笔",并保留原作者的名字。

本文地址:Ubuntu下CodeBlocks的安装、配置及静态库动态库