error: cannot convert xx lambda to xx pointer in initialization

lambda和指针并不能无缝转换,如果lambda有捕获,不能赋值给指针,需要用std::function来存,SO

这个编译错误很难看懂,特别是模版,多余的信息一大堆,我看了半天才发现是lambda的问题

cannot allocate memory in static TLS block

dlopen遇到的,问题在于so文件的依赖,要排除掉用thread local storage的依赖,既然是dlopen的so,就要最小化依赖

主要问题是pthread 实现中 TLS 和线程栈使用的是同一块内存空间,内存不够用dlopen直接报错推出

这里有个简单代码走读

server.h:1022:5: error: expected specifier-qualifier-list before ‘_Atomic’

 _Atomic unsigned int lruclock; /* Clock for LRU eviction */

redis 6.0rc报错_Atomic引起的,这个是c11关键字

原来redis终于用c11了,毕竟2020了。

我看了下makefile,flags里有std=c11,搜了半天,搜到了都是升级gcc的方法

我的测试机器有两个gcc,gcc 4.8和gcc5.4 参考链接介绍了redis构建使用自定义编译器的方法

CC=clang make

猜测我的机器使用了旧的gcc,所以手动CC=/xx/gcc-5.4.0/bin/gcc make,总算编译成功

warning: invalid application of ‘sizeof’ to a function type [-Wpointer-arith]

class GuessMySize 
{ 
public:     
  virtual void Foo() {}     
  char a[5];     
  int b;     
  double c;     
  short d; 
};  

int f() {  return  sizeof(GuessMySize);     } //40

int f2() { GuessMySize a; return  sizeof(a);     } // 40

int f3() {  return  sizeof(GuessMySize{});     } // 40

int f4() {  return  sizeof(GuessMySize());     } // 1

f4会有这个报错,返回的是1,sizeof把内部的表达式翻译成函数了

cc1plus: out of memory allocating 228680 bytes after a total of 14639104 bytes virtual memory exhausted:

内存不够了,如果无法升级硬件就打开swap解决,如果是ld链接失败可以考虑换lld

tbb::strict_ppl::concurrent_queue<std::function<void()>*>’ has no member named ‘emplace’

错误:‘class tbb::strict_ppl::concurrent_queue<std::function<void()>*>’ has no member named ‘emplace’
     _queue.emplace(new Task(t));
            ^~~~~~~
make[2]: *** [src/CMakeFiles/faster.dir/wrdb/async_task.cc.o] 错误 1
make[1]: *** [src/CMakeFiles/faster.dir/all] 错误 2

tbb centos内置的版本太旧了没有emplace接口,这里用 https://github.com/wjakob/tbb make build && cd build && cmake ../tbb && make install 一套流程下来就解决了,我一开始用onetbb,链接阶段符号有点问题,报ld: error: undefined symbol: tbb::detail::r1::cache_aligned_deallocate(void*)

/usr/bin/ld: cannot find -llzma

需要安装xz-dev/xz-devel

用PRIu64来打印uint64 有编译错误

