g++

std::regex and dual ABI

橙三吉。 提交于 2019-12-22 05:13:57
问题 Today I have found an interesting case of the dual libstdc++ ABI affecting compatibility of libraries. Long story short, I have two libraries that both use std::regex internally. One is built with the CXX11 ABI and one is not. When these two libraries are linked together in one executable, it crashes on startup (before main is entered). The libraries are unrelated and do not expose interfaces that mention any std:: types. I thought such libraries should be immune to dual ABI issues.

Why calling via weak_ptr is so slow?

烂漫一生 提交于 2019-12-22 04:43:29
问题 I have read the question What's the performance penalty of weak_ptr? but my own tests show different results. I'm making delegates with smart pointers. The simple code below shows reproduces the performance issues with weak_ptr . Can anybody tell me why? #include <chrono> #include <functional> #include <iostream> #include <memory> #include <stdint.h> #include <string> #include <utility> struct Foo { Foo() : counter(0) { incrStep = 1;} void bar() { counter += incrStep; } virtual ~Foo() { std:

ambiguous overload with deleted move constructor

爷,独闯天下 提交于 2019-12-22 03:51:10
问题 g++ 4.6.3 and 4.7.2 fail to compile the following code (in c++0x mode) if BREAK is defined. template<class T> struct Test { Test(T&) {} #ifdef BREAK Test(T&&) = delete; #endif }; void func(Test<int> const&) {} void func(Test<double> const&) {} int main() { int x = 0; func(x); return 0; } The error is error: call of overloaded 'func(int&)' is ambiguous while clang 3.2 RC2 and VC11 (if I replace Test(T&&) = delete; with private: Test(T&&); ) accept the code. I can't see where that should be

Odd return behavior with std::function created from lambda (C++)

丶灬走出姿态 提交于 2019-12-22 01:54:03
问题 I'm having trouble with std::functions created from lambdas if the function returns a reference but the return type isn't explicitly called out as a reference. It seems that the std::function is created fine with no warnings, but upon calling it, a value is returned when a reference is expected, causing things to blow up. Here's a very contrived example: #include <iostream> #include <vector> #include <functional> int main(){ std::vector<int> v; v.push_back(123); std::function<const std:

Class template argument deduction failed with derived class

浪子不回头ぞ 提交于 2019-12-22 01:53:47
问题 #include <utility> template<class T1, class T2> struct mypair : std::pair<T1, T2> { using std::pair<T1, T2>::pair; }; int main() { (void)std::pair(2, 3); // It works (void)mypair(2, 3); // It doesn't work } Is the above well formed? Is it possible deduce the class template arguments in the second case if the constructors are being inherited? Are the constructors of std::pair participating in the creation of implicit deduction guides for mypair ? My compiler is g++ 7.2.0. 回答1: I think this is

What is libg2c library?

巧了我就是萌 提交于 2019-12-22 01:25:09
问题 I have found the code which links against of 'g2c' library. Why do I need it? Just would like to understand why it might be important and what it does in general. Thanks! 回答1: What is GNU Fortran? g77 consists of several components: A modified version of the gcc command, which also might be installed as the system's cc command. (In many cases, cc refers to the system's “native” C compiler, which might be a non-GNU compiler, or an older version of gcc considered more stable or that is used to

To include or -include auto-generated dependencies?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 00:20:18
问题 I like to use the g++ -MM feature to auto-build my dependencies. The way I do this is as follows: include $(ALLOBJ:%.o=%.d) %.d: %.cxx @echo making dependencies for $< @g++ -MM $(CXXFLAGS) $< -o $@ @sed -i 's,$*\.o,& $@ ,g' $@ Basically I can give this rule ALLOBJ , and it will: convert every .o name to a .d name, and include it, when it can't find a .d , it will create it from the .cxx file the final line of the %.d: %.cxx rule will add the name of the .d file to the file itself, so that the

g++ duplicate symbol error when working with templates (noob question)

让人想犯罪 __ 提交于 2019-12-21 20:46:47
问题 So I'm trying to pick C++, and to do so I decided to write a generic Group class using templates, that takes a Type and size as template parameters: in group.h: #ifndef __GROUP_H #define __GROUP_H #define MAX_SIZE 10 /********************************************************** * Define a Group class that handles a collection of members * of some Type **********************************************************/ template <class Type, int max> class Group { private: std::string name; int count,

How do I dump gcc warnings into a structured format?

倖福魔咒の 提交于 2019-12-21 20:44:52
问题 Like many, I build my project with the an abundance of warning flags. Since not all warning flags are detrimental, the compilation becomes noisy. Warnings such as "unused variables", "shadowing members in initialization lists", "missing switch defaults", are all important to log, but they create too much clutter during builds, and it is hard to spot the important warnings. Given a large project, there can be thousands of warnings mixed in with build statements, and parsing though it

How to compile a standalone OpenCV executable?

独自空忆成欢 提交于 2019-12-21 20:08:52
问题 I compile my my OpenCV programs as follows: g++ `pkg-config --cflags opencv --libs opencv` <filename>.cpp It works perfectly on my computer. Can I complile the shared libraries alone with the program so that it can be run on other computers which doesnt have opencv on it? If so, how do I do it? 回答1: The program during compilation are dynamically linked to Shared Libraries (.so files) on our computer. The executable compiled use these shared libraries during run-time. But these shared