導航:首頁 > 源碼編譯 > scons編譯語句

scons編譯語句

發布時間:2023-07-21 03:26:01

㈠ jsoncpp linux下怎麼編譯

# tar zxvf scons-2.1.0.tar.gz
# tar zxvf jsoncpp-src-0.5.0.tar.gz

設定環境變數【關鍵】,絕對路徑
# export MYSCONS=解壓的路徑
# export SCONS_LIB_DIR=$MYSCONS/engine

# cd jsoncpp-src-0.5.0
# python $MYSCONS/script/scons platform=linux-gcc
編譯成功後,在在jsoncpp-src-0.5.0/libs/目錄下找到相應的*.a和*.so
可以修改為:mv libjson_linux-gcc-4.4.6_libmt.so libjson.so


0

㈡ scons 怎麼忽視某個.c文件

介紹,scons用的是python語法。需要安裝python和scons後才能運行,能夠跨平台。比較automake自動生成makefile文件,scons可以認為直接是make的功能,因為只需要執行scons命令就等於執行了make的功能。
現在有一個hello.c的文件。
新建一個SConstruct文件,是一個python腳本文件。
Program('hello.c') 編譯hello.c並生成.o文件和可執行文件
Object('hello.c') 編譯hello.c但只生成生成.o文件
這兩個方法都是python的method。
如果想執行clean操作,我們不需要再象makefile那樣指名make clean語句,而是直接執行scons -c 或者scons -clean就可以。程序會根據SConstruct文件內容自動清除。

SConstruct的讀取和執行順序是彼此獨立的,直接看以下例子。
SConstruct文件內容:
print "Calling Program('hello.c')"
Program('hello.c')
print "Calling Program('goodbye.c')"
Program('goodbye.c')
print "Finished calling Program()"

㈢ 怎樣使用Scons生成 交叉編譯的動態庫

第一步,我先從簡單的調用出發,定義了一個簡單的函數,該函數僅僅實現一個整數加法求和:

LIBEXPORT_API int mySum(int a,int b){ return a+b;}
C# 導入定義:

public class RefComm
{
[DllImport("LibEncrypt.dll",
EntryPoint=" mySum ",
CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
public static extern int mySum (int a,int b);
}
在C#中調用測試:

int iSum = RefComm.mySum(,);

運行查看結果iSum為5,調用正確。第一步試驗完成,說明在C#中能夠調用自定義的動態鏈接庫函數。

第二步,我定義了字元串操作的函數(簡單起見,還是採用前面的函數名),返回結果為字元串:

LIBEXPORT_API char *mySum(char *a,char *b){sprintf(b,"%s",a); return a;}
C# 導入定義:

public class RefComm
{
[DllImport("LibEncrypt.dll",
EntryPoint=" mySum ",
CharSet=CharSet.Auto,
CallingConvention=CallingConvention.StdCall)]
public static extern string mySum (string a, string b);
}
在C#中調用測試:

string strDest="";
string strTmp= RefComm.mySum("45", strDest);

運行查看結果 strTmp 為"45",但是strDest為空。我修改動態鏈接庫實現,返回結果為串b:

LIBEXPORT_API char *mySum(char *a,char *b){sprintf(b,"%s",a) return b;}
修改 C# 導入定義,將串b修改為ref方式:

public class RefComm
{
[DllImport("LibEncrypt.dll",
EntryPoint=" mySum ",
CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
public static extern string mySum (string a, ref string b);
}
在C#中再調用測試:

string strDest="";
string strTmp= RefComm.mySum("45", ref strDest);
運行查看結果 strTmp 和 strDest 均不對,含不可見字元。再修改 C# 導入定義,將CharSet從Auto修改為Ansi:

public class RefComm
{
[DllImport("LibEncrypt.dll",
EntryPoint=" mySum ",
CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
public static extern string mySum (string a, string b);
}
在C#中再調用測試:

string strDest="";
string strTmp= RefComm. mySum("45", ref strDest);
運行查看結果 strTmp 為"45",但是串 strDest 沒有賦值。第二步實現函數返回串,但是在函數出口參數中沒能進行輸出。再次修改 C# 導入定義,將串b修改為引用(ref):

public class RefComm
{
[DllImport("LibEncrypt.dll",
EntryPoint=" mySum ",
CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
public static extern string mySum (string a, ref string b);
}

運行時調用失敗,不能繼續執行。

第三步,修改動態鏈接庫實現,將b修改為雙重指針:

LIBEXPORT_API char *mySum(char *a,char **b){sprintf((*b),"%s",a); return *b;}
C#導入定義:

public class RefComm
{
[DllImport("LibEncrypt.dll",
EntryPoint=" mySum ",
CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
public static extern string mySum (string a, ref string b);
}
在C#中調用測試:

string strDest="";
string strTmp= RefComm. mySum("45", ref strDest);

運行查看結果 strTmp 和 strDest 均為"45",調用正確。第三步實現了函數出口參數正確輸出結果。

第四步,修改動態鏈接庫實現,實現整數參數的輸出:

LIBEXPORT_API int mySum(int a,int b,int *c){ *c=a+b; return *c;}
C#導入的定義:

public class RefComm
{
[DllImport("LibEncrypt.dll",
EntryPoint=" mySum ",
CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
public static extern int mySum (int a, int b,ref int c);
}
在C#中調用測試:

int c=0;
int iSum= RefComm. mySum(,, ref c);

運行查看結果iSum 和c均為5,調用正確。

經過以上幾個步驟的試驗,基本掌握了如何定義動態庫函數以及如何在 C# 定義導入,有此基礎,很快我實現了變長加密函數在 C# 中的調用,至此目標實現。

三、結論

在 C# 中調用 C++ 編寫的動態鏈接庫函數,如果需要出口參數輸出,則需要使用指針,對於字元串,則需要使用雙重指針,對於 C# 的導入定義,則需要使用引用(ref)定義。

對於函數返回值,C# 導入定義和 C++ 動態庫函數聲明定義需要保持一致,否則會出現函數調用失敗。定義導入時,一定注意 CharSet 和 CallingConvention 參數,否則導致調用失敗或結果異常。運行時,動態鏈接庫放在 C# 程序的目錄下即可,我這里是一個 C# 的動態鏈接庫,兩個動態鏈接庫就在同一個目錄下運行。

㈣ 新人求教 驅動源碼編譯安裝

1、安裝scons
(1) 下載python2.7, 使用x86_32位,因為scons只有32位安裝包可用;
(2) 下載scons2.3.0;
(3) 安裝python 和 scons, 將C:\Python27\Scripts寫入PATH;
(4) 下載安裝pywin32 ,It is recommended you install pywin32 if you want to do parallel builds (scons -j)

2、安裝boost庫(1.49版本).
解壓後雙擊bootstrap.bat,生成bjam.exe後,cd到目錄c:\boost下,(將boost_1_49更名為boost了)編譯boost。
編譯命令:C:\boost>bjam variant=release --with-filesystem --with-thread --with-date_time --with-program_options threading=multi toolset=msvc-10.0 link=static runtime-link=static address-model=32
這是使用VS2010環境編譯的release版本,編譯完成後,生成C:\boost\stage\lib文件夾,下面有6個lib庫:

如果要編譯成debug版本,使用命令:bjam variant=debug --with-filesystem --with-thread --with-date_time --with-program_options threading=multi toolset=msvc-10.0 link=static runtime-link=static address-model=32

編譯完成後,生成C:\boost\stage\lib文件夾,下面有10個lib庫和dll:

此處為MongoDB文檔中對於編譯boost庫的要求原文:
When using bjam, MongoDB expects
variant=debug for debug builds, and variant=release for release builds
threading=multi
link=static runtime-link=static for release builds
address-model=64 for 64 bit(64位的話,把32換為64)。link=static runtime-link=static,boost需要編譯成靜態庫,因為mongodb只會去鏈接boost的靜態庫
address-model=64在win7 64環境下此項必須,不加在編譯mongodb的c++ client時會出現鏈接錯誤。

3、下載mongo2.4.6源碼 http://www.mongodb.org/downloads官網下載
編譯Mongoclient.lib

cmd命令提示符下,cd到解壓後的文件目錄,例如我放在了E盤,E:\mongodb-src-r2.4.6,輸入命令:
scons –-dd --32 mongoclient.lib // build C++ client driver library
Add --64 or --32 to get the 64- and 32-bit versions, respectively. Replace --release with --dd to build a debug build.
編譯後在mongodb\build\win32\32\dd\client_build\生成mongoclient.lib.

4、測試程序
就用Mongodb自帶的例子吧,使用VS2010打開E:\mongodb-src-r2.4.6\src\mongo\client\examples中的simple_client_demo.vcxproj,編譯,會提示生成simple_client_demo.sln,保存。
使用debug模式,配置工程環境:打開工程->屬性,配置Configuration Properties下的VC++ Directories,頭文件路徑添加C:\boost,Lib庫路徑添加boost的lib,以及mongodb client的lib:
C:\boost\stage\lib

E:\mongodb-src-r2.4.6\build\win32\32\dd\client_build
進入C/C++下面的Code Generation,將Runtime Library設置為Multi-threaded Debug (/MTd)
進入Linker下面的Input,設置Additional Dependencies,添加ws2_32.lib,psapi.lib,Dbghelp.lib,mongoclient.lib
將E:\mongodb-src-r2.4.6\build\win32\32\dd\mongo\base下生成的error_codes.h和error_codes.cpp文件,拷貝到E:\mongodb-src-r2.4.6\src\mongo\base目錄下。
ok,編譯、運行.

5、問題解決
error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(dbclient.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(assert_util.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(jsobj.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(status.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(mutexdebugger.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj

VS的版本不匹配,lib是在更高級的版本中編譯生成的,而使用的時候,是在低級版本中使用的,所以出現了不匹配的錯誤。例如,我在VS2010 SP1和VS2012的環境下編譯的,而使用是在VS2010上使用,所以在編譯時,出現了以上問題。

1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymCleanup
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymGetMoleInfo64
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymInitialize
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_StackWalk64
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymFromAddr

在工程依賴庫中添加Dbghelp.lib

其它問題,看看你手頭的編譯器、編譯出來的boost庫版本、mongoclient.lib的版本,是否對應好了。

㈤ 請教Scons python 編譯問題

一、概述

scons是一個Python寫的自動化構建工具,和GNU make相比優點明顯:
1、移植性:python能運行的地方,就能運行scons
2、擴展性:理論上scons只是提供了python的類,scons使用者可以在這個類的基礎上做所有python能做的事情。比如想把一個已經使用了Makefile大型工程切換到scons,就可以保留原來的Makefile,並用python解析Makefile中的編譯選項、源/目標文件等,作為參數傳遞給scons,完成編譯。
3、智能:Scons繼承了autoconf/automake的功能,自動解析系統的include路徑、typedef等;「以全局的觀點來看所有的依賴關系」

二、scons文件

scons中可能出現的文件:
SConstruct,Sconstruct,sconstruct,SConscript

scons將在當前目錄以下次序 SConstruct,Sconstruct,sconstruct 來搜索配置文件,從讀取的第一個文件中讀取相關配置。
在配置文件SConstruct中可以使用函數SConscript()函數來定附屬的配置文件。按慣例,這些附屬配置文件被命名為」SConscript」,當然也可以使用任意其它名字。

三、scons的命令行參數
scons: 執行SConstruct中腳本
scons -c clean
scons -Q 只顯示編譯信息,去除多餘的列印信息
scons -Q --implicit-cache hello 保存依賴關系
--implicit-deps-changed 強制更新依賴關系
--implicit-deps-unchanged 強制使用原先的依賴關系,即使已經改變

四、SConstruct提供的方法

1、Program:生成可執行文件

Program('hello.c') 編譯hello.c可執行文件,根據系統自動生成(hello.exe on Windows; hello on POSIX)
Program('hello','hello.c') 指定Output文件名(hello.exe on Windows; hello on POSIX)
Program(['hello.c', 'file1.c', 'file2.c']) 編譯多個文件,Output文件名以第一個文件命名
Program(source = "hello.c",target = "hello")
Program(target = "hello" , source = "hello.c")
Program('hello', Split('hello.c file1.c file2.c')) 編譯多個文件

Program(Glob("*.c"))
src = ["hello.c","foo.c"];Program(src)

2、Object:生成目標文件

Object('hello.c') 編譯hello.c目標文件,根據系統自動生成(hello.obj on Windows; hello.o on POSIX)

3、Library:生成靜態/動態庫文件

Library('foo', ['f1.c', 'f2.c', 'f3.c']) 編譯library
SharedLibrary('foo', ['f1.c', 'f2.c', 'f3.c']) 編譯 shared library
StaticLibrary('bar', ['f4.c', 'f5.c', 'f6.c']) 編譯 static library

庫的使用:

Program('prog.c', LIBS=['foo', 'bar'], LIBPATH='.') 連接庫,不需加後綴或是前綴

4、SourceSignatures:判斷源文件是否修改
SourceSignatures('MD5') 根據內容是否改變,默認方式
SourceSignatures('timestamp') 根據修改時間

5、TargetSignatures:判斷目標文件是否改變
TargetSignatures('build') 根據編譯結果
TargetSignatures('content') 根據文件內容,如果只是加了句注釋,將不會被重新編譯

6、Ignore:忽略依賴關系

Ignore(hello, 'hello.h') 忽略某個依賴關系

7、Depends:明確依賴關系

Depends(hello, 'other_file') 明確依賴關系

8、SConscript:scons的配置文件。

源文件的目錄結構如下:
src:
| SConstruct
|test.cpp
| mA(目錄):
| SConscript
| func.cpp
其中test.cpp為主文件,中調用func.cpp中定義的函數

SConstruct內容如下:

[cpp]view plain

㈥ 請教Scons python 編譯問題

哈哈,解決問題的方法不可思議,我看了半天main.py後,就把那2個代碼SConstruct 和SConscript拷到python的根目錄下,居然編譯一大半,不過還有問題,請幫助我;提示如下
E:\svn_rt-thread\rt-thread\bsp\mini2440>scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build\bsp
armcc -o build\bsp\application.o -c --device DARMSS9 --apcs=interwork --diag_sup
press=870 -I"C:\Keil\ARM\BIN30/ARM/RV31/INC" -g -O0 -IE:\svn_rt-thread\rt-thread
\include -IE:\svn_rt-thread\rt-thread\libcpu\arm\s3c24x0 -IE:\svn_rt-thread\rt-t
hread\libcpu\arm\common -I. -IE:\svn_rt-thread\rt-thread -IE:\svn_rt-thread\rt-t
hread\components\finsh -IE:\svn_rt-thread\rt-thread\components\dfs -IE:\svn_rt-t
hread\rt-thread\components\dfs\include -IE:\svn_rt-thread\rt-thread\components\r
tgui\include -IE:\svn_rt-thread\rt-thread\components\rgtui\common -IE:\svn_rt-th
read\rt-thread\components\rtgui\server -IE:\svn_rt-thread\rt-thread\components\r
tgui\widgets application.c
'armcc' 不是內部或外部命令,也不是可運行的程序
或批處理文件。
scons: *** [build\bsp\application.o] Error 1
scons: building terminated because of errors.

E:\svn_rt-thread\rt-thread\bsp\mini2440>
以下圖片

閱讀全文

與scons編譯語句相關的資料

熱點內容
android讀取res 瀏覽:139
南方周末pdf 瀏覽:25
玻璃比重演算法 瀏覽:226
怎麼把pdf文件轉成jpg格式的 瀏覽:111
雲伺服器ecs測評 瀏覽:320
俄羅斯解壓縮軟體 瀏覽:685
富士通單片機模擬器 瀏覽:846
華為無線配置命令 瀏覽:150
dumpjava內存 瀏覽:874
貼吧app怎麼復制貼子鏈接 瀏覽:260
果然程序員大多都容易禿頭 瀏覽:909
優選源碼庫會員 瀏覽:583
便箋能否整理與設立文件夾管理 瀏覽:601
同花順籌碼起爆公式源碼大全 瀏覽:55
android音頻移植 瀏覽:1000
國際服伺服器繁忙怎麼重新連接 瀏覽:355
pdf怎麼保存jpg 瀏覽:775
伺服器被封號怎麼解封 瀏覽:773
雲伺服器查看內存 瀏覽:357
怎麼在韓國伺服器玩絕地求生 瀏覽:943