will be initialized after [-Wreorder], 类成员构造顺序
初始化列表的顺序应该是按照你成员声明顺序初始化
#include <iostream>
using namespace std;
class Test
{
public:
Test(int j)
:pb(j)
,pa(pb+5) //和定义顺序有关。。。先初始化pa再初始化pb
{
}
public:
int pb; //如果pb放在pa前面,pb就先初始化,pa就是15
int pa;
};
void main()
{
Test a(10);
cout<<a.pa<<endl;
cout<<a.pb<<endl;
cin.get();
}
__memcpy_ssse3_back段错误
-
错误
#0 0x00007ffff7341829 in __memcpy_ssse3_back () from /lib64/libc.so.6
#1 0x00007ffff7b9256e in char* std::string::_S_construct(char const*, char const*, std::allocator const&, std::forward_iterator_tag) ()
from /lib64/libstdc++.so.6
#2 0x00007ffff7b925dd in std::basic_string, std::allocator >::basic_string(char const*, unsigned long, std::allocator const&) () from /lib64/libstdc++.so.6
#3 0x0000000000400c1f in main (argc=1, argv=0x7fffffffd9e8) at a.cpp:20 -
解决
线程之间的锁定存在错误,并且以某种方式覆盖了内存或在其他线程中释放了内存。修复了锁定依赖性后,segfault的问题就解决了。
jump to case label [-fpermissive]、cannot jump from switch statement to this case
问题:C语言编程时,在switch case 结构中, 如果在case里定义变量就会出现这种编译错误:jump to case label [-fpermissive]
原因:编译器认为这种写法会错过变量的定义,因些报这个错。
解决方法:将变量的定义移到switch case结构之上;
总结:不要在case语句下定义变量;
在有返回值的函数中,控制流程到达函数尾
添加默认返回值比如:
return 0;
Enable multithreading to use std::thread: Operation not permitted
error://usr/local/lib/libavformat.a(http.o): undefined reference to symbol’inflateInit2_’
解决办法:
添加链接库zlib
编译选项中加上
-lz
error: cannot jump from this goto statement to its label
发现变量的声明必须放在任何goto前面, 不能再goto后边声明变量
undefined symbol: _ZNSt8ios_base4InitD1
错误:
[root@localhost usehellolib]# gcc main.cpp -I include/ -L lib/ -lhello -o usehello
/usr/bin/ld: /tmp/cct6c7yF.o: undefined reference to symbol '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4'
//usr/lib64/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: 错误:ld 返回 1
原因:
用gcc编译C++动态库导致,用g++编译就好了
解决:
[root@localhost usehellolib]# g++ main.cpp -I include/ -L lib/ -lhello -o usehello
undefined reference to symbol ‘gzclose’
错误
/usr/bin/ld: ../../lib/opencv/libopencv_core.a(persistence.cpp.o): undefined reference to symbol 'gzclose'
//usr/lib64/libz.so.1: error adding symbols: DSO missing from command line
解决:
-lz
对’pthread_atfork’的未定义引用
- 错误
对'pthread_atfork'的未定义引用
-
原因:没有引用
pthread
-
解决:
-pthread
undefined reference to symbol ‘dlclose@@GLIBC_2.2.5’
- 错误:
undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
//usr/lib64/libdl.so.2: error adding symbols: DSO missing from command line
- 解决:
-ldl # 显式加载动态库的动态函数库
还有一种情况,就是链接库有问题.比如本案例中,吾意思是链接-lavcodec,结果没有libavcodec.so,却有libavcodec.a,于是什么都链接不上.
对‘shm_open’未定义的引用
- 错误:
对‘shm_open’未定义的引用
- 解决:
target_link_libraries(${PROJECT_NAME} rt)
对‘pow’未定义的引用
- 错误:
对‘pow’未定义的引用
- 解决:
在linux环境下编译时,需要链接数学库,参考解决方式:
在编译语句后面加一个 -lm
target_link_libraries(${PROJECT_NAME} -lm)
error This file requires compiler and library support for the ISO C++ 2011 standard.
error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
当使用CMAKE编译工程时,出现这个错误,解决办法:
在工程主目录的CMakeLists.txt中添加如下,可以编译成功:
SET( CMAKE_CXX_FLAGS "-std=c++11 -O3")
错误:变量‘std::ofstream fout’有初始值设定,但是类型不完全
-
问题描述:
-
原因分析:
头文件引入不完全
- 解决方案:
引入头文件:
error This file requires compiler and library support for the ISO C++ 2011错误解决办法
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()