Difference between revisions of "FAQ-Compiling (general)"

From Code::Blocks
(FAQ breakup.)
 
m (→‎Q: How do I report a compilation problem on the forums?: Explain codeblock.RPT will be in the config folder if C::B's one is not writable)
 
(13 intermediate revisions by 5 users not shown)
Line 3: Line 3:
 
Return to '''[[FAQ]]'''.
 
Return to '''[[FAQ]]'''.
  
== Compiling (general) ==
+
----
  
 
==== Q: What compiler can I use with Code::Blocks? ====
 
==== Q: What compiler can I use with Code::Blocks? ====
Line 107: Line 107:
  
 
==== Q: How do I add version information to windows executables and dll's? ====
 
==== Q: How do I add version information to windows executables and dll's? ====
'''A:''' You need to create a reosurce file with the extension .rc and write the version info there. Then add that file to the Code::Blocks project you are working on.
+
'''A:''' You need to create a resource file with the extension .rc and write the version info there. Then add that file to the Code::Blocks project you are working on.
  
 
Sample content of a resource file that you can use and modify for your needs:
 
Sample content of a resource file that you can use and modify for your needs:
<source lang="cpp">
+
<source lang="cpp" enclose="div">
 
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
 
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
  
Line 167: Line 167:
 
==== Q: How do I report a compilation problem on the forums? ====
 
==== Q: How do I report a compilation problem on the forums? ====
  
'''A:''' Try building the project from command line. If the same error comes up, it is a problem with either the source file, the compiler, or the compiler setup. If this is the case, you are unlikely to receive support for it on the Code::Blocks forums, however, [[FAQ-Compiling (errors)#Q: How do I troubleshoot an compiler problem?|How do I troubleshoot an compiler problem?]] may help.
+
'''A:''' Try building the project from command line. If the same error comes up, it is a problem with either the source file, the compiler, or the compiler setup. If this is the case, you are unlikely to receive support for it on the Code::Blocks forums, however, [[FAQ-Compiling (errors)#Q: How do I troubleshoot a compiler problem?|How do I troubleshoot a compiler problem?]] may help.
  
If it works fine building from command line, it is either a problem with your project, Code::Blocks' setup, or possibly an actual bug. When posting this problem, include the name of your compiler, operating system, Code::Blocks version, compiler log (go to ''Settings->Compiler and debugger...->Build options (tab)'' and check ''Save build log'' and ''Always output the full command line''), and, if it caused Code::Blocks to crash, the <tt>codeblocks.RPT</tt> file (located in the Code::Blocks installation directory).
+
If it works fine building from command line, it is either a problem with your project, Code::Blocks' setup, or possibly an actual bug. When posting this problem, include the name of your compiler, operating system, Code::Blocks version, compiler log (go to ''Settings->Compiler and debugger...->Build options (tab)'' and check ''Save build log'' and ''Always output the full command line''), and, if it caused Code::Blocks to crash, the <tt>codeblocks.RPT</tt> file. This file is located in the Code::Blocks installation directory if it is writable, and in the config directory if it is not. On MSW you can open the config directory pressing Windows+R and writing "%appdata%\CodeBlocks" in the edit box.
 +
 
 +
[[File:forum_code_tag.png|frame|Button for code tags in the new post editor of the forum]]
 +
 
 +
'''Important''' If you post code or log message to the forum, please use code tags: Click the "#" button in the new post editor (see image) and post your code/log between the two "[code][/code]" words. This helps to distinguish between your text and the log and it shortens the posts.
  
 
''Template: Paste the following template into your post, editing the relevant sections.''
 
''Template: Paste the following template into your post, editing the relevant sections.''
  OS = ''MyOperatingSystem''
+
  I am running Code::Blocks version <span style="color:DarkRed">''Code::BlocksVersionNumber''</span> on <span style="color:DarkRed">''MyOperatingSystem''</span>
  CB Version = ''Code::BlocksVersionNumber''
+
  (version <span style="color:DarkRed">''OperatingSystemVersionNumber''</span>). The compiler I use is <span style="color:DarkRed">''CompilerName''</span>
  Compiler = ''CompilerName CompilerVersionNumber''
+
version <span style="color:DarkRed">''CompilerVersionNumber''</span>.
 +
   
 +
When I ...
 +
<span style="color:DarkRed">''Steps to reproduce problem.''</span>
 
   
 
   
  ''Description of relevant events.''
+
  <span style="color:DarkRed">''Description of problem.''</span>
 +
... happens.
 
   
 
   
 
  Build log:
 
  Build log:
 
  [code]
 
  [code]
  ''Paste build log here''
+
  <span style="color:DarkRed">''Paste <span style="color:FireBrick">'''full'''</span> build log here. (It is found in the 'Build log' tab). Please make always a 'rebuild' (Menu: Build->Rebuild) or a 'clean' and 'build' before you copy the full build log. ''</span>
 
  [/code]
 
  [/code]
 
   
 
   
 
  Crash report:
 
  Crash report:
 
  [code]
 
  [code]
  ''If Code::Blocks crashed, paste the contents of'' codeblocks.RPT ''here.''
+
  ''<span style="color:DarkRed">Paste the contents of</span>'' <span style="color:MidnightBlue">codeblocks.RPT</span> ''<span style="color:DarkRed">here</span> (if Code::Blocks crashed).''
 
  [/code]
 
  [/code]
 +
 +
    ''(Although the following is not necessary, showing that you''
 +
      ''have tried increases the probability of a response.)''
 +
I have already tried ...
 +
<span style="color:DarkRed">''List of attempted solutions.''</span>
 +
... but none of them worked.
  
 
==== Q: All of the Build related options are grayed out? ====
 
==== Q: All of the Build related options are grayed out? ====
Line 193: Line 207:
  
 
More often it is useful to [[Creating a new project|create a project]] so that Code::Blocks can manage the entire build.
 
More often it is useful to [[Creating a new project|create a project]] so that Code::Blocks can manage the entire build.
 +
 +
==== Q: I get a blank (black) terminal window on windows ====
 +
 +
'''A:''' Your Anti Virus is blocking your executable. Modern Anti Virus (AV) programs use heuristics to determine if a program is a virus or not. Often this gives false positives and your AV will block your self created applications. [[Solution:]] Deactivate your AV, or for the paranoid: add your project folder, gcc folder and probably also the c::b folder to the AV exception.
 +
 +
==== Q: My program runs in codeblocks but if i start it from the outside it only flashes and closes immediately ====
 +
 +
'''A:''' Your program does exactly what you tell him. You have written that the program should return as soon as it is finished with his code. Codeblocks adds a convenient layer and keeps the console open until you press a key. You can add this to your program with the following lines of code in c++:
 +
 +
<source lang="cpp" enclose="div">
 +
//clear buffer, wait for input to close program
 +
std::cin.clear(); std::cin.ignore(INT_MAX, '\n');
 +
std::cin.get();
 +
return 0;
 +
</source>
 +
 +
for c it is not that easy. You can use
 +
 +
<source lang="cpp" enclose="div">
 +
getch()
 +
</source>
 +
but the user has to press ENTER to continue.
 +
 +
----
 +
 +
Return to '''[[FAQ]]'''.

Latest revision as of 12:15, 11 April 2022

Return to FAQ.


Q: What compiler can I use with Code::Blocks?

A: Code::Blocks philosophy is to be able to use any compiler on earth! Well, almost.

As a matter of fact it largely depends on the used compiler plugin. Some provided with the default Code::Blocks installation are GNU GCC (MinGW/Cygwin), MS Visual C++ Free Toolkit 2003, Borland's C++ Compiler 5.5, DigitalMars Free Compiler., OpenWatcom, Small Device C Compiler (SDCC) and others.

Q: My project should be compiled with a custom makefile. Is it possible with Code::Blocks?

A: Yes, you can. You need to change one settings with Code::Blocks 8.02:

In your project's Properties, check "This is a custom makefile".

And that's it! :)

Q: I have downloaded MS VC++ Toolkit 2003 for a compiler. How do I tell Code::Blocks that it is my compiler?

A: Click on "Project/Build options" and select the compiler you want for your project/target.

Q: Microsoft calls MSVCRT.DLL a "Known DLL." How do I know if I can/should use it?

Microsoft does not clearly describe what 'Known DLL' means. A zLib FAQ entry makes it much more clear. The short answer is that MSVCRT.DLL is a protected system component and to preserve system integrity it cannot be updated by any end user product installers but may be updated from time to time by system updates. If it works use it. If it doesn't you'll need use a non protected library such as MSVCR70 or MSVCR80 which not only can be updated but private versions can be installed. A small and simple C program is likely to work just fine with MSVCRT.DLL. A large and complex C++ program is more likely to need the additional functionality of MSVCR.

The MSVCRT.LIB that ships with 32 bit compiler Visual C++ Toolkit 2003 dynamically links to MSVCR71.DLL which is not present in a freshly installed Windows XP system. MSVCR only appears after some software package that needs it such as Adobe Acrobat Reader is installed. This means that programs that depend on MSVCR must redistribute it or risk not working on a substantial percentage of systems for reasons not obvious to either the affected end users or the program supplier.

For projects that can safely use MSVCRT and where it is impractical to redistribute MSVCR, a Win32 MSVCRT.LIB that links to MSVCRT.DLL is available in any Device Driver Kit. It is best to preserve the MSVCRT.LIB provided by the compiler and alter the name of the MSVCRT.LIB extracted from a DDK. List your newly named MSVCRTxx in the lib. If you use MSVCRT.LIB from the Windows 2003 DDK you may encounter the link error LNK2001: unresolved external symbol ___security_cookie. This can be solved by switching to the MSVCRT.LIB in the Windows XP DDK or by linking bufferoverflowU.lib found in the Windows SDK. A Win64 MSVCRT.LIB that links to MSVCRT.DLL is available in the Windows SDK or Platform PSDK.

To prevent problems it is recommended to include both /MD and /NODEFAULTLIB:MSVCRT switches so that problems come up at link time instead of random crashes at run time. Be sure to load your programs into Dependancy Walker to ensure that functions aren't being linked into both MSVCRxx.DLL and MSVCRT.DLL. It is essential that malloc, calloc, realloc, free, and related memory allocation functions all import from the same DLL.

Source: TCL Wiki

Q: How can I use a DLL without DEF or LIB files?

A: I tried to find a solution, and the following script solved the problem for me. I used a cygwin environment for tclsh and sed, but the MinGW tools for objdump and dlltool. See here tclsh script to extract import .lib from (any?) DLL (MinGW)

TODO: Someone might add some informations about problems

Request: Is MinGW or Code::Blocks able to support automatic generation of import libraries ?

See also: http://www.mingw.org/wiki/CreateImportLibraries

See also: http://wyw.dcweb.cn/stdcall.htm

Q: Where are the libraries for the OpenGL, Ogre3D, SDL, QT, wxWidgets etc. projects?

A: They're not bundled. The templates were provided for your convenience, but you need to download the libraries on your own. In common terms, "batteries not included" :)

Q: Is it possible to use Visual C++ 6.0 with Code::Blocks?

A: Yes. See Integrating Microsoft Visual C 6 with Code::Blocks IDE for a detailed description on using VC++ 6.0 with Code::Blocks.

Q: I would like to compile a project using some non-standard libraries. How can I indicate to CodeBlocks that these libraries and include files exist?

A: You can specify them for your global environment or just for your project.

For global environment :
- Menu Settings/Compiler and debugger
- In the Global compiler settings, select the directories tab
- Add the required paths for compiler and linker.

For your project :
- Right click on the project then select Build options
- Select the directories tab
- Add the required paths for compiler and linker.
- Add your specific libraries in the linker tab.
- Pay attention to project settings and target settings.

Q: How do I use both Debug and Release builds of wx libraries?

A: I would use the default method of doing it and the default folder naming.

Using these C::B custom varibles

WX_SUFFIX=""  // ANSI Release
WX_SUFFIX="d"  // ANSI Debug
WX_SUFFIX="u"  // Unicode Release
WX_SUFFIX="ud"  // Unicode debug

I use WX_CFG when I am using a special configuration WX_CFG="rc3"

Remember, the CodeBlocks globel variable WX needs to point to the wxWidgets folder.

Example minGW build command for "Unicode debug" 2.8.0 RC3

mingw32-make -f makefile.gcc VENDOR=rc3 CFG=rc3 USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=debug   UNICODE=1

"VENDOR=" just puts rc3 in the DLL name; "CFG=" sets which folder the DLL is placed in. In this case in lib\gcc_dllrc3

Before using CFG in the mingw32-make build you need to do one prior wxWidget build without using it; else the build errors out. (See note below.)

"__WXDEBUG__" must be defined (in the codeblocks project setting) if you wish to link against the debug version of wxWidgets DLL. Else you will get a runtime error, when you try to run your project output.

Contributed by Tim S

Note:

  • I have never gotten the following command to work
 mingw32-make -f makefile.gcc VENDOR=rc3 CFG=rc3 USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=debug   UNICODE=1
  • unless I have first run this command on the same wxWidgets folders
 mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=debug   UNICODE=1
  • I am guessing that the build without the CFG creates a file or directory needed by the build with the CFG.

Q: How do I add version information to windows executables and dll's?

A: You need to create a resource file with the extension .rc and write the version info there. Then add that file to the Code::Blocks project you are working on.

Sample content of a resource file that you can use and modify for your needs:

LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

VS_VERSION_INFO    VERSIONINFO
  FILEVERSION      1,0,0,1
  PRODUCTVERSION   1,0,0,1
  FILEFLAGSMASK    0x3fL // VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
  FILEFLAGS        0x1L  // VS_FF_DEBUG|VS_FF_PRIVATEBUILD|VS_FF_PRERELEASE
#else
  FILEFLAGS        0x0L  // final version
#endif
  FILEOS           VOS_NT_WINDOWS32
  FILETYPE         VFT_APP
  FILESUBTYPE      VFT2_UNKNOWN // not used
{
  BLOCK "StringFileInfo"
  {
    BLOCK "040904E4" // Lang=US English, CharSet=Windows Multilingual
    {
      VALUE "Build",            "August 2007\0"
      VALUE "Comments",         "Free for personal use only.\0"
      VALUE "CompanyName",      "Fake Company\0"
      VALUE "Developer",        "The Developer\0"
      VALUE "FileDescription",  "Application implementing something\0"
      VALUE "FileVersion",      "1.0.000\0"
      VALUE "InternalName",     "AppInternalName\0"
      VALUE "LegalCopyright",   "Copyright (C) 2007 Fake Company\0"
      VALUE "LegalTrademarks",  "All rights reserved.\0"
      VALUE "OriginalFilename", "TheEXE.exe\0"
      VALUE "PrivateBuild",     "\0"
      VALUE "ProductName",      "The EXE\0"
      VALUE "ProductVersion",   "1.0.000\0"
      VALUE "SpecialBuild",     "\0"
      VALUE "Support",          "TheEXE at fake-domain.com\0"
      VALUE "Users",            "Unlimited.\0"
    } // BLOCK "040904E4"
  } // BLOCK "StringFileInfo"
  BLOCK "VarFileInfo"
  {
    VALUE "Translation", 0x409, 1252 // 1252 = 0x04E4
  } // BLOCK "VarFileInfo"
}

Also you can use the the AutoVersioning plugin to assist you on the generation of version information. For documentation of the syntax and values used on windows resource files, you can visit the following websites:

Q: Code::Blocks does not force relink if the library is changed?

A: Open Project->Properties...->Build targets (tab) and select the executable. Click Dependencies... and add the name of the library (including its relative path) to External dependency files. Also see inter-project dependencies.

Example: output\myLibrary\libdostuff.a

Q: How do I report a compilation problem on the forums?

A: Try building the project from command line. If the same error comes up, it is a problem with either the source file, the compiler, or the compiler setup. If this is the case, you are unlikely to receive support for it on the Code::Blocks forums, however, How do I troubleshoot a compiler problem? may help.

If it works fine building from command line, it is either a problem with your project, Code::Blocks' setup, or possibly an actual bug. When posting this problem, include the name of your compiler, operating system, Code::Blocks version, compiler log (go to Settings->Compiler and debugger...->Build options (tab) and check Save build log and Always output the full command line), and, if it caused Code::Blocks to crash, the codeblocks.RPT file. This file is located in the Code::Blocks installation directory if it is writable, and in the config directory if it is not. On MSW you can open the config directory pressing Windows+R and writing "%appdata%\CodeBlocks" in the edit box.

Button for code tags in the new post editor of the forum

Important If you post code or log message to the forum, please use code tags: Click the "#" button in the new post editor (see image) and post your code/log between the two "[code][/code]" words. This helps to distinguish between your text and the log and it shortens the posts.

Template: Paste the following template into your post, editing the relevant sections.

I am running Code::Blocks version Code::BlocksVersionNumber on MyOperatingSystem
(version OperatingSystemVersionNumber). The compiler I use is CompilerName
version CompilerVersionNumber.

When I ...
Steps to reproduce problem.

Description of problem.
... happens.

Build log:
[code]
Paste full build log here. (It is found in the 'Build log' tab). Please make always a 'rebuild' (Menu: Build->Rebuild) or a 'clean' and 'build' before you copy the full build log. 
[/code]

Crash report:
[code]
Paste the contents of codeblocks.RPT here (if Code::Blocks crashed).
[/code]

    (Although the following is not necessary, showing that you
     have tried increases the probability of a response.)
I have already tried ...
List of attempted solutions.
... but none of them worked.

Q: All of the Build related options are grayed out?

A: Code::Blocks checks the file extension for individual files before allowing them to be compiled. Save your file with the correct file extension (*.c or *.cpp).

More often it is useful to create a project so that Code::Blocks can manage the entire build.

Q: I get a blank (black) terminal window on windows

A: Your Anti Virus is blocking your executable. Modern Anti Virus (AV) programs use heuristics to determine if a program is a virus or not. Often this gives false positives and your AV will block your self created applications. Solution: Deactivate your AV, or for the paranoid: add your project folder, gcc folder and probably also the c::b folder to the AV exception.

Q: My program runs in codeblocks but if i start it from the outside it only flashes and closes immediately

A: Your program does exactly what you tell him. You have written that the program should return as soon as it is finished with his code. Codeblocks adds a convenient layer and keeps the console open until you press a key. You can add this to your program with the following lines of code in c++:

//clear buffer, wait for input to close program
std::cin.clear(); std::cin.ignore(INT_MAX, '\n');
std::cin.get();
return 0;

for c it is not that easy. You can use

getch()

but the user has to press ENTER to continue.


Return to FAQ.