Tag Archives: c++

[Solved] fatal error: cannot write PCH file: required memory segment unavailable

Error Message:

fatal error: cannot write PCH file: required memory segment unavailable
make[4]: *** [Makefile:1904: arm-eabi/bits/extc++.h.gch/O2g.gch] Error 1
make[4]: Leaving directory ‘/d/gnu/gcc-12.2.0-build/arm-eabi/libstdc+±v3/include’
make[3]: *** [Makefile:576: all-recursive] Error 1
make[3]: Leaving directory ‘/d/gnu/gcc-12.2.0-build/arm-eabi/libstdc+±v3’
make[2]: *** [Makefile:501: all] Error 2
make[2]: Leaving directory ‘/d/gnu/gcc-12.2.0-build/arm-eabi/libstdc+±v3’
make[1]: *** [Makefile:12620: all-target-libstdc+±v3] Error 2

 

 

Solution:

Downgrade your GCC pack, because there are some bugs in your current gcc-12.2.0. you can go to the official website or the following link to download it:

http://ftp.gnu.org/gnu/gcc/

[Solved] Error: error C2601: ‘b‘ : local function definitions are illegal error C2063: ‘b‘ : not a function

Scene:

In general, this problem may be that a "}" is missing
There is also a small probability that your C++standard library is C++98 or earlier, which does not support non built-in initialization list writing.


the Situation of Missing ‘}’

We can see that if our test1 method is short of one}, all subsequent functions will report errors. We need to check it carefully

Solution
Check for yourself that the first line of code near the line number that reports the error is missing a }.

C++ standard does not support
When your C++ standard is C++98, the initialization list of C++98 does not support the initialization list methods of non-built-in types. This can be seen in the following code

#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main()
{
	int a[] = { 1, 2, 3 };

	int b[] {1, 2, 3};
	vector<int> v{1,5,5};
	map<int, float> m{{1, 2.f}, {2, 3.2f}};

	return 0;
}

编译结果:

Solution:
Then in this case your non-built-in type variables will have to be initialized using other methods

ERROR [Executor task launch worker for task 30867] NebulaEdgeWriter:52 – failed to write

ERROR [Executor task launch worker for task 30867] NebulaEdgeWriter:52 – failed to write

11:32:16,614 ERROR [Executor task launch worker for task 30867] NebulaEdgeWriter:52 - failed to write INSERT edge `SUPPLIER_AVERAGE_QUOTA`(`four_level_name`,`start_time`,`push_time`,`quote_cycle`) VALUES -7708723366638923441->-7708723366638923441@6325772268643779185: ("Shock Absorber", "2022-05-16 18:25:24", "2022-05-17 09:57:34", "2") for Storage Error: More than one request trying to add/update/delete one edge/vertex at the same time.
11:32:16,614 ERROR [Executor task launch worker for task 30868] NebulaEdgeWriter:52 - failed to write INSERT edge `SUPPLIER_AVERAGE_QUOTA`(`four_level_name`,`start_time`,`push_time`,`quote_cycle`) VALUES -7708723366638923441->-7708723366638923441@6325772268643779185: ("Shock Absorber", "2022-05-16 18:25:24", "2022-05-17 09:57:34", "2") for Storage Error: More than one request trying to add/update/delete one edge/vertex at the same time.
11:32:18,658 ERROR [Executor task launch worker for task 30901] NebulaEdgeWriter:52 - failed to write INSERT edge `SUPPLIER_AVERAGE_QUOTA`(`four_level_name`,`start_time`,`push_time`,`quote_cycle`) VALUES 8524141067397973150->8524141067397973150@-2616939442014903388: ("Color Paint", "2022-01-15 17:11:57", "2022-01-17 17:20:07", "3") for Storage Error: More than one request trying to add/update/delete one edge/vertex at the same time.
11:32:22,097 ERROR [main] NebulaDataSourceEdgeWriter:98 - failed execs:
 List(INSERT edge `SUPPLIER_AVERAGE_QUOTA`(`four_level_name`,`start_time`,`push_time`,`quote_cycle`) VALUES -7708723366638923441->-7708723366638923441@6325772268643779185: ("Shock Absorber", "2022-05-16 18:25:24", "2022-05-17 09:57:34", "2"))
