Author Topic: Include automatically  (Read 7241 times)

Offline Sec0nd

  • Single posting newcomer
  • *
  • Posts: 5
Include automatically
« on: November 11, 2010, 06:45:13 pm »
I learn c++ in my school, there we use DevC++.
I heard from Code::blocks from my friend and I want to use it at home, but in school we use system("pause") command, but Code::Blocks isn't familiar with it.I wan't to use my files both of IDE.
So how can I set that Code::Block include automatically <stdlib.h>, without writing it to the source file?

Thank You for helping!!!

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Include automatically
« Reply #1 on: November 11, 2010, 07:09:54 pm »
Learn the difference between an Compiler and the Code::Blocks IDE.

Learn to Always include the correct header for the functions you use even if it works sometimes without using the proper headers!

Learn to mention the OS and Compiler you are using when asking an question about how to do something that has to do with your compiler/OS and little to do with Code::Blocks!

Tim S.
« Last Edit: November 11, 2010, 07:12:39 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Sec0nd

  • Single posting newcomer
  • *
  • Posts: 5
Re: Include automatically
« Reply #2 on: November 11, 2010, 07:28:35 pm »
I'm using the default C++ compiler.( GNU GCC )
The OS is Windows7.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Include automatically
« Reply #3 on: November 11, 2010, 09:30:24 pm »
Try GCC Option "include" in Code::Blocks, IIRC in the extra Compile area.

http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options

Quote
-include file
    Process file as if #include "file" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the #include "..." search chain as normal.

    If multiple -include options are given, the files are included in the order they appear on the command line.

No idea if the above does what you want; this is NOT really a Code::Blocks question.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Sec0nd

  • Single posting newcomer
  • *
  • Posts: 5
Re: Include automatically
« Reply #4 on: November 12, 2010, 04:38:42 pm »
Sorry, I don't really understand your suggestion:S


Try GCC Option "include" in Code::Blocks, IIRC in the extra Compile area.

http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options

Quote
-include file
    Process file as if #include "file" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the #include "..." search chain as normal.

    If multiple -include options are given, the files are included in the order they appear on the command line.

No idea if the above does what you want; this is NOT really a Code::Blocks question.

Tim S.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Include automatically
« Reply #5 on: November 13, 2010, 11:47:44 pm »
Try placing "-include stdlib.h" without the double quotes in the Other Options section.

Project -> Build Option
Tab "Compiler Settings"
Sub Tab "Other Options"
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Sec0nd

  • Single posting newcomer
  • *
  • Posts: 5
Re: Include automatically
« Reply #6 on: November 14, 2010, 05:35:11 pm »
Thanks, but I don't use projects, I'm a beginner.
We work with several source files..

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Include automatically
« Reply #7 on: November 14, 2010, 07:34:43 pm »
Thanks, but I don't use projects, I'm a beginner.
We work with several source files..

So long then; because if you do NOT want to use projects; then in my opinion you have no real reason to use Code::Blocks or to expect help from the website.
You wasted a lot of my time by NOT saying the fact you do NOT use projects right at first.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Sec0nd

  • Single posting newcomer
  • *
  • Posts: 5
Re: Include automatically
« Reply #8 on: November 14, 2010, 07:40:09 pm »
Okay, sorry.
And thanks for trying to help....

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Include automatically
« Reply #9 on: November 14, 2010, 08:41:31 pm »
Try placing "-include stdlib.h" without the double quotes in the Other Options section.

Project -> Build Option
Tab "Compiler Settings"
Sub Tab "Other Options"


You can also use the option in the Compiler Settings; this should work without a project. I have never tried it before.

Settings -> Compiler and Debugger
Tab "Compiler Settings"
Sub Tab "Other Options"


Never ask why the debugger does NOT work; it requires a project to work.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org