FAQ Database Discussion Community


Meaning of options in mingw-w64 installer

windows,g++,mingw-w64
In the MinGW-W64 online installer there are several fields you can select. However I cannot find any documentation on this, and the guesses I've made don't give me the behaviour I want. Clearly a lot of work has gone into this project so it seems a pity that uptake is...

Undefined reference to '_fdopen' when linking against bzip2 library

c++,linux,gcc,g++,standard-library
I'm new to compiling on linux, so I'm treading on somewhat unfamiliar territory. I'm using the G++ and GCC compilers on Ubuntu 14.04 . I'm trying to compile bzip2 (1.0.6) as a shared library and use it in another application. To build the shared library, I've used: gcc -shared -fPIC...

g++ Compilation in AIX server - Throwing core dump

c++,c,g++,aix
I have the below code. cat sample.c #include<stdio.h> #include "hello.c" int main() { hello_world(); return 0; } cat hello.c #include<stdio.h> void hello_world() { printf("Hello World"); } Compliation command Used: g++ -gxcoff -maix64 -shared -fpic -fpermissive -w -Ihello.c -o sample sample.c -Xlinker -e.main Execution $ ./sample Segmentation fault(coredump) I tried to...

Why do I need to add const to the argument?

linux,compiler-errors,g++,gtkmm
I have this function : void SpookyBoy( bool Troublemaker, const Glib::ustring& name, HorrorPunkBand& band ); if I remove the word const I got this error : no known conversion for argument 2 from ‘const char [5]’ to ‘Glib::ustring&’ I just wonder what does the compiler, can someone explains to me...

Hide long description of function while profiling with gprof2dot

g++,profiling,profiler,gprof
I use gprof2dot to profile my application: ./gprof2dot.py -f callgrind callgrind.out.x | dot -Tsvg -o output.svg source Even though, it gives me beautiful graphical profiling, the name of each function in each box is very long and goes far over screen size. Since boost library has high usage of templates....

cross compile Boost 1.57.0 on ubuntu for arm

g++,arm,cross-compiling
I am new into cross compile process. Need to cross compile boost library for arm. Please suggest step to cross-compile boost library. Is it possible to cross compile required feature of boost library?

Make mysqlpp::Connection object private member of wxFrame class object

c++,g++,mysql++
I'm getting errors trying to build code that has a mysqlpp::Connection object as a private member of my wxFrame object. class MyFrame: public wxFrame { public: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); private: mysqlpp::Connection conn(false); wxDECLARE_EVENT_TABLE(); }; G++ gives the following errors. C:\TestApp\testapp.cpp:31:28: error: expected identifier before...

c++ expected template-name before ‘<’ token error [closed]

c++,templates,ubuntu,inheritance,g++
I´ve browser other similar topics and did not find answer for my problem... Here are my classes, a base one and a derived one: Base.hpp namespace test { template<class T> class Base { public: Base(); virtual ~Base(); }; } Base.cpp #include "Base.hpp" namespace test { template<class T> Base<T>::Base() { //...

Customize where R looks for shared objects?

r,g++,rcpp,centos5,g++4.8
This question is similar to this previous question with respect to RcppArmadillo. Some quick context: I currently must work on a CentOS 5 system. Naturally, the compiler that comes with CentOS 5 was too old so we installed gcc-4.8.3. Now, others were concerned about back compatibility with the old compiler...

Strange gdb c++ error

debugging,g++,mingw
I am making a commandline program in C++ and have run into some strange problems. I am very new to C++, so this is probably why I am so baffled. I am using MinGW to compile and debug. Here is the current code: #include <string> #include <vector> #include <iostream> #include...

There is a way in gcc to get a warning when a constexpr can't be evaluated at compile time?

gcc,g++,c++14,constexpr
I'm using gcc 5.1.0 (c++14) and I was trying with constexpr. Is very annoying to verify if the constexpr I've implemented are evaluated at compile time. I couldn't find any flag for get a warning about that situation. Here is an example: example.cpp ----------------------------------------- #include <stdlib.h> const char pruVar[] =...

C++14 support in GCC is experimental

c++,gcc,g++,c++14,g++4.9
Quoting from the GCC page on C++14 support Important: Because the final ISO C++14 standard was only recently published, GCC's support is experimental. No attempt will be made to maintain backward compatibility with implementations of C++14 features that do not reflect the final standard. I could not find the official...

gcc auto dependency full path