11:32:22,097 ERROR [main] NebulaDataSourceEdgeWriter:98 - failed execs:
 List(INSERT edge `SUPPLIER_AVERAGE_QUOTA`(`four_level_name`,`start_time`,`push_time`,`quote_cycle`) VALUES -7708723366638923441->-7708723366638923441@6325772268643779185: ("Shock Absorber", "2022-05-16 18:25:24", "2022-05-17 09:57:34", "2"))
11:32:22,097 ERROR [main] NebulaDataSourceEdgeWriter:98 - failed execs:
 List(INSERT edge `SUPPLIER_AVERAGE_QUOTA`(`four_level_name`,`start_time`,`push_time`,`quote_cycle`) VALUES 8524141067397973150->8524141067397973150@-2616939442014903388: ("Color Paint", "2022-01-15 17:11:57", "2022-01-17 17:20:07", "3"))

 

Solution: The data should be skewed, add this when partitioning can be

[Solved] Error:E0415 no suitable constructor exists to convert from “int“ to “Rational“

Scene:

The problem is that the constructor for is missing or is declared as explicit.

Please refer to the following scenario.

#include <iostream>

using std::cout;
using std::endl;

class Rational1
{
public:
	Rational1(int n = 0, int d = 1):num(n), den(d)
	{
		cout << __func__ << "(" << num << "/" << den << ")" << endl;
	}

public:
	int num; 
	int den;
};

class Rational2
{
public:
	explicit Rational2(int n = 0, int d = 1) :num(n), den(d)
	{
		cout << __func__ << "(" << num << "/" << den << ")" << endl;
	}

public:
	int num;
	int den;
};

void Display1(Rational1 r)
{
	cout << __func__ << endl;
}

void Display2(Rational2 r)
{
	cout << __func__ << endl;
}


int main()
{
	Rational1 r1 = 11;
	Rational1 r2(11);
	Rational2 r3 = 11; // error E0415
	Rational2 r4(11);

	Display1(1);
	Display2(2); // error  E0415
	return 0;
}

Explicit keyword

1. Specifies that the constructor or conversion function (from C++11) is explicit, that is, it cannot be used for implicit conversion and copy initialization
2. Explicit can be used with constant expressions The function is explicit if and only if the constant expression evaluates to true (From C++20)

Problem description

Error:E0415 no suitable constructor exists to convert from “int“ to “Rational“

Solution:

1. Implement the corresponding constructor yourself. (Recommended)
2. Delete the constructor modified by the explicit keyword. (Not recommended)

[Solved] error: invalid operands of types ‘const char [6]‘ and ‘const char [6]‘ to binary ‘operator+‘

 

preface

When using strings in C++, we habitually use + to connect two strings enclosed in "". The error is reported: error: invalid operators of types' const char [6] 'and' const char [6] 'to binary' operator+',


1. Scenarios

	//std::string str = "hello" + "world"; // error: invalid operands of types 'const char [6]' and 'const char [6]' to binary 'operator+'
	//std::string str = std::string("hello") + " world"; // correct
	//std::string str = "hello" + std::string("world"); //correct
	std::string str = "hello"" world"; //correct

    cout << "str=" << str << endl;

When using the+operator to connect two strings wrapped with "", an error occurs. The reason is that in C++, the strings enclosed by "" are regarded as const char* types, rather than string types.

2. Solution

Refer to the explanation on stackoverflow. For details, please read error: invalid operators of types’ const char * ‘and’ const char * ‘to binary’ operator+’

1. Explicitly declare one of them as std::string type (recommended)

std::string str = std::string("hello") + " world";

2. Remove the+and let the compiler splice strings (not recommended)

std::string str = "hello"" world";

Most compilers automatically splice strings enclosed by "", but it is not guaranteed that all compilers are normal. It is recommended to display strings declared as string types and then perform the+operation.


