Posts

Showing posts with the label Gcc

Checking The Gcc Version In A Makefile?

Answer : I wouldn't say its easy, but you can use the shell function of GNU make to execute a shell command like gcc --version and then use the ifeq conditional expression to check the version number and set your CFLAGS variable appropriately. Here's a quick example makefile: CC = gcc GCCVERSION = $(shell gcc --version | grep ^gcc | sed 's/^.* //g') CFLAGS = -g ifeq "$(GCCVERSION)" "4.4.3" CFLAGS += -Wtype-limits endif all: $(CC) $(CFLAGS) prog.c -o prog Edit: There is no ifgt . However, you can use the shell expr command to do a greater than comparison. Here's an example CC = gcc GCCVERSIONGTEQ4 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 4) CFLAGS = -g ifeq "$(GCCVERSIONGTEQ4)" "1" CFLAGS += -Wtype-limits endif all: $(CC) $(CFLAGS) prog.c -o prog To transform full 3-part gcc version (not only first digit) into numerical format, suitable for comparison (e.g. 40701 ) us...

Can't Find File Executable In Your Configured Search Path For Gnc Gcc Compiler

Answer : I'm guessing you've installed Code::Blocks but not installed or set up GCC yet. I'm assuming you're on Windows, based on your comments about Visual Studio; if you're on a different platform, the steps for setting up GCC should be similar but not identical. First you'll need to download GCC. There are lots and lots of different builds; personally, I use the 64-bit build of TDM-GCC. The setup for this might be a bit more complex than you'd care for, so you can go for the 32-bit version or just grab a preconfigured Code::Blocks/TDM-GCC setup here. Once your setup is done, go ahead and launch Code::Blocks. You don't need to create a project or write any code yet; we're just here to set stuff up or double-check your setup, depending on how you opted to install GCC. Go into the Settings menu, then select Global compiler settings in the sidebar, and select the Toolchain executables tab. Make sure the Compiler's installation director...

C11 In GCC?

Answer : The standard C11 header for threading is <threads.h> , not <thread.h> . See section 7.26 of the N1570 draft. Most of the C standard library, including stdio for example, is not included in the gcc distribution. Instead, gcc depends on whatever runtime library is provided by the operating system. That generally includes both the headers (like <threads.h> ) and the actual code that implements the library. For most Linux systems (or GNU/Linux if you prefer), the library is GNU's glibc; for other systems it will be something else. So the real question is probably when glibc, or whichever C library you're using, will support C11's threading features. glibc adds support for C11 threads in version 2.28. Ubuntu 18.04.1 LTS system currently still uses glibc 2.27. Again, this applies only to implementations using GNU libc, not to all gcc-based implementations. Mentioned by WorldSEnder in a comment. UPDATE: Ubuntu 18.10 (not an LTS (Long Term Su...

Can C++ Raise An Error When Std Array Initialization Is Too Small?

Answer : You can use std::make_array or something like it to cause the types to differ std::array<int, 6> = std::make_array(4,3,2); gives this error in gcc: <source>:30:53: error: conversion from 'array<[...],3>' to non-scalar type 'array<[...],6>' requested You can create your own layer of abstraction that complains when you don't pass the exact same number of arguments for initialization. template <std::size_t N, class ...Args> auto createArray(Args&&... values) { static_assert(sizeof...(values) == N); using First = std::tuple_element_t<0, std::tuple<Args...>>; return std::array<First, N>{values...}; } To be invoked as auto ok = createArray<6>(4, 3, 2, 1, 0, -1); auto notOk = createArray<6>(4, 3, 2}; Instead of writing your own createArray method you can use the https://en.cppreference.com/w/cpp/experimental/make_array if your compiler supports it. #include ...

A Simple Explanation Of What Is MinGW

Answer : MinGW is a complete GCC toolchain (including half a dozen frontends, such as C, C++, Ada, Go, and whatnot) for the Windows platform which compiles for and links to the Windows OS component C Runtime Library in msvcrt.dll. Rather it tries to be minimal (hence the name). This means, unlike Cygwin, MinGW does not attempt to offer a complete POSIX layer on top of Windows, but on the other hand it does not require you to link with a special compatibility library. It therefore also does not have any GPL-license implications for the programs you write (notable exception: profiling libraries, but you will not normally distribute those so that does not matter). The newer MinGW-w64 comes with a roughly 99% complete Windows API binding (excluding ATL and such) including x64 support and experimental ARM implementations. You may occasionally find some exotic constant undefined, but for what 99% of the people use 99% of the time, it just works perfectly well. You can also use t...

Codeblocks Can't Find My Compiler

Answer : I faced the same problem. I have fixed out by going to Setting -> Compiler -> Global Compiler Settings -> Toolchain Execuatables (tab) . There, click on Program Files and then rename C compiler to gcc.exe and C++ compiler to g++.exe . I know this is an old question but let me see if I can help. First of all, on the download page make sure you downloaded codeblocks-13.12mingw-setup.exe and NOT codeblocks-13.12-setup.exe. Of course the version numbers may change but pay attention to the name. Then after installing codeblocks, go to Settings->Compiler->Toolchain executables. From here, change the C compiler to gcc.exe and C++ compiler to g++.exe. Hope this helps anyone else going through this problem :-)

Clang Vs GCC - Which Produces Faster Binaries?

Answer : Here are some up-to-date albeit narrow findings of mine with GCC 4.7.2 and Clang 3.2 for C++. UPDATE: GCC 4.8.1 v clang 3.3 comparison appended below. UPDATE: GCC 4.8.2 v clang 3.4 comparison is appended to that. I maintain an OSS tool that is built for Linux with both GCC and Clang, and with Microsoft's compiler for Windows. The tool, coan, is a preprocessor and analyser of C/C++ source files and codelines of such: its computational profile majors on recursive-descent parsing and file-handling. The development branch (to which these results pertain) comprises at present around 11K LOC in about 90 files. It is coded, now, in C++ that is rich in polymorphism and templates and but is still mired in many patches by its not-so-distant past in hacked-together C. Move semantics are not expressly exploited. It is single-threaded. I have devoted no serious effort to optimizing it, while the "architecture" remains so largely ToDo. I employed Clang prior to 3...