c++,gcc,makefile,g++
I have a simple project - it has a foo.cxx and a bar.h: // bar.h // nothing // foo.cxx #include "bar.h" // nothing else If I include bar.h with ""s, then the dependency file has everything with its full paths: $ g++ -std=c++11 -MP -MMD -MF /home/barry/sandbox/foo.d -c /home/barry/sandbox/foo.cxx -o...

Why does using std::remove_reference and std::remove_const in different order produce different results?

c++,c++11,g++,typetraits,clang++
In the following code I have used std::remove_const and std::remove_reference but in different order in two cases which are giving different results : #include <iostream> #include <string> #include <vector> #include <iterator> #include <type_traits> using namespace std; int main() { vector<string> ar = {"mnciitbhu"}; cout<<boolalpha; cout<<"First case : "<<endl; for(const auto&...

Source code defined wide char strings and cross-platform

c,string,unicode,g++,widechar
Under Visual Studio source-code-defined strings like L"abc" result into a C-string with 2-bytes wide chars. What about Linux compilers ? Is it also possible to use the L"" syntax ? If yes, are the chars of the C-string linux wide chars (i.e 4-bytes wide) ? Is there a "cross-compiler" way...

C++ unsigned long doesn't wrap around after 4294967295

c++,visual-c++,integer,g++,long-integer
I was playing with some c++ code, and found that if I start a unsigned long with 4294967295 (its max allowed value) and add let's say 6 I MUST get 5, and it does! but the following operation of addition, and mod 255 does not give the correct answer. why...

warning: Wlogical-not-parentheses

c++,g++,warnings
I am confronted with a problem of a few days. I receive this warning when compiling my program. In member function 'void CClientManager::RESULT_SAFEBOX_LOAD(CPeer*, SQLMsg*)': 661:25: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses] if (!dwSkillVnum > 120) ^ And another warning : 661:25: warning:...

Enabling OpenGL 4.1 under OS X 10.10 with GLEW, GLFW and g++ compilation

c++,osx,opengl,g++,glfw
I have a 2014 RMBP, updated to the latest version of OS X which should guarantee me compatibility up to OpenGL 4.1. I have put together a minimal working example: #include <iostream> #include "GL/glew.h" #include <GLFW/glfw3.h> using namespace std; int main(){ int windowWidth = 800; int windowHeight = 800; string...

mysql C++ will not compile with make but will if g++ arguments put on cmd line

c++,mysql,c++11,make,g++
So i'm just trying to compile this sample mysql C++ program. It will compile and run just fine if i put g++ -Wall -I/usr/include/cppconn -o mysql_test mysql_test.cpp -L/usr/lib -lmysqlcppconn on the command line. If i try to use make, it fails due to a undefined function call. What is wrong...

Are memory leaks possible with decltype(new any_type())?

c++,c++11,memory-leaks,g++
I am checking for any memory leaks possibility with class pointers using valgrind and found out that following program has no memory leaks : #include <iostream> #include <utility> #include <memory> using namespace std; class base{}; int main() { unique_ptr<base> b1 = make_unique<base>(); base *b2 = new base(); cout << is_same<decltype(new...

Why can C compile time() without its library?

c++,c,gcc,g++,time.h
When I use the time() function (i.e., just randomize seed for rand() ) but not include the header file time.h, it works for C. For example: #include <stdio.h> #include <stdlib.h> int main() { int i; srand(time(NULL)); for(i=0;i<10;i++){ printf("\t%d",rand()%10); } printf("\n"); return 0; } When I try to compile the code...

What does gcc without multilib mean?

osx,gcc,g++,openmp
I was trying to use omh.h header file and I realized it was missing. I tried reinstalling gcc on my mac using brew. This is the message I got at the end of the installation. .. GCC has been built with multilib support. Notably, OpenMP may not work: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60670 If...

__cplusplus < 201402L return true in gcc even when I specified -std=c++14

c++,gcc,g++,c++14,predefined-macro
The directive: #ifndef __cplusplus #error C++ is required #elif __cplusplus < 201402L #error C++14 is required #endif The command-line: g++ -Wall -Wextra -std=c++14 -c -o header.o header.hpp My g++ version: g++ (tdm-1) 4.9.2 The error C++14 is required is generated even when I added -std=c++14, I don't know why. Please...

Making and compiling C++ projects with multiple files

c++,g++
I am new to C/C++, I already know the basics and I am starting to learn more advanced concepts now. Currently I am developing a project using C++ and it is quite a big one, so structuring my project will be better. From what I have already seen, a good...

multiple definition of #define function