error: expected ')' before 'PRIu64'
   ROCKS_LOG_DEBUG(info_log_, "kAllCommitted ts in commit: #%" PRIu64,
                                                               ^
./util/logging.h:19:74: note: in definition of macro 'PREPEND_FILE_LINE'
 #define PREPEND_FILE_LINE(FMT) ("[" __FILE__ ":" TOSTRING(__LINE__) "] " FMT)
                                                                          ^
utilities/transactions/transaction_db_impl.cc:272:3: note: in expansion of macro 'ROCKS_LOG_DEBUG'
   ROCKS_LOG_DEBUG(info_log_, "kAllCommitted ts in commit: #%" PRIu64,
   ^
utilities/transactions/transaction_db_impl.cc:273:62: error: expected ')' before ';' token
                   TSmgr_.TimeStamps[kAllCommitted].timestamp);

解决办法,头文件前加上宏定义

#define __STDC_FORMAT_MACROS
#include <inttypes.h>

https://stackoverflow.com/questions/14535556/why-doesnt-priu64-work-in-this-code

gcc编译提示siginfo_t找不到

在redis基础上开发,redis 编译条件是-std=c99

我加了个新文件,包含了一个外部头文件threadpool.h,和server.h

在server.h中有原型

void sigsegvHandler(int sig, siginfo_t *info, void *secret);

编译提示找不到,但其他文件没有这个问题,

我将这两个头文件交换顺序,编过了。判断是threadpool.c的问题,然后进去看,发现有定义

#define _POSIX_C_SOURCE 200809L

这引入了posix依赖环境,导致找不到?

解决方案,交换头文件顺序,或者改成-std=gnu99

https://stackoverflow.com/questions/48332332/what-does-define-posix-source-mean

https://stackoverflow.com/questions/22912674/unknown-type-name-siginfo-t-with-clang-using-posix-c-source-2-why

运行提示load shared libraries error,xxx file too short

部署出现问题,库的软连接坏了,变成莫名其妙的实体了,然后二进制运行加载文件太短,就有这个效果了

https://blog.csdn.net/xiaojun111111/article/details/54693004

internal compiler error: unexpected expression ‘I’ of kind template_parm_index

编译apache arrow遇到的,这个是gcc 7.3.1的bug,无解,换编译器

unexpected unqualified-id (

std::isnan std::isinf 和头文件cmath要匹配。要么math.h 函数不加std:: prefix要么cmath

error reading variable: Cannot access memory

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400f8b in encryptFile (
inPath=<error reading variable: Cannot access memory at address 0x7fffff63a0f8>, 
outPath=<error reading variable: Cannot access memory at address 0x7fffff63a0f0>, 
key=<error reading variable: Cannot access memory at address 0x7fffff63a0e8>) at 

一般是堆栈爆了,踩了栈变量,找是否有大对象,是否有函数递归调用过深

https://stackoverflow.com/questions/14484682/error-reading-variable-cannot-access-memory-at-address-x/37829799


[Too many arguments for format -Wformat-extra-args]

这个一般是用到% 参数和%对不上,我遇到的场景,我根本就没用到%,怎么会报错?因为用了逗号,代码类似这样

printf(
"Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]\n\n"
" -h <hostname>      Server hostname (default 127.0.0.1)\n"
" -p <port>          Server port (default 6379)\n"
" -s <socket>        Server socket (overrides host and port)\n"
" -c <clients>       Number of parallel connections (default 50)\n"
" -n <requests>      Total number of requests (default 10000)\n"
" -d <size>          Data size of SET/GET value in bytes (default 2)\n"
" -dbnum <db>        SELECT the specified db number (default 0)\n",
" -k <boolean>       1=keep alive 0=reconnect (default 1)\n",
" -r <keyspacelen>   Use random keys for SET/GET/INCR, random values for SADD\n",
"  Using this option the benchmark will expand the string __rand_int__\n",
"  inside an argument with a 12 digits number in the specified range\n");

注意后面几行的逗号

这个问题可以认为的%,之间的关系,要匹配上,有,说明有参数,有参数,就要有匹配的%

autoreconf -ivf 报错 configure: creating ./config.status

.in’ig.status: error: cannot find input file: `

这个代码包是我从windows上拷贝到arm编译机器上的。

找到了个答案https://github.com/mobile-shell/mosh/issues/313

执行dos2unix *就可以了

/usr/bin/ld: cannot find -lstdc++

正常来说不应该缺少这个库。我是静态链接的,所以可能缺静态的libstdc++

执行 yum install libstdc++-static,果然缺

error: comparison is always true due to limited range of data type [-Werror=type-limits] while (-1 != (c = getopt(argc, argv, “hv”)))

其中c是char类型。arm平台这里报错

这里的坑在于,char类型的默认符号是平台定义的,arm平台是默认unsigned,x86是默认signed

https://stackoverflow.com/questions/757482/comparison-is-always-true-due-to-limited-range-of-data-type-warning-in-c/757508

http://blog.coderhuo.tech/2017/03/19/__arm__char_problem/

编译报错 -Wimplicit-fallthrough

gcc 7编译报错 代码下方加上/* Falls through. */ 规避。也可以用c++17的attribute

https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/

编译报错 -Wunused-result

有一些系统函数,write之类的,会提示返回值未检查警告

https://stackoverflow.com/questions/40576003/ignoring-warning-wunused-result

这个链接给了个通用方案 编译flag 加上-Wno-xx 不过最好不要这么搞,这样使WError没意义了

error: ‘::memchr’ has not been declared

一般来说,都是没加string.h或者cstring 我的代码加了还有这个问题,代码中有同名文件string.h把系统文件覆盖了。编译搜索的时候不要添加内部目录就好了

https://stackoverflow.com/questions/9877635/how-do-i-fix-some-versioning-issue-when-compiling-c-code