"Continued. Update "Summarize the general Principle of C + + development

Source: Internet
Author: User

0, when learning with editor, make, Compiler, linker and debugger There are a variety of tools to understand the development details. Use the IDE to speed up development when you are in combat.

Unless your project is simple enough to command: compiler a.cpp can generate A.exe. Otherwise, use a good file organization structure:

Your_project_folder\

Src\

Module_a\

A.cpp

Ax.cpp

Axx.cpp

Module_b\

B.cpp

Bx.cpp

Bxx.cpp

Bin\

Lib\

Library_a\

Xxx.lib

Yyy.lib

Zzz.lib

Library_b\

Hhh.lib

Jjj.lib

Kkk.lib

Include\

Library_a\

Iii.h

Uuu.h

Library_b\

Ggg.h

Fff.h

Module_a\

A.h

Ax.h

Axx.h

Module_b\

D..

Bx.h

Bxx.h

I usually use the makefile can download from here , there is a c++demo download down there is makefile, you can refer to (I am not very deep understanding of makefile, so the writing may be some wordy, but somehow can use ... ), paste the following on my own usual makefile template (with Visual Studio NMAKE program, switch to Linux is actually changed compiler and linker there are some other operating system related instructions can be used, not too much)

  

1 # compiler2 CC=CL3 # linker4 LINK=Link5 # Libraries6 Lib_zthread=/libpath:e:\cppwksp\zthreaddemo_win\libs\zthread7 Lib_sync_output=/libpath:e:\cppwksp\zthreaddemo_win\demo\c11\531-synchronizedoutput\lib8# Headers9 Header_path=/I e:\cppwksp\zthreaddemo_win\include/i includeTen # Options One EHSC=/EHSC A compilation_only=/ C - C_out=/fo: - L_out=/OUT: the # Compiler & linker debug option, to disable debug, replace '/zi ' & '/debug ' with empty strings - # c_debug =/zi -  # l_debug =/debug  - C_debug= + L_debug= - # targets +  A  bin\test.exe: bin Lib\synchronizedoutput_win32.lib obj\synchronizedoutputtask.obj obj\normaltask.obj Obj\task.obj Obj\main.obj at  $ (LINK) $ (l_debug) $ (lib_zthread) $ (lib_sync_output) $ (l_out)Bin\test.exe obj\main.obj obj\ Synchronizedoutputtask.obj obj\normaltask.obj obj\task.obj synchronizedoutput_win32.lib ZThread_win32.lib -      -  lib\synchronizedoutput_win32.lib: lib obj obj\synchronizedoutput.obj - LIB $ (l_out)lib\synchronizedoutput_win32.lib obj\synchronizedoutput.obj -  -  obj\synchronizedoutput.obj: src\synchronizedoutput.cpp include\synchronizedoutput.h in  $ (CC) $ (c_debug) $ (EHSC) $ (header_path) $ (compilation_only) src\synchronizedoutput.cpp $ (c_out) Obj\synchronizedoutput.obj -  to  obj\main.obj: src\main.cpp include\synchronizedoutputtask.h include\normaltask.h include\Task.h +  $ (CC) $ (c_debug) $ (EHSC) $ (header_path) $ (compilation_only) src\main.cpp $ (c_out)obj\main.obj< /c5> -  the  obj\synchronizedoutputtask.obj: src\synchronizedoutputtask.cpp include\synchronizedoutputtask.h Include\task.h include\synchronizedoutput.h *  $ (CC) $ (c_debug) $ (EHSC) $ (header_path) $ (compilation_only) src\synchronizedoutputtask.cpp $ (c_out) Obj\synchronizedoutputtask.obj $     Panax Notoginseng  obj\normaltask.obj: src\normaltask.cpp include\normaltask.h include\task.h -  $ (CC) $ (c_debug) $ (EHSC) $ (header_path) $ (compilation_only) src\normaltask.cpp $ (c_out)obj\ Normaltask.obj the  +  obj\task.obj: src\task.cpp include\task.h A  $ (CC) $ (c_debug) $ (EHSC) $ (header_path) $ (compilation_only) src\task.cpp $ (c_out)obj\task.obj< /c3> the      + # Folders -  $ Bin: $ MkDir bin -  - obj: the mkdir obj -     Wuyi Lib: the mkdir Lib -      Wu # Clean - # Bin, lib, obj folders and pdb files About  $ . Phony:  clean - Clean : - -rmdir/s/Q bin - -rmdir/s/q Lib A -rmdir/s/q obj +-del *.pdb

About Makefile, I wrote a note very important, Click here to view

1, the first file of # include order: Their own header files, third-party tools of the header files, standard header files, as far as possible from the top to the bottom of this arrangement order

Header file must be written on #ifndef xxx #define XXX #endif的header guard

Header file In addition to template and inline, all write declaration do not write implementation code in the header file, so that xxx redefined error, keep a good habit

2. Do not include in the header file: Using directives and using namespace directives

Do not initialize the static member in the header file, avoid the xxx redefined error, and put in the CPP file to initialize

3. If you have a class, try to create a separate header file and CPP file for this class, except when you need to hide the implementation details

4. Waiting to be added ...

"Continued. Update "Summarize the general Principle of C + + development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.