g++

“pure virtual function called” on gcc 4.4 but not on newer version or clang 3.4

余生长醉 提交于 2019-12-18 19:09:04
问题 I've got an MCVE which, on some of my machines crashes when compiled with g++ version 4.4.7 but does work with clang++ version 3.4.2 and g++ version 6.3. I'd like some help to know if it comes from undefined behavior or from an actual bug of this ancient version of gcc. Code #include <cstdlib> class BaseType { public: BaseType() : _present( false ) {} virtual ~BaseType() {} virtual void clear() {} virtual void setString(const char* value, const char* fieldName) { _present = (*value != '\0');

let's analyse “collect2: ld returned 1 exit status”?

非 Y 不嫁゛ 提交于 2019-12-18 18:55:09
问题 I know this indicates a linker problem, mostly unresolved symbols. I know that to resolve that problem / to get rid of that errormessage, one would have to provide much more information. I know there is a lot of questions on resolving this problems on SO already. My questions aims at helping to understand make and ld, to find out what (and who) is trying to express what with this line. collect2: ld returned 1 exit status What does "collect2:" mean? Is it a step make invokes ? I can't find an

How to use execv() without warnings?

一笑奈何 提交于 2019-12-18 17:50:23
问题 I am working on MacOS-X Lion with GCC 4.2. This code works, but I get a warning I would like fix: #include <unistd.h> main() { char *args[] = {"/bin/ls", "-r", "-t", "-l", (char *) 0 }; execv("/bin/ls", args); } warning: deprecated conversion from string constant to 'char*' I do not want the warning to be suppressed, I want not to have it at all. It is C++ code, not C. Using a char *const (so exactly the type required by execv()) still produces the warning. Thank you. 回答1: This seems to be ok

How to use execv() without warnings?

筅森魡賤 提交于 2019-12-18 17:50:04
问题 I am working on MacOS-X Lion with GCC 4.2. This code works, but I get a warning I would like fix: #include <unistd.h> main() { char *args[] = {"/bin/ls", "-r", "-t", "-l", (char *) 0 }; execv("/bin/ls", args); } warning: deprecated conversion from string constant to 'char*' I do not want the warning to be suppressed, I want not to have it at all. It is C++ code, not C. Using a char *const (so exactly the type required by execv()) still produces the warning. Thank you. 回答1: This seems to be ok

Static linking of Glibc

£可爱£侵袭症+ 提交于 2019-12-18 15:32:14
问题 How can i compile my app linking statically glibc library, but only the code needed for my app? (Not all lib) Now my compile command: g++ -o newserver test.cpp ... -lboost_system -lboost_thread -std=c++0x Thanks! 回答1: That's what -static does (as described in another answer): unneeded modules won't get linked into your program. But your expectations on the amount of stuff which is needed (in a sense that we can't convince linker to the contrary) may be too optimistic. If you trying to do it

How can I get gcc to add a prefix to all symbol names

扶醉桌前 提交于 2019-12-18 15:17:41
问题 I know that in the past there was an option -fprefix-function-name that would add a prefix to all generated symbols, it doesn't seem to be part of gcc anymore. Is there any other way to do this? 回答1: I believe this answer will give you the solution. In short, you can 'prefix' symbols in an existing library using objcopy like this: objcopy --prefix-symbols=foo_ foo.o 回答2: *EDIT: George Skoptsov's solution's better than mine :) The nm trick might come in handy though. This is not exactly what

What does gcc without multilib mean?

本小妞迷上赌 提交于 2019-12-18 12:49:38
问题 I was trying to use the 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 you need OpenMP support you may want to brew reinstall gcc --without-multilib ==> Summary 🍺 /usr/local/Cellar/gcc/4.9.2_1: 1156 files, 203M It suggests that if I need OpenMP support I need

“g++” and “c++” compiler

孤者浪人 提交于 2019-12-18 12:43:30
问题 I just found on my Ubuntu, there are two different C++ compiler: /usr/bin/g++ and /usr/bin/c++. I am not familiar with the latter, but man c++ just jumps to the manpage of gcc. I wonder what is their difference as C++ compilers? 回答1: This is typical Ubuntu symlink mayhem. If you ls -l /usr/bin/c++ , you will see it is actually a symbolic link. to: /etc/alternatives/c++ Which in turn, is also a symbolic link to: /usr/bin/g++ So, on Ubuntu systems, c++ is g++. The reasoning behind the link

Dump class/struct member variables in g++

不打扰是莪最后的温柔 提交于 2019-12-18 12:19:14
问题 Is there a flag in g++ or tools to dump the member variables of a struct/class? To illustrate, consider source code like this struct A { virtual void m() {}; }; struct B : public A { int b; virtual void n() = 0; }; struct C : public B { int c1, c2; void o(); }; struct D : public C { virtual void n() {}; A d; }; I want to get something similar to A: 0 = (vptr) B: 0 = (vptr) 4 = b C: 0 = (vptr) 4 = b 8 = c1 12 = c2 D: 0 = (vptr) 4 = b 8 = c1 12 = c2 16 = d ( -fdump-class-hierarchy does not work

Upgrade GCC 4.6.3 on Ubuntu 12.04 to 4.8.2

本小妞迷上赌 提交于 2019-12-18 12:08:20
问题 I'm about to update default GCC (version 4.6.3) shipped by Ubuntu 12.04 to 4.8.2, though the compilation requires a standalone C++ compiler admin@ubuntu: /usr/local/gcc_build$ sudo make ends up with configure: error: C++ compiler missing or inoperational make[2]: *** [configure-stage1-libcpp] Error 1 Therefore I turn to the process of g++ installation with a preference to the latest version, which means that I would like to compile from source directly rather than apt-get . But seriously, I