3. Validation

	std::string str1 = std::string("hello") + " world" + "!"; // correct
    std::string str2 = "hello" + std::string(" world") + "!"; //correct
    std::string str3 = "hello"" world" "!"; //correct

    cout << "str1=" << str1 << endl;
    cout << "str2=" << str2 << endl;
    cout << "str3=" << str3 << endl;

[Solved] fatal error C1083: Cannot open included files: “stdafx.h”: No such file or directory

 

1. Error reporting

“Cannot open include file:” StdAfx. H “: no such file or directory”

The error here is that you included the header file # include generated by “StdAfx.h”. Presumably, you created an empty project but included this header file.

2. Solution

Method 1
replace the header file (this method is recommended, which is simpler); The contents of “StdAfx.h” are:

#include < stdio.h>
#include < tchar.h>
just delete your # include “StdAfx.h” here. Replace with what it contains. Namely:

#include < stdio.h>
#include < tchar.h>

method 2:
in your project, find the header file and add a header file named StdAfx.h: After adding successfully, click and add content:

#include < stdio.h>
#include < tchar.h>
save, compile again, and resolve the error~

 

[Solved] error C2041: illegal digit ‘9‘ for base ‘8‘ | error C2059: syntax error: ‘bad suffix on number‘

Error log

Text

Octal value is out of range

1> E:\CProject\test12\Source. c(5,10): error C2041: illegal digit ‘8’ for base ‘8’

Hexadecimal value is out of range

1> E:\CProject\test12\Source. c(5,10): error C2059: syntax error: ‘bad suffix on number’
1> E:\CProject\test12\Source. c(5,10): error C2153: integer literals must have at least one digit
1> E:\CProject\test12\Source. c(5,13): error C2021: expected exponent value, not ‘;’
1> E:\CProject\test12\Source. c(5,10): warning C4244: ‘initializing’: conversion from ‘double’ to ‘int’, possible loss of data
1> Done building project “test12.vcxproj” – FAILED.

Screenshot (hexadecimal value exceeds the range)

Solution:

C2041 series error: this kind of number, which is generally octal or hexadecimal, is out of range
for example:

  1. 09; because there is no 9 in octal
  2. 0xq; because hex doesn’t have the q character.

This requires us to carefully check whether the relevant figures exceed the range.

[Solved] fatal error C1189: #error: STL1003: Unexpected compiler, expected C++ compiler

Error Log:

screenshot

text version:

F:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\yvals_core.h(23,1): fatal error C1189: #error: STL1003: Unexpected compiler, expected C++ compiler.
F:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\yvals_core.h(23,1): fatal error C1189: #error: STL1003: Unexpected compiler, expected C++ compiler.

 

Error

Solution:
This problem is because the C++ header file is referenced in the C file. Just replace cmath with math.h.

error: undefined reference to `calculate()` [How to Solve]

Error Messages:

error: undefined reference to `calculate()`

 

When calling functions in xx.h and xx.c, such as calculate()
are as follows:

#include "xx.h"
int t;
int result = calculate(t);

An error is reported at this time:

error: undefined reference to `calculate()`

 

Solution:

Modify xx.c to xx.cpp, it will be OK!
Guessing that a direct call to xx.h in Qt may not find the definition in xx.c, but only the definition in xx.cpp can be recognized.

[Solved] vcpkg Error: Error: Could not detect vcpkg-root.

Phenomenon

When transferring vcpkg from CentOS 8 to CentOS virtual machine through SCP, the above error is always reported when running vcpkg

Root cause

The Linux environment needs to add the system variable $VCPKG_ROOT

Solution:

vim ~/. bash_profile

Add a line:

export VCPKG_ROOT=”/home/devuser1/vcpkg”

Change the directory to your directory

Close the shell, reconnect, and everything is OK

verification

[root@localhost vcpkg]# ./vcpkg list
abseil:x64-linux                                   2021-03-24#1     an open-source collection designed to augment th...
amqpcpp:x64-linux                                  4.3.11           AMQP-CPP is a C++ library for communicating with..

[Solved] runtime error: reference binding to null pointer of type ‘std::vector<int, std::allocator<int>>‘