c++,c,g++
I have logger.h file and defining a macro function for logging: //logger.h: #ifndef _LOGGER_H_ #define _LOGGER_H_ #ifdef LOG_DEBUG ofstream debug_log("debug.log"); #define log(...) debug_log << __FILE__ << ":" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "| " << __VA_ARGS__ << std::endl #else #define log(...) #endif #endif This header file is included...

gcc make dependency and object simultaneously

gcc,makefile,g++
I am using gcc 4.8.2, and I am trying to build both the object file and the dependency file concurrently. This works: $ g++ -std=c++11 -MP -MD -c foo.cxx -o foo.o $ [ -s foo.d ] && [ -s foo.o ] && echo yay yay However, instead of generating foo.d,...

How to deal with libraries like Boost when cross compiling for arm?

ubuntu,cmake,g++,cross-compiling,beagleboneblack
I'd like to cross compile from my AMD64 desktop to ARM7 for Beagleboard Black. So I started with this to get the cross compilers installed: sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf I also created a cmake toolchain file: set (CMAKE_SYSTEM_NAME Linux) set (CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) set (CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) When I run cmake,...

Can't use struct in derived templated class?

c++,templates,struct,g++
Ok, maybe not the best title, but here's the deal: I have a templated interface: template<typename T> class MyInterface { public: struct MyStruct { T value; }; virtual void doThis(MyStruct* aPtr) = 0; }; and an implementation: template <typename T> class MyImpl : public MyInterface<T> { public: void doThis(MyStruct* aPtr)...

C++. Avoiding cross-linking in multple files project

c++,linux,g++
I've been building many C++ projects for my university recently. They were consisted of multiple files with one Makefile. All in a prj folder with Makefile within, the source files in src folder and headers in inc folder. Makefile compiled it to object files in obj folder and than linked...

I need the install path to C++ in Ubuntu

c++,intellij-idea,ide,g++
I am trying to link IntelliJ to C++ in Ubuntu and I cannot find the install path to the g++ compiler. I know its there because I've installed it, I just can't find it. Thanks for the help. I'm working with IntelliJ 14

Using std::vector<> and std::shared_ptr<> should cause error

c++,c++11,g++,c++14
Here is my code of what I am doing : #include <iostream> #include <vector> #include <memory> using namespace std; int main() { vector<int> ar = {1}; shared_ptr<int> sp(&ar[0]); cout<<*sp<<endl; // ---- [1] ar[0] = 10; cout<<*sp<<endl; // ---- [2] ar.clear(); cout<<*sp<<endl; // ---- [3] return 0; } The output is...

compiling against libstdc++.so.5 is not finding symbols @GLIBCPP_3.2

c++,c,gcc,g++,libstdc++
I am building an application which makes use of a third party library which requires libstdc++.so.5. Until recently I was compiling my application with libstdc++.so.6 which worked fine, however it had some portability issues. Therefore I decided installing g++ version 3.3.4 in order to be capable of compiling my application...

No _fdopen on Linux and gcc

c++,visual-c++,g++
I'm calling fdopen. On Windows, using Visual C++ 2010, when I call it I get a warning saying Warning 1 warning C4996: 'fdopen': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fdopen. On Linux (g++ 4.8.2) it works. When I switch to _fdopen,...

Expand defines with GCC

c++,c,gcc,g++
How can I expand or collapse the defines in the header file for example #define IOC_IN 0x80000000 #define IOC_WS2 0x08000000 #define _WSAIOW(x,y)(IOC_IN|(x)|(y)) #define SIO_ASSOCIATE_HANDLE _WSAIOW(IOC_WS2,1) I tried doing gcc -E file.h > output.h however this outputs an empty file. I am using MingW compiler. I expect the defines to be...

undefined references when linking with static library with OTL using a makefile

c++,makefile,linker,g++
I want to link my project to a static library (msodbcsql11.lib), and I want to include it's header (msodbcsql.h) and another header file of a framework otlv4.h) using a simple makefile, but it looks like it can't find the library. Here is my makefile: CC=g++ LDFLAGS= CFLAGS=-c -Wall SOURCES=main.cpp LIBB...

Compiling with -mpopcnt causes Illegal instruction error

c++,linux,g++
I compile the following C++ code // main.cpp #include <cstdio> int main() { unsigned char tab[4] = {0}; printf("%d\n", __builtin_popcount(*((int *)tab))); } using command line: g++ -o prog main.cpp -mpopcnt When I run the program I get error: Illegal instruction Compiling without -mpopcnt does not give an error (it just...

Makefile on different folders

c++,makefile,g++
I know it has already been discussed a lot, but I'm getting a bit crazy and cannot figured it out by myself. I'm trying to learn how to create makefiles, and I'm having problems in defining a makefile for files in different folders. This is what I would like to...

