Ⅰ 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)。