How to Solve Error: runtime error: reference binding to null pointer of type ‘std::vector<int, std::allocator<int>>‘

For vector<vector >
When initializing it, you have to open up the appropriate storage space for it!

Solution:
when initializing, open up the required storage space:

//Suppose the size of the two-dimensional array space is m x n
vector<vector<int> > count(m);
for(int i=0;i<m;i++)
	count[i].resize(n);

[Solved] catkin_make Error: Invoking “make -j12 -l12“ failed

While studying the official ROS tutorial Writing a Simple Publisher and Subscriber (C++), the following error occurred when running catkin_make:

Base path: /home/free/catkin_ws
Source space: /home/free/catkin_ws/src
Build space: /home/free/catkin_ws/build
Devel space: /home/free/catkin_ws/devel
Install space: /home/free/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/free/catkin_ws/build"
####
####
#### Running command: "make -j12 -l12" in "/home/free/catkin_ws/build"
####
[  0%] Built target std_msgs_generate_messages_lisp
[  0%] Built target std_msgs_generate_messages_nodejs
[  0%] Built target std_msgs_generate_messages_cpp
[  0%] Built target std_msgs_generate_messages_py
[  0%] Built target std_msgs_generate_messages_eus
[  0%] Built target _beginner_tutorials_generate_messages_check_deps_Num
[  0%] Built target _beginner_tutorials_generate_messages_check_deps_AddTwoInts
[ 58%] Built target beginner_tutorials_generate_messages_py
[ 64%] Built target beginner_tutorials_generate_messages_eus
[ 58%] Built target beginner_tutorials_generate_messages_lisp
[ 58%] Built target beginner_tutorials_generate_messages_cpp
[ 76%] Built target beginner_tutorials_generate_messages_nodejs
[ 76%] Built target beginner_tutorials_generate_messages
[ 82%] Linking CXX executable /home/free/catkin_ws/devel/lib/beginner_tutorials/talker
[ 88%] Linking CXX executable /home/free/catkin_ws/devel/lib/beginner_tutorials/listener
/usr/bin/ld: CMakeFiles/listener.dir/src/listener.cpp.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: Final link failure: output non-representable links
collect2: error: ld returned 1 exit status
beginner_tutorials/CMakeFiles/listener.dir/build.make:112: recipe for target '/home/free/catkin_ws/devel/lib/beginner_tutorials/listener' failed
make[2]: *** [/home/free/catkin_ws/devel/lib/beginner_tutorials/listener] Error 1
CMakeFiles/Makefile2:1344: recipe for target 'beginner_tutorials/CMakeFiles/listener.dir/all' failed
make[1]: *** [beginner_tutorials/CMakeFiles/listener.dir/all] Error 2
make[1]: *** Waiting for unfinished tasks....
/usr/bin/ld: CMakeFiles/talker.dir/src/talker.cpp.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: Final link failure: output non-representable links
collect2: error: ld returned 1 exit status
beginner_tutorials/CMakeFiles/talker.dir/build.make:112: recipe for target '/home/free/catkin_ws/devel/lib/beginner_tutorials/talker' failed
make[2]: *** [/home/free/catkin_ws/devel/lib/beginner_tutorials/talker] Error 1
CMakeFiles/Makefile2:1381: recipe for target 'beginner_tutorials/CMakeFiles/talker.dir/all' failed
make[1]: *** [beginner_tutorials/CMakeFiles/talker.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j12 -l12" failed

After looking for the reason for a long time, I finally found that the final error was due to the wrong version of GCC and G + +. After changing GCC and g++ 5.5.0, I successfully compiled

Process for installing GCC and g++ version 5.5.0:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test 
sudo apt-get update 
sudo apt-get install gcc-5
sudo apt-get install g++-5

Change GCC and g++ versions

cd /usr/bin 
sudo rm gcc 
sudo ln -s gcc-5 gcc 
sudo rm g++ 
sudo ln -s g++-5 g++

Finally, check whether the modification is successful

gcc --version
g++ --version

Recompile:

catkin_make clean   #Clear the front compile
catkin_make