Conversion error in std::remove function

c++,c++11,gcc,g++
Hello im trying to import a code a guy made in visual studio with c++ to gcc in linux. Im getting an error at this piece of code at the rhs.erase line. void cleanString(std::string &rhs) { char chars[] = "/-"; for (unsigned int i = 0; i < strlen(chars); ++i){...

main() used as a function and CLI

c++,build,g++,gnu-make,entry-point
I have several source files that run together as anonymous publish/subscribe nodes. There is a main function that collects all the nodes and launches them through their start functions. // main.cpp #include "nodeA.h" #include "nodeB.h" int main(int argc, char *argv[]) { /* some argument parsing here */ start_node_a(argc, argv); start_node_b(argc,...

will be initialized after [-Wreorder]

c++,g++
When I compile my files I get this warning : In file included from AsyncSQL.cpp:8:0: AsyncSQL.h: In constructor 'CAsyncSQL::CAsyncSQL()': AsyncSQL.h:192:10: warning: 'CAsyncSQL::m_iCopiedQuery' will be initialized after [-Wreorder] int m_iCopiedQuery; ^ Here is my AsyngSQL.H http://pastebin.com/u72kyuq7 So what am I doing wrong?...

Why does std::shared_ptr = std::unique_ptr compile, while std::shared_ptr = std::unique_ptr does not?

c++,stl,g++,c++14
I explored this topic in Coliru with the following input command: g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp && ./a.out The test can be found here, but I have posted the code below. I used int in my example, as it's a basic type. #include <iostream> #include <memory> struct Foo{...

Dwarf Error: Can't read DWARF data from '/tmp/spyauth787438238

debugging,gdb,g++,redhat
I am trying to debug a C++ code using GDB. I can run debugger, set breakpoints and also breakpoints are hit correctly. But when I've tried to execute 'next' command when a breakpoint is hit, it throws the following error: "Dwarf Error: Can't read DWARF data from '/tmp/spyauth787438238" Also I...

How -s option works actually in gcc compilers?

gcc,g++,command-line-interface
gcc & g++ provides command line option -s to reduce the size of executable file. But I want to know that how this -s option works exactly? What it does so that size of the executable reduces? How the size of file gets reduced?

What is needed for the simplest pass-by-reference?

c++,g++
I am very new to C++. I am comfortable with Java and Python and I am trying to do a quickstart into C++. I am trying to figure out how to declare/define a non-member function that takes an argument to a class object by-reference. I am unable to compile my...

Visual 2015 Compiling DLL

c++,visual-studio,dll,g++
I'm creating DLL that should work as module (runtime loading) It works on linux/windows with dlopen etc.. It looks like: .cpp std::string pomnoz(std::string &s, std::string &ds) { std::cout << s << " " << ds << std::endl; return s.append(ds); } .h #ifdef __cplusplus extern "C" { #endif std::string pomnoz(std::string &s,...

include throws No such file or directory

c++,netbeans,directory,g++,cygwin
#include<apis/api1/api.h> throws No such file or directory i even tried moving api.h and api.cc to the main project directory and using #include<api.h> does the same thing even though it is in the exact same directory that the other classes use i tried adding /apis/api1 to the compiler search path that...

clang bug? namespaced template class' friend

c++,g++,language-lawyer,clang++
The following code which doesn't compile under clang but does under gcc and VS: template<typename T> class bar; namespace NS { template<typename T> class foo { foo() {} template<typename U> friend class bar; }; } template<typename R> class bar { public: bar() { NS::foo<int> f; } }; int main(int, char...

What is the meaning of the libstdc++6.dylib version number on mac os x?

osx,g++,macports,libstdc++
I try to determine which version of libstdc++ is running by the gcc5.1 port on Mac OS X (Yosemite 10.10.3). The otool command gives the following information: /opt/local/lib/libgcc/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.21.0) What is the meaning of version 7.21.0? libstdc++7 does really exist?...

Friend name resolving scope in C++

c++,g++
This is legacy code that likely worked in era 3.2 or 2.8 g++, but no longer. It does still compile under microsoft C/C++ optimizing compiler v.17. The code has also been trimmed down from the original to isolate the salient issue. in function +=, error: 'to_every' was not declared in...

gcc warning flag at the end of warning output. what does it mean?

c++,c,gcc,g++,warnings
I want to know what does the warning flag at the end of warning statement (in compilation output) shows ? e.g in this code #include <stdio.h> int g_var = 'ghij'; int main(void) { fprintf(stderr," g_var = %d " , g_var); return 0; } when compiled with gcc temp.c compilation shows...

Where is the -I (captial i) path relative to in g++?

c++,include,g++,preprocessor,header-files
I am in the App folder of my project. I run the following command to compile character.cpp g++ -Wall -std=c++11 -I../App -c Character/character.cpp -o Obj/character.o which is in App/Character directory. character.cpp has the following include #include "Inventory/inventory.hpp" where the folder of inventory.cpp is App/Inventory. I thought because I am running...

Get address of a function which has variadic templates in C++11

c++11,g++
When saving the address of a function with a variadic template, the g++ compiler (Version 4.8.2) outputs this error: address of overloaded function with no contextual type information The code in question: template<typename... Args> void redirect_function(const char *format, Args... args) { pLog->Write(format, args...); // or: printf(format, args...); } void *fnPtr...

Use constexpr non-member size function in static_assert

c++,g++,clang++
Here is a simplified version of a situation that I encountered #include <array> template <typename T, size_t BufferSize> constexpr size_t size(const std::array<T, BufferSize>&) { return BufferSize; } template <typename T, size_t BufferSize> constexpr size_t size(const T (&)[BufferSize]) { return BufferSize; } template <typename Num, typename Buff> inline Num func(const Num&...

VLAs when compiling a C++ source with g++

c++,g++
I understand that VLAs are part of C99 but not C++0x. My question is then why and how g++ would compile code with VLAs. I wrote a test case below: test.c #include "stdio.h" int main(int argc, char *argv[]) { int i; int array[argc]; for(i = 0; i < argc; i++)...

Is there an equivalent of -I (capital I) for object files in g++?

c++,linker,g++
I have several object files coming from different directories (they are stored near the corresponding source that generated them). Is there a way that given this directory structure Root main.o Root/Some_long_path object_1.o object_2.o I could run a command like this g++ -Wall main.o -ISome_long_path object_1.o object_2.o -o app So that...

Expected unqualified-id before '[' token

c++,g++
I know this error is generally for syntax errors, but I can't seem to find anything wrong with this code. Can anyone help me point it out? Here are the errors I'm getting: deli.cc:10:7: error: expected unqualified-id before ‘[’ token int [] myCashierNums; ^ deli.cc:11:7: error: expected unqualified-id before ‘[’...

makefile foreach stops at the first iteration

makefile,g++
I have a list of source files to be compiled. I select them from different directories/subdirectories and in the end I have a list. I thought I would use a foreach loop with eval/call/define.The command info works and the first pass of make sees all of them. Here is the...

MinGW-W64 linker skipping incompatible files when searching for third-party static libraries

c++,windows,linker,g++,mingw-w64
I'm on Windows 7 64-bit, and I'm compiling with g++ from MinGW-W64. I'm trying to compile an application that I wrote on a Unix computer. I'm running into problems, however, when I try to link against certain third-party lib<name>.lib files. Specifically, I need to link to ROOT libraries. The linker...

Initializing a struct from a constructor

c++,struct,constructor,g++
I'm getting back into writing some C++ and I'm honestly rusty. I get the feeling I'd find a quick answer to my question if I just knew how to phrase it properly, but still I'd appreciate your help. sanitycheck.cpp: #include <string> using namespace std; typedef struct STR_1 { int val_a,...

Separately typing each library compiles, but a single static library archive fails

c++,g++,ar
I'm trying to build a single library so that it can be linked easily by a single -l switch. Basically If I compile an executable and type out all the libraries my project needs like so: g++ ncorr_test.cpp -o ncorr_test -I../include -I../../opencv/include/opencv2 -std=c++11 ../lib/ncorr.o ../lib/Strain2D.o ../lib/Disp2D.o ../lib/Data2D.o ../lib/ROI2D.o ../lib/Image2D.o ../lib/Array2D.o...

GDB core backtrace Bogus adresses

c++,gdb,g++,core,backtrace
When I compile same code with g++ with -o2 flag I can backtrace successfully without any Bogus adresses. Like; 0x08156079 in CItem::GetValue (this=0x3adb0f00, idx=0) at item.cpp:957 0x081b123c in quest::item_has_flag (L=0x3af9bdc0) at questlua_item.cpp:155 0x08363cba in luaD_precall (L=0x3af9bdc0, func=0x3b1cedd8) at ldo.c:249 0x0836ba86 in luaV_execute (L=0x3af9bdc0) at lvm.c:637 0x08363fad in resume (L=0x3af9bdc0, ud=0xffffa164)...

disabled exceptions and noexcept()

c++,c++11,g++,noexcept
std::swap is declared this way: template <class T> void swap (T& a, T& b) noexcept (is_nothrow_move_constructible<T>::value && is_nothrow_move_assignable<T>::value); If I disable exceptions in my program (like with -fno-exceptions for g++) will std::swap use move operations for my custom types if they are move-enabled no matter if they are noexcept or...

C++ Compile error on NetBSD '::system' has not been declared

c++,unix,boost,g++,netbsd
I have some C++ code that compiles nicely on Linux but so far I'm having trouble getting it to compile correctly on NetBSD. These are my includes: #include <fstream> #include <iostream> #include <cstdlib> #include <unistd.h> #include <iomanip> #include <boost/regex.hpp> I compile with this command: g++ -v -O2 -fno-strict-aliasing -I /usr/pkg/include...

Overloading function in C++ as unsigned char and unsigned int result in ambiguous

g++,function-overloading
I have to overloaded functions: void wypisz(unsigned int32 x, int n = 1); void wypisz(unsigned char x, int n = 1); here is code where I rise them: main() { wypisz((int32)(32), 7); wypisz('a', 7); return 0; } and when I try to compile it using G++ I get an error:...

C++ tokenizing madness with templates and virtual functions

c++,templates,g++,clang++
During refactoring of a rather large code-base my compiler came up with a great way to misunderstand me. This is a minimal example of what I am talking about: #include <iostream> class Foo { public: virtual int get() = 0; template <typename T> int get(int i) { return 4 +...

Static variable lifetimes, file-scope vs. function scope

c++,static,g++
suppose I have a .cpp file: static Foo aFoo; Foo& staticFoo(){ return aFoo; } Foo& singletonFoo(){ // not thread safe in c++-03 static Foo staticFoo; return staticFoo; } and a .h file that exposes these functions (but not aFoo directly). Am I certain that aFoo is initialized prior to staticFoo?...

g++ 4.6.3 reading contents of a file into string parsing ambiguity

c++,g++
I would like to read the contents of a ifstream #include <vector> #include <iterator> #include <fstream> std::ifstream stream; std::vector<char> buf(std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>()); But then when I say: if(buf.size()) ... I get an error error: request for member 'size' in 'buf', which is of non-class type 'std::vector<char, std::istreambuf_iterator<char, std::char_traits<char> > >(std::istreambuf_iterator<char, std::char_traits<char>...

Error with construction, unable to find object when calling its method?

c++,visual-c++,constructor,g++,rvalue
I've created a few toy classes below. During compilation, it appears that the compiler has some problem with constructing the object, but throws the error when the object's method is called. I've tried compiling using MSVC10 and gcc 4.9 and the respective error messages are: MSVC10: error C2228: left '.get'...

Why did the C++ designers choose not to allow non-member operator()()?

c++,c++11,gcc,g++,c++14
I am just playing with std::function<> and operators, to make C++ statements look like Functional Languages(F#) and found out that there is a difference between operator() and operator<<. My code : Function 1 (Operator Overload): function<int(int)> operator>>(function<int(int)> f1, function<int(int)> f2) { function<int(int)> f3 = [=](int x){return f1(f2(x));}; return f3; }...

No match for 'operator=' in sort function

c++,c++11,g++,codeblocks
I'm trying to have a program write out all permutations of a string. Here is my code: #include <stdio.h> #include <string> #include <iostream> #include <algorithm> using namespace std; int main () { string input; int length; cin >> input; input = sort(begin(input), end(input)); length = input.length(); do { cout <<...

How does GCC handle variable redefinition

c++,c,gcc,g++
I wrote a piece of code like this int a; int a = 100; int main() { } It was compiled successfully by GCC, but not by G++. I guess GCC handle this by ignoring the first definition of variable a. But I want to know the precise rule so...

Why this code didn't work for -m32?

c++,templates,g++,32bit-64bit
#include <stddef.h> template<size_t N = sizeof(void*)> struct a; template<> struct a<4> { enum { b }; }; template<> struct a<8> { template<int> struct b {}; }; enum { c, d }; int main() { a<>::b<c>d; d; } I have a piece of code which succesfully compiles for x64 architecture by...

How do I build gcc with C++ concepts (“concepts lite”) support?

c++,g++,generic-programming,c++-concepts,c++1z
The C++ standards committee is working on a TS (Technical Specification) for Concepts extension: "Programming Languages - C++ Extensions for Concepts". N4377 is the latest version of this document. For inclusion into the C++ standard features are asked to be implemented, ideally for a publicly accessible system. I'm aware of...

Single-command compile and link fails, separate steps work

linker,g++
While I was trying to solve a linker problem with g++, I found that trying to compile link a simple one-file program in one command was failing, due to undefined symbols. g++ -lEGL -lGLESv2 -o test test.cpp However, if I compiled test.cpp separately, and then linked as a second step,...

Compile a project with C and C++ files separately using gcc and g++?

c++,c,gcc,makefile,g++
I have a project that contains C and C++ files and I created a Makefile to compile this project. Is it possible to have a Makefile that will "separate" the C and C++ files, the C files will be compile with gcc and the C++ files with g++ and create...

C++ rounding behavior

c++,linux,g++,rounding
#include <iostream> #include <iomanip> int main() { float f = 0.115; std::cout << f << std::endl; std::cout << std::fixed << std::setprecision(2) << f << std::endl; return 0; } The output of the above code is: 0.115 0.12 It makes sense that 0.115 is rounded to 0.12. However, when we change...

Backtrace Queries Extremely Slow

c++,linux,g++,profiling,glibc
(Note: the following mentions execinfo / backtrace, but this is only an example. The behavior in the question appeared with various libraries.) Consider a utility library that tracks the resource allocations of some application linked with it. As functions allocate and deallocate resources, they call a tracking function that records...

Linking my program using g++

c++,linker,g++
I have some problems to build a program using g++. The program is using a library that I have written in C called libiec60063. I want to write my new project in C++ (even if not yet familiar with C++) but I can't manage to link it correctly. For example...

mingw64 (win8.1) how to let him see boost libs?

c++,windows,g++
I've installed at my win8.1 mingw and I would like to compile my program. When I use command: g++ -o test test.cpp -lboost_unit_test_framework-mt I got an error: no such file od directory: "#include boost/test/unit_test.hpp" // in "<>" ofc. when I use my msVS it works fine. ...

Memory allocation for public and private fields - GCC way

c++,c++11,gcc,g++,memory-alignment
This is not a duplicate of this question, I read the answers and I still have some questions about this subject. I tested some classes like this one: class A { private: int b; public: char c; int a; private: char e; }; And I've seen that the fields are...

Why this program compiles fine in C & not in C++?

c++,c,string,gcc,g++
Following program compiles fine in C with one warning but fails in compilation in C++. Why? What is the reason? #include <stdio.h> int main(void) { char a[5]="Hello"; a[0]='y'; puts(a); for(int i=0;i<5;i++) printf("%c",a[i]); return 0; } Warning:[Error] initializer-string for array of chars is too long [-fpermissive] enabled by default But if...

missing .lib file, Dynamic linking confusion

c++,linker,g++,eclipse-cdt
According to this question, Dynamic linking is done at run time, by the operating system. Until now, using g++ with eclipse CDT, I statically linked odbc32.lib I got from windows SDK to get some ODBC functions to my program. But I deleted the file by accident and was surprised to...

g++ include files in other directories

c++,c,compilation,linker,g++
I have a main.cpp file in a directory called test that has an #include "INIReader.h" The structure of the files is like below ---/test/main.cpp ---/inih/ini.h ini.c ---/inih/cpp/INIReader.h INIReader.cpp INIReader.cpp has these includes #include "../ini.h" #include "INIReader.h" I am trying to compile main.cpp in one line with g++ -o test -Wall...

Namespace “manufacturing” when I include [closed]

c++,namespaces,g++
I have a namespace problem that is driving me bat-sh*t crazy. There is a namespace called "Utility" written by another programmer here that I am using in some of my code. One file gives me nothing but problems. This file includes < algorithm > and I must have it. I've...

Why is there not any warning on a declaration without initialization in a for loop?

c++,initialization,g++,warnings,declaration
I tried to compile the following code using g++ (gcc version 4.8.2 (Debian 4.8.2-1)), with -Wall flag (adding the -Wextra flag does not change anything for me). #include <iostream> using namespace std ; int main() { int i ; cout << i << endl ; } It gave this warning:...

version `GLIBC_2.11' not found while using gcc

linux,gcc,g++,glibc,libc
I have problem using gcc/g++ after I changed the machine I use, I installed gcc-4.9.2 in my previous machine, when I moved to the new machine, I copied gcc folder to the new machine. When I try to use I get this error : /data/obenchek/gcc-4.9.2/bin/g++: /lib64/libc.so.6: version `GLIBC_2.11' not found...

How to compile multiple cpp file header file using gcc/g++?

c++,osx,g++
i am trying to compile multiple .cpp and .h file. But it show error. My files are: ApplicationWindow.cpp #include "ApplicationWindow.h" void ApplicationWindow::DrawContents () { GetView()->DrawOn(this); } ApplicationWindow.h #ifndef APPLICATION_WINDOW_H #define APPLICATION_WINDOW_H #include "Window.h" class ApplicationWindow : public Window { public: // ... virtual void DrawContents(); }; #endif /* APPLICATION_WINDOW_H */...

initialization of class member in anonymous union

c++,c++11,g++,clang++
I have observed that the following code segfaults at the line ar.p(): #include <iostream> class A { public: virtual void p() { std::cout<<"A!\n"; } }; class B : public A { public: void p() { std::cout<<"B!\n"; } }; struct Param { enum {AA, BB} tag; union { A a; B...

Wrapper for __m256 producing segmentation fault with constructor

c++,g++,avx,mingw-w64
I have a union that looks like this union bareVec8f { __m256 m256; //avx 8x float vector float floats[8]; int ints[8]; inline bareVec8f(){ } inline bareVec8f(__m256 vec){ this->m256 = vec; } inline bareVec8f &operator=(__m256 m256) { this->m256 = m256; return *this; } inline operator __m256 &() { return m256; }...

Why size of an empty array is 0 but size of an empty class is not 0?

c++,gcc,g++
For example: int main() { struct {} foo; int bar[0]; struct { int dummy[0]; } baz; cout << sizeof(foo) << endl; //display '1' cout << sizeof(bar) << endl; //display '0' cout << sizeof(baz) << endl; //display '0' return 0; } Please tell me is there any reason stand behind that...

g++ compilation error on AIX unix server

c++,g++,aix
I have a socket program server code written in C++. I'm facing the below error when it is compiled using g++ compiler(OS : Unix AIX). The same code compiled successfully using cc compiler(OS : Unix Sun OS ). Please let me know how to resolve it. Code snippet enum sockStates...

G++ Template instantiation results in “Undefined reference to” error

c++,templates,g++,undefined-reference
I've been having some issues lately with my custom written general purpose vector code, which relies on templates for functionality. I am reluctant to include the implementation in the header file (as is common with templates), as this would add significantly to the compilation time. So I have instead manually...

Downloading JUST g++ binary

g++
This question may seem stupid to you guys, but I am in a situation where I have no access to command line, and I need a version of g++ on my computer so I can compile my c++ code. I looked on the GNU repository, and I have NO idea...

Undefined reference to static const member in g++ if no using code is linked

c++,c++11,g++,linker-error
the project I'm working on currently consists of three basic build targets: The core, containing almost all of the classes The tests, containing only a few test classes and a main function. They touch (hopefully) every piece of code in the core. The client, which only consists of a main...

Linking a shared library in executable vs. another shared lib

c++,linux,linker,g++,clang++
tl;dr Are there any differences in the way linux loads and links a shared library if the library is linked by an executable or by another shared library? Background Suppose I have a shared library (e.g. libA.so) containing a class with a static std::map and a set of singleton classes....

Woking With BMP File in C++, Ubuntu

c++,linux,terminal,g++,bmp
I am trying to work with a bmp file in linux with g++ compiler. I am using C++ language. I Need to load a .bmp file from the standard input. for example: ./a.out < test.bmp So I need a Code to do this job. I think storing the whole .bmp...

SIGSEGV with std::map of pointers to template objects

c++,templates,inheritance,g++,stdmap
I need to keep a std::map of pointers to templated objects. To get rid of templates, I use a common untemplated base class. When running the code, I get a SIGSEGV signal. Debugging shows that the problem arises with statement data_[id] = s; It could be a problem related to...

how to force recompile when changing Makefile flags?

c++,c,gcc,g++
I am compiling some project with dependency so i won't have to recompile each time, but when i am adding -Dsome_flags to my CFLAGS, it is not recompiling. dep: $(CPPS) $(CC) $(CFLAGS) $(INC) -M $(CPPS) > dep i add to my CFLAS -DDEBUG_FLAG and it forces me to do make...

Returning iterator from constant member function

c++,c++11,g++,c++14
In the following code why the return type of foo::func is vector<int>::const_iterator and not vector<int>::iterator though I am returning an object of vector<int>::iterator. #include <iostream> #include <vector> #include <algorithm> using namespace std; class foo { private: vector<int> ar; public: foo() { ar.resize(10); iota(ar.begin(), ar.end(), 1); } auto func() const {...

Regex functionality in g++ 5.1

regex,g++,gcc5
Is all the regex functionality finally implemented in gcc5.1? The previous versions only had partial support.