g++

segmentation fault on a recursive function

♀尐吖头ヾ 提交于 2021-02-10 18:42:13
问题 I simply want to test something. I am wondering what I did wrong? #include <iostream> using namespace std; unsigned long pwr(unsigned long n, unsigned long m) { if(m == 0) n = 1; if(m == 1) n = n; n = pwr(n, m/2) * pwr(n, m/2); return n; } int main () { unsigned long n(2), m(16); cout << pwr(n, m); return 0; } output is Segmentation fault 回答1: There is no exit from recursion. You may wanted if(m == 0) n = 1; else if(m == 1) n = n; else n = pwr(n, m/2) * pwr(n, m/2); return n; 回答2: Infinite

segmentation fault on a recursive function

夙愿已清 提交于 2021-02-10 18:40:39
问题 I simply want to test something. I am wondering what I did wrong? #include <iostream> using namespace std; unsigned long pwr(unsigned long n, unsigned long m) { if(m == 0) n = 1; if(m == 1) n = n; n = pwr(n, m/2) * pwr(n, m/2); return n; } int main () { unsigned long n(2), m(16); cout << pwr(n, m); return 0; } output is Segmentation fault 回答1: There is no exit from recursion. You may wanted if(m == 0) n = 1; else if(m == 1) n = n; else n = pwr(n, m/2) * pwr(n, m/2); return n; 回答2: Infinite

C++ compiler not finding #include <thread>

这一生的挚爱 提交于 2021-02-10 18:13:58
问题 Here is the top of my source file: #include <iostream> #include <thread> #include <fstream> ... thread help(startHelp); Where the thread is inside the function handleRequestsFromServer and startHelp is a void function. When compiling this with g++ on Mac OS X 10.8.4, I get this error: $ g++ diskutilityhelper.cpp -o run.out diskutilityhelper.cpp:5:18: error: thread: No such file or directory diskutilityhelper.cpp: In function ‘void handleRequestsFromServer()’: diskutilityhelper.cpp:140: error:

building for macOS-x86_64 but attempting to link with file built for macOS-arm64

对着背影说爱祢 提交于 2021-02-10 18:00:25
问题 I wrote a code using c++ and OpenCV: #include <iostream> #include <time.h> #include <opencv2/opencv.hpp> #include <opencv2/highgui.hpp> using namespace std; int main() { ... return 0; } then I trying to Running my code on the terminal and build using g++: g++ $(pkg-config --cflags --libs opencv) -std=c++11 yourFile.cpp -o yourFileProgram but I get this error: ... ld: warning: ignoring file /opt/homebrew/Cellar/opencv/4.5.1_2/lib/libopencv_core.dylib, building for macOS-x86_64 but attempting

Why does sqrt() work fine on an int variable if it is not defined for an int?

大兔子大兔子 提交于 2021-02-10 12:19:40
问题 In chapter 3 of Programming: Principles and Practice using C++ (sixth printing), Stroustrup states (p.68): "Note that sqrt() is not defined for an int " . Here is a simple C++ program based on that chapter: #include "std_lib_facilities.h" int main() { int n = 3; cout << "Square root of n == " << sqrt(n) << "\n"; } Given the quote above, I would expect the process of compiling or running this program to fail in some way. To my surprise, compiling it (with g++ (GCC) 4.2.1) and running it

Enable error when linking if a function is not implemented

与世无争的帅哥 提交于 2021-02-10 08:44:38
问题 I noticed that when linking a project using G++, if there are functions that are declared, but not implemented, there are no errors, unless I try to call them. Q1: Is it possible to enable an error (or at least warning) if a function is declared but not implemented? Q2: Why this behavior? ( Note: I am using G++ 4.7.0 , ld 2.22 if that is the linker used by gcc, from the mingw package) 回答1: A2: An entity such as a non-inline function with external linkage can have zero or one definitions in a

Why does boost::interprocess::managed_shared_memory throw a boost::interprocess_exception upon construction?

ⅰ亾dé卋堺 提交于 2021-02-10 07:26:08
问题 In the code below, I'm trying to initialize a managed_shared_memory object. When the constructor is invoked I see the below error message - terminate called after throwing an instance of 'boost::interprocess::interprocess_exception' what(): boost::interprocess_exception::library_error Aborted why is this exception being thrown? I'm running this on an ubuntu 16.04 linux OS, compiled the program using g++ 9.3.0. Boost version 1.58.0 struct test_obj { size_t x; size_t y; uint8_t buf[32]; bool is

Unresolved Inclusion in Eclipse CDT

走远了吗. 提交于 2021-02-10 06:15:19
问题 I have read: unresolved external symbol in eclipse cdt and Unresolved inclusion in Eclipse I am using Eclipse CDT Neon Version: Neon.3 Release (4.6.3). Eclipse CDT can compile my code but for some reason, it highlights #include <boost/algorithm/string.hpp> #include <boost/algorithm/string/split.hpp> as "Unresolved inclusion". I have already set the include path for my GCC compiler (in properties->C/C++ Build->Settings->Tool Settings->Includes) to have /opt/boost, which symlinks to /opt/boost

Unresolved Inclusion in Eclipse CDT

冷暖自知 提交于 2021-02-10 06:13:57
问题 I have read: unresolved external symbol in eclipse cdt and Unresolved inclusion in Eclipse I am using Eclipse CDT Neon Version: Neon.3 Release (4.6.3). Eclipse CDT can compile my code but for some reason, it highlights #include <boost/algorithm/string.hpp> #include <boost/algorithm/string/split.hpp> as "Unresolved inclusion". I have already set the include path for my GCC compiler (in properties->C/C++ Build->Settings->Tool Settings->Includes) to have /opt/boost, which symlinks to /opt/boost