Ⅰ vs2019不小心把兩個程序弄了一個解決方案
想要解決可以根據
1.庫的分類
根據鏈接時期的不同,庫又有靜態庫和動態庫之分。
靜態庫是在鏈接階段被鏈接的(好像是廢話,但事實就是這樣),所以生成的可執行文件就不受庫的影響了,即使庫被刪除了,程序依然可以成功運行。
有別於靜態庫,動態庫的鏈接是在程序執行的時候被鏈接的。所以,即使程序編譯完,庫仍須保留在系統上,以供程序運行時調用。(TODO:鏈接動態庫時鏈接階段到底做了什麼)
2 靜態庫和動態庫的比較
鏈接靜態庫其實從某種意義上來說也是一種粘貼復制,只不過它操作則棗的對象是目標代碼而不是源碼而已。因為靜態庫被鏈接後庫就直接嵌入可執行文件中了,這樣就帶來了兩個問題。
首先就是系統空間被浪費了。這是顯而易見的,想像一下,如果多個程序鏈接了同一個庫,則每一個生成的可執行文件就都會有一個庫的副本,必然會浪費系統空間。
再者,人非聖賢,即使是精心調試的庫,也難免會有錯。一旦發現了庫中有bug,挽救起來就比較麻煩了。必須一一把鏈接該庫的程序找出來,然後重新編譯。
而動態庫的出現正彌補了靜態庫的以上弊端。因為動態庫是在程序運行時被鏈接的,所以磁碟上只須保留一份副本,因此節約了磁碟空間。如果發現了bug或要升級也很簡單,只要用新的庫把原來的替換掉就行了。
那麼,是不是靜態庫就一無是處了呢?
答曰:非也非也。不是有句話么:存在即是合理。靜態庫既然沒有湮沒在滔滔的歷史長河中,就必然有它的用武之地。想像一下這樣的情況:如果你用libpcap庫編了一個程序,要給被人運行,而他的系統上沒有裝pcap庫,該怎麼解決呢?最簡單的辦法就是編譯該程序時把所有要鏈接的庫都鏈接它們的靜態庫,這樣,就可以在別人的系統上直接運行該程序了。
所謂有得必有失,正因為動態庫在程序運行時被鏈接,故程序的運行速度和鏈接靜態庫的版本相比必然會打折扣。然而瑕不掩瑜,動態庫的不足相對於它帶來的好處在現今硬體下簡直是微不足道的,所以鏈接程序在鏈接時一般是優先鏈接動態庫的,除非用-static參數指定鏈接靜態庫。
gcc作為編譯工具,用在Linux操作系統中,可以編譯C、C++、Object-C、JAVA等語言。編譯過程中可以帶編譯選項,選擇編譯過程。
一、GCC編譯流程
1)預處理 Pre-Processing
2)編譯 Compiling
3)匯編 Assembling
4)鏈接 Linking
二、GCC編譯選項
1、gcc總體選項列表
1) -c :指編譯,不鏈接,生成目標文件「.o」。
2) -S :只編譯,不匯編,生成匯編代碼「.S」。
3) -E :只進行預編譯/預處理,不做其他處理。
4) -o file:把輸出文件輸出到file里。
5) -g :在可執行程序中包含標准調試信息。
6) -v :列印出編譯器內部編譯各過程的命令行信息和編譯器的版本。孫帶拆
7) -I dir :在頭文件的搜索路徑列表中添加dir目錄
8) -L dir :在庫文件的搜索路徑列表中添加dir目錄
9) -static :連接靜態庫(靜態庫也可以用動態庫鏈接方式鏈接)
10) -llibrary :連接名為library的庫文件(顯示指定需要鏈接的動態庫文件)
2、gcc告警和出錯選項
1) -ansi :支持符合ANSI標準的C程序
2) -pedantic :允許發出ANSI C標准所列出的全部警告信息
3) -pedantic-error :允許發出ANSI C標准所列出的全部錯誤信息
4) -w :關閉所有警告
5) -Wall :允許發出gcc提供的所有有用的報警信息
6) -werror :把所有的告警信息轉化為錯誤信息,並在告警發生時終止編譯過程
3、gcc優化選項
gcc可以對代碼進行優化,它通過編譯選項「-On」來控制優化代碼的生成,其中n是一個代表優化級別的整數。對於不同版本的gcc,
n的取值范圍不一致,比較典型的范圍為0變化到2或者3。
雖然優化選項可以加速代碼的運行速度,但對於調試而言將是一個很大的挑戰。因為代碼在經過優化之後,原先在源程序中聲明和使用
的變數很可能不再使用,控制流也可能會突然跳轉到意外的地方,循環語句也可能因為循環展開而變得到處行神都有。
三、GCC生成動態庫和靜態庫
1)動態庫生成
1.單個源文件/目標直接生成動態庫
a. gcc -fPIC -shared xxx.c -o libxxx.sob.gcc -fPIC -shared xxx.o -o libxxx.so
2.多個源文件/目標生成動態庫
a.gcc -fPIC -shared xxx1.c xxx2.c xxx3.c -o libxxx.so b.gcc -fPIC -shared xxx1.o xxx2.o xxx3.o -o libxxx.so
2)靜態庫生成
1.單個源文件/目標直接生成靜態庫
a.ar -rc libxxx.a xxx.o(正確方法)b. ar -rc libxxx.a xxx.c (靜態庫可以生成;當運行連接了該靜態庫的可執行程序會報錯:could not read symbols:Archive has no index;run ranlib to add one)
2.多個源文件/目標生成靜態庫
a.ar -rc libxxx.a xxx1.o xxx2.o xxx3.o (正確方法)b.ar -rc libxxx.a xxx1.c xxx2.c xxx3.c (靜態庫可以生成;當運行連接了該靜態庫的可執行程序會報錯:could not read symbols:Archive has no index;run ranlib to add one)
四、多個源文件生成一個可執行文件
Ⅱ gcc的基本用法
在使用GCC編譯器的時候,我們必須給出一系列必要的調用參數和文件名稱。GCC編譯器的調用參數大約有100多個,這里只介紹其中最基本、最常用的參數。具體可參考GCC Manual。
GCC最基本的用法是∶gcc [options] [filenames]
其中options就是編譯器所需要的參數,filenames給出相關的文件名稱。
-c,只編譯,不鏈接成為可執行文件,編譯器只是由輸入的.c等源代碼文件生成.o為後綴的目標文件,通常用於編譯不包含主程序的子程序文件。
-o output_filename,確定輸出文件的名稱為output_filename,同時這個名稱不能和源文件同名。如果不給出這個選項,gcc就給出預設的可執行文件a.out。
-g,產生符號調試工具(GNU的gdb)所必要的符號資訊,要想對源代碼進行調試,我們就必須加入這個選項。
-O,對程序進行優化編譯、鏈接,採用這個選項,整個源代碼會在編譯、鏈接過程中進行優化處理,這樣產生的可執行文件的執行效率可以提高,但是,編譯、鏈接的速度就相應地要慢一些。
-O2,比-O更好的優化編譯、鏈接,當然整個編譯、鏈接過程會更慢。
-Idirname,將dirname所指出的目錄加入到程序頭文件目錄列表中,是在預編譯過程中使用的參數。C程序中的頭文件包含兩種情況∶
A)#include <myinc.h>
B)#include 「myinc.h」
其中,A類使用尖括弧(< >),B類使用雙引號(「 」)。對於A類,預處理程序cpp在系統預設包含文件目錄(如/usr/include)中搜尋相應的文件,而B類,預處理程序在目標文件的文件夾內搜索相應文件。
-v gcc執行時執行的詳細過程,gcc及其相關程序的版本號
原版gcc manual該選項英文解釋
Print (on standard error output) the commands executed to run the stages of compilation. Also print the version number of the compiler driver program and of the preprocessor and the compiler proper.
編譯程序時加上該選項可以看到gcc搜索頭文件/庫文件時使用的搜索路徑!
Ⅲ gcc 編譯優化做了哪些事求解答
用過gcc的都應該知道編譯時候的-O選項吧。它就是負責編譯優化。下面列出它的說明: -O -O1 Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function. With -O, the compiler tries to rece code size and execution time, without performing any optimizations that take a great deal of compilation time. -O turns on the following optimization flags: -fdefer-pop -fdelayed-branch -fguess-branch-probability -fcprop-registers -floop-optimize -fif-conversion -fif-conver- sion2 -ftree-ccp -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-ter -ftree-lrs -ftree-sra -ftree-rename -ftree-fre -ftree-ch -funit-at-a-time -fmerge-constants -O also turns on -fomit-frame-pointer on machines where doing so does not interfere with debugging. -O doesn』t turn on -ftree-sra for the Ada compiler. This option must be explicitly speci- fied on the command line to be enabled for the Ada compiler. -O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code. -O2 turns on all optimization flags specified by -O. It also turns on the following opti- mization flags: -fthread-jumps -fcrossjumping -foptimize-sibling-calls -fcse-follow-jumps -fcse-skip-blocks -fgcse -fgcse-lm -fexpensive-optimizations -fstrength-rece -fre- run-cse-after-loop -frerun-loop-opt -fcaller-saves -fpeephole2 -fschele-insns -fsched- ule-insns2 -fsched-interblock -fsched-spec -fregmove -fstrict-aliasing -fdelete-null-pointer-checks -freorder-blocks -freorder-functions -falign-functions -falign-jumps -falign-loops -falign-labels -ftree-vrp -ftree-pre Please note the warning under -fgcse about invoking -O2 on programs that use computed gotos. -O3 Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops and -fgcse-after-reload options. -O0 Do not optimize. This is the default. -Os Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to rece code size. -Os disables the following optimization flags: -falign-functions -falign-jumps -falign-loops -falign-labels -freorder-blocks -freorder-blocks-and-partition -fprefetch-loop-arrays -ftree-vect-loop-version If you use multiple -O options, with or without level numbers, the last such option is the one that is effective. Options of the form -fflag specify machine-independent flags. Most flags have both positive and negative forms; the negative form of -ffoo would be -fno-foo. In the table below, only one of the forms is listed---the one you typically will use. You can figure out the other form by either removing no- or adding it. The following options control specific optimizations. They are either activated by -O options or are related to ones that are. You can use the following flags in the rare cases when "fine-tuning" of optimizations to be performed is desired. -fno-default-inline Do not make member functions inline by default merely because they are defined inside the class scope (C++ only). Otherwise, when you specify -O, member functions defined inside class scope are compiled inline by default; i.e., you don』t need to add inline in front of the member function name. -fno-defer-pop Always pop the arguments to each function call as soon as that function returns. For machines which must pop arguments after a function call, the compiler normally lets argu- ments accumulate on the stack for several function calls and pops them all at once. Disabled at levels -O, -O2, -O3, -Os. -fforce-mem Force memory operands to be copied into registers before doing arithmetic on them. This proces better code by making all memory references potential common subexpressions. When they are not common subexpressions, instruction combination should eliminate the separate register-load. This option is now a nop and will be removed in 4.2. -fforce-addr Force memory address constants to be copied into registers before doing arithmetic on them. -fomit-frame-pointer Don』t keep the frame pointer in a register for functions that don』t need one. This avoids the instructions to save, set up and restore frame pointers; it also makes an extra regis- ter available in many functions. It also makes debugging impossible on some machines. On some machines, such as the VAX, this flag has no effect, because the standard calling sequence automatically handles the frame pointer and nothing is saved by pretending it doesn』t exist. The machine-description macro "FRAME_POINTER_REQUIRED" controls whether a target machine supports this flag. Enabled at levels -O, -O2, -O3, -Os. -foptimize-sibling-calls Optimize sibling and tail recursive calls. Enabled at levels -O2, -O3, -Os. -fno-inline Don』t pay attention to the "inline" keyword. Normally this option is used to keep the com- piler from expanding any functions inline. Note that if you are not optimizing, no func- tions can be expanded inline. -finline-functions Integrate all simple functions into their callers. The compiler heuristically decides which functions are simple enough to be worth integrating in this way. If all calls to a given function are integrated, and the function is declared "static", then the function is normally not output as assembler code in its own right. Enabled at level -O3. -finline-functions-called-once Consider all "static" functions called once for inlining into their caller even if they are not marked "inline". If a call to a given function is integrated, then the function is not output as assembler code in its own right. Enabled if -funit-at-a-time is enabled. -fearly-inlining Inline functions marked by "always_inline" and functions whose body seems smaller than the function call overhead early before doing -fprofile-generate instrumentation and real inlining pass. Doing so makes profiling significantly cheaper and usually inlining faster on programs having large chains of nested wrapper functions. Enabled by default. -finline-limit=n By default, GCC limits the size of functions that can be inlined. This flag allows the control of this limit for functions that are explicitly marked as inline (i.e., marked with the inline keyword or defined within the class definition in c++). n is the size of func- tions that can be inlined in number of pseudo instructions (not counting parameter han- dling). The default value of n is 600. Increasing this value can result in more inlined code at the cost of compilation time and memory consumption. Decreasing usually makes the compilation faster and less code will be inlined (which presumably means slower programs). This option is particularly useful for programs that use inlining heavily such as those based on recursive templates with C++. Inlining is actually controlled by a number of parameters, which may be specified indivi- ally by using --param name=value. The -finline-limit=n option sets some of these parame- ters as follows: max-inline-insns-single is set to I<n>/2. max-inline-insns-auto is set to I<n>/2. min-inline-insns is set to 130 or I<n>/4, whichever is smaller. max-inline-insns-rtl is set to I<n>. See below for a documentation of the indivial parameters controlling inlining. Note: pseudo instruction represents, in this particular context, an abstract measurement of function』s size. In no way does it represent a count of assembly instructions and as such its exact meaning might change from one release to an another. -fkeep-inline-functions In C, emit "static" functions that are declared "inline" into the object file, even if the function has been inlined into all of its callers. This switch does not affect functions using the "extern inline" extension in GNU C. In C++, emit any and all inline functions into the object file. -fkeep-static-consts Emit variables declared "static const" when optimization isn』t turned on, even if the vari- ables aren』t referenced. GCC enables this option by default. If you want to force the compiler to check if the variable was referenced, regardless of whether or not optimization is turned on, use the -fno-keep-static-consts option. -fmerge-constants Attempt to merge identical constants (string constants and floating point constants) across compilation units. This option is the default for optimized compilation if the assembler and linker support it. Use -fno-merge-constants to inhibit this behavior. Enabled at levels -O, -O2, -O3, -Os. -fmerge-all-constants Attempt to merge identical constants and identical variables. This option implies -fmerge-constants. In addition to -fmerge-constants this considers e.g. even constant initialized arrays or initialized constant variables with integral or floating point types. Languages like C or C++ require each non-automatic variable to have distinct location, so using this option will result in non-conforming behavior. -fmolo-sched Perform swing molo scheling immediately before the first scheling pass. This pass looks at innermost loops and reorders their instructions by overlapping different itera- tions. -fno-branch-count-reg Do not use "decrement and branch" instructions on a count register, but instead generate a sequence of instructions that decrement a register, compare it against zero, then branch based upon the result. This option is only meaningful on architectures that support such instructions, which include x86, PowerPC, IA-64 and S/390. The default is -fbranch-count-reg, enabled when -fstrength-rece is enabled. -fno-function-cse Do not put function addresses in registers; make each instruction that calls a constant function contain the function』s address explicitly. This option results in less efficient code, but some strange hacks that alter the assembler output may be confused by the optimizations performed when this option is not used. The default is -ffunction-cse -fno-zero-initialized-in-bss If the target supports a BSS section, GCC by default puts variables that are initialized to zero into BSS. This can save space in the resulting code. This option turns off this behavior because some programs explicitly rely on variables going to the data section. E.g., so that the resulting executable can find the beginning of that section and/or make assumptions based on that. The default is -fzero-initialized-in-bss. -fmudflap -fmudflapth -fmudflapir For front-ends that support it (C and C++), instrument all risky pointer/array dereferenc- ing operations, some standard library string/heap functions, and some other associated con- structs with range/validity tests. Moles so instrumented should be immune to buffer overflows, invalid heap use, and some other classes of C/C++ programming errors. The instrumentation relies on a separate runtime library (libmudflap), which will be linked into a program if -fmudflap is given at link time. Run-time behavior of the instrumented program is controlled by the MUDFLAP_OPTIONS environment variable. See "env MUD- FLAP_OPTIONS=-help a.out" for its options. Use -fmudflapth instead of -fmudflap to compile and to link if your program is multi-threaded. Use -fmudflapir, in addition to -fmudflap or -fmudflapth, if instrumenta- tion should ignore pointer reads. This proces less instrumentation (and therefore faster execution) and still provides some protection against outright memory corrupting writes, but allows erroneously read data to propagate within a program. -fstrength-rece Perform the optimizations of loop strength rection and elimination of iteration vari- ables. Enabled at levels -O2, -O3, -Os. -fthread-jumps Perform optimizations where we check to see if a jump branches to a location where another comparison subsumed by the first is found. If so, the first branch is redirected to either the destination of the second branch or a point immediately following it, depending on whether the condition is known to be true or false. Enabled at levels -O2, -O3, -Os. -fcse-follow-jumps In common subexpression elimination, scan through jump instructions when the target of the jump is not reached by any other path. For example, when CSE encounters an "if" statement with an "else" clause, CSE will follow the jump when the condition tested is false. Enabled at levels -O2, -O3, -Os. -fcse-skip-blocks This is similar to -fcse-follow-jumps, but causes CSE to follow jumps which conditionally skip over blocks. When CSE encounters a simple "if" statement with no else clause, -fcse-skip-blocks causes CSE to follow the jump around the body of the "if". Enabled at levels -O2, -O3, -Os. -frerun-cse-after-loop Re-run common subexpression elimination after loop optimizations has been performed. Enabled at levels -O2, -O3, -Os. -frerun-loop-opt Run the loop optimizer twice. Enabled at levels -O2, -O3, -Os. -fgcse Perform a global common subexpression elimination pass. This pass also performs global constant and propagation. Note: When compiling a program using computed gotos, a GCC extension, you may get better runtime performance if you disable the global common subexpression elimination pass by adding -fno-gcse to the command line. Enabled at levels -O2, -O3, -Os. -fgcse-lm When -fgcse-lm is enabled, global common subexpression elimination will attempt to move loads which are only killed by stores into themselves. This allows a loop containing a load/store sequence to be changed to a load outside the loop, and a /store within the loop. Enabled by default when gcse is enabled. -fgcse-sm When -fgcse-sm is enabled, a store motion pass is run after global common subexpression elimination. This pass will attempt to move stores out of loops. When used in conjunction with -fgcse-lm, loops containing a load/store sequence can be changed to a load before the loop and a store after the loop. Not enabled at any optimization level. -fgcse-las When -fgcse-las is enabled, the global common subexpression elimination pass eliminates rendant loads that come after stores to the same memory location (both partial and full rendancies). Not enabled at any optimization level. -fgcse-after-reload When -fgcse-after-reload is enabled, a rendant load elimination pass is performed after reload. The purpose of this pass is to cleanup rendant spilling. -floop-optimize Perform loop optimizations: move constant expressions out of loops, simplify exit test con- ditions and optionally do strength-rection as well. Enabled at levels -O, -O2, -O3, -Os. -floop-optimize2 Perform loop optimizations using the new loop optimizer. The optimizations (loop unrolling, peeling and unswitching, loop invariant motion) are enabled by separate flags. -funsafe-loop-optimizations If given, the loop optimizer will assume that loop indices do not overflow, and that the loops with nontrivial exit condition are not infinite. This enables a wider range of loop optimizations even if the loop optimizer itself cannot prove that these assumptions are valid. Using -Wunsafe-loop-optimizations, the compiler will warn you if it finds this kind of loop. -fcrossjumping Perform cross-jumping transformation. This transformation unifies equivalent code and save code size. The resulting code may or may not perform better than without cross-jumping. Enabled at levels -O2, -O3, -Os. -fif-conversion Attempt to transform conditional jumps into branch-less equivalents. This include use of conditional moves, min, max, set flags and abs instructions, and some tricks doable by standard arithmetics. The use of conditional execution on chips where it is available is controlled by "if-conversion2". Enabled at levels -O, -O2, -O3, -Os. -fif-conversion2 Use conditional execution (where available) to transform conditional jumps into branch-less equivalents. Enabled at levels -O, -O2, -O3, -Os. -fdelete-null-pointer-checks Use global dataflow analysis to identify and eliminate useless checks for null pointers. The compiler assumes that dereferencing a null pointer would have halted the program. If a pointer is checked after it has already been dereferenced, it cannot be null. In some environments, this assumption is not true, and programs can safely dereference null pointers. Use -fno-delete-null-pointer-checks to disable this optimization for programs which depend on that behavior. Enabled at levels -O2, -O3, -Os. -fexpensive-optimizations Perform a number of minor optimizations that are relatively expensive. Enabled at levels -O2, -O3, -Os. -foptimize-register-move -fregmove Attempt to reassign register numbers in move instructions and as operands of other simple instructions in order to maximize the amount of register tying. This is especially helpful on machines with two-operand instructions. Note -fregmove and -foptimize-register-move are the same optimization. Enabled at levels -O2, -O3, -Os. -fdelayed-branch If supported for the target machine, attempt to reorder instructions to exploit instruction slots available after delayed branch instructions. Enabled at levels -O, -O2, -O3, -Os. -fschele-insns If supported for the target machine, attempt to reorder instructions to eliminate execution stalls e to required data being unavailable. This helps machines that have slow floating point or memory load instructions by allowing other instructions to be issued until the result of the load or floating point instruction is required. Enabled at levels -O2, -O3, -Os. -fschele-insns2 Similar to -fschele-insns, but requests an additional pass of instruction scheling after register allocation has been done. This is especially useful on machines with a rel- atively small number of registers and where memory load instructions take more than one cycle. Enabled at levels -O2, -O3, -Os. -fno-sched-interblock Don』t schele instructions across basic blocks. This is normally enabled by default when scheling before register allocation, i.e. with -fschele-insns or at -O2 or higher. -fno-sched-spec Don』t allow speculative motion of non-load instructions. This is normally enabled by default when scheling before register allocation, i.e. with -fschele-insns or at -O2 or higher. -fsched-spec-load Allow speculative motion of some load instructions. This only makes sense when scheling before register allocation, i.e. with -fschele-insns or at -O2 or higher. -fsched-spec-load-dangerous Allow speculative motion of more load instructions. This only makes sense when scheling before register allocation, i.e. with -fschele-insns or at -O2 or higher. -fsched-stalled-insns -fsched-stalled-insns=n Define how many insns (if any) can be moved prematurely from the queue of stalled insns into the ready list, ring the second scheling pass. -fno-fsched-stalled-insns and -fsched-stalled-insns=0 are equivalent and mean that no insns will be moved prematurely. If n is unspecified then there is no limit on how many queued insns can be moved prema- turely. -fsched-stalled-insns-dep -fsched-stalled-insns-dep=n Define how many insn groups (cycles) will be examined for a dependency on a stalled insn that is candidate for premature removal from the queue of stalled insns. This has an effect only ring the second scheling pass, and only if -fsched-stalled-insns is used and its value is not zero. +-fno-sched-stalled-insns-dep is equivalent to +-fsched-stalled-insns-dep=0. +-fsched-stalled-insns-dep without a value is equivalent to +-fsched-stalled-insns-dep=1. -fsched2-use-superblocks When scheling after register allocation, do use superblock scheling algorithm. Superblock scheling allows motion across basic block boundaries resulting on faster scheles. This option is experimental, as not all machine descriptions used by GCC model the CPU closely enough to avoid unreliable results from the algorithm. This only makes sense when scheling after register
Ⅳ 怎樣修改gcc的默認優化參數
不是release優化的問題。如果是直接運行的話,mingwm10.dll、libgcc_s_dw2-1.dll、qtcore4.dll、qtgui4.dll,還有相應的你用到的庫都要放在運行目錄下嘩念,用dependency walker可以看到dll依賴情況。
然後用到的插件比如qmltooling、imageformats等目錄也需要拷到運行目錄中,這個用工具看不到依賴,只能全拷然後用排除法,有經驗之後代碼里哪些用到了就知道了。
出現runtime library錯誤的最大橡蘆侍可能性就是運行目錄下的插件不完整。
另外有一種解決方法就是把qt改成靜態鏈接,編譯梁吵進exe,商業版允許這樣做,lgpl版的話如果不是自用就有法律風險。
Ⅳ 如何查看gcc編譯器的默認選項設置
默認編譯器的設置,是通過全局變數的設置: 你進入命令模式,打命令:vi /etc/profile 在打開的文件里,加上: PATH=$PATH:$gcc_PATH/bin 其中:$gcc_PATH是你的編譯器安裝路徑
Ⅵ 怎麼用gcc編譯文件
在終端中輸入 gcc 文件名 -o 目標文件名x0dx0a然後 ./目標文件名 就行了,沒有目標文件名,自動存為 ax0dx0a執行 ./a 就行了。x0dx0ax0dx0a在使用Gcc編譯器的時候,我們必須給出一系列必要的調用參數和文件名稱。GCC編譯器的調用參數大約有100多個,其中多數參數我們可能根本就用不到,這里只介紹其中最基本、最常用的參數。x0dx0aGCC最基本的用法是∶gcc [options] [filenames]x0dx0a其中options就是編譯器所需要的參數,filenames給出相關的文件名稱。x0dx0a-c,只編譯,不連接成為可執行文件,編譯器只是由輸入的.c等源代碼文件生成.o為後綴的目標文件,通常用於編譯不包含主程序的子程序文件。x0dx0a-o output_filename,確定輸出文件的名稱為output_filename,同時這個名稱不能和源文件同名。如果不給出這個選項,gcc就給出預設的可執行文件a.out。x0dx0a-g,產生符號調試工具(GNU的gdb)所必要的符號資訊,要想對源代碼進行調試,我們就必須加入這個選項。x0dx0a-O,對程序進行優化編譯、連接,採用這個選項,整個源代碼會在編譯、連接過程中進行優化處理,這樣產生的可執行文件的執行效率可以提高,但是,編譯、連接的速度就相應地要慢一些。x0dx0a-O2,比-O更好的優化編譯、連接,當然整個編譯、連接過程會更慢。x0dx0a-Idirname,將dirname所指出的目錄加入到程序頭文件目錄列表中,是在預編譯過程中使用的參數。C程序中的頭文件包含兩種情況∶x0dx0aA)#include
Ⅶ 怎麼加快codeblock計算速度
1.啟用多核支持:打開Codeblocks選項,選擇「編譯器和工具」,然後在「GCC編譯器」選項卡中打開「多核構建」選項。
2.關閉調試選項:在構建項目時,可以禁用調試信息和調試符號。這將減少生成的可執行文件的大小並提高編譯速度。
3.使用最新的編譯器版本:更新您的GCC編譯器版本,這將有助於優化編譯器的性能和編譯速度。
4.盡可能使用靜態鏈接庫:避免使用動態鏈接庫,在編譯時直接將所需的函數和庫鏈接到可執行文件中。
5.使用預編譯頭(州岩PCH):創建PCH文件,它包含了項目中經常使用的頭文件。編譯器在編譯其他文件時可以使用PCH文件,從而加快編譯速度。
6.優化代碼高鄭:消除冗餘循環或遞歸,減少內存分配和復制等都可以提高代碼運行效率。
以上這些方法可以加快Codeblocks的編譯戚跡頌速度,但請注意,這些優化方法可能會影響可讀性和可維護性。在進行優化時,請確保權衡好速度和質量。
Ⅷ 什麼叫 -O2編譯
【-O2編譯】編譯器提供-O選項,供程序優化使用。其中:
1、-O0表示沒有優化;
2、-O1為預設值,提供基礎級別的優化;
3、-O2 提供更加高級的代碼優化,會佔用更長的編譯時間;
4、-O3 提供最高級的代碼優化。
【編譯器】就是將「一種語言(通常為高級語言)」翻譯為「另一種語言(通常為低級語言)」的程序。一個現代編譯器的主要工作流程:源代碼 (source code) → 預處理器 (preprocessor) → 編譯器 (compiler) → 目標代碼 (object code) → 鏈接器(Linker) → 可執行程序 (executables)
高級計算機語言便於人編寫,閱讀交流,維護。機器語言是計算機能直接解讀、運行的。編譯器將匯編或高級計算機語言源程序(Source program)作為輸入,翻譯成目標語言(Target language)機器代碼的等價程序。源代碼一般為高級語言 (High-level language), 如Pascal、C、C++、Java、漢語編程等或匯編語言,而目標則是機器語言的目標代碼(Object code),有時也稱作機器代碼(Machine code)。