1) 下面是因为没有指定链接参数-lz(/usr/lib/libz.so,/usr/lib/libz.a ) /usr/local/mysql/lib/mysql/libmysqlclient.a(my_compress.c.o): In function `my_uncompress': /home/software/mysql-5.5.24/mysys/my_compress.c:122: undefined reference to `uncompress' /usr/local/mysql/lib/mysql/libmysqlclient.a(my_compress.c.o): In function `my_compress_alloc': /home/software/mysql-5.5.24/mysys/my_compress.c:71: undefined reference to `compress'
2) 下面是因为没有指定编译链接参数-pthread(注意不仅仅是-lpthraed) /usr/local/mysql/lib/mysql/libmysqlclient.a(charset.c.o): In function `get_charset_name': /home/zhangsan/mysql-5.5.24/mysys/charset.c:533: undefined reference to `pthread_once'
3) 下面这个是因为没有指定链接参数-lrt /usr/local/thirdparty/curl/lib/libcurl.a(libcurl_la-timeval.o): In function `curlx_tvnow': timeval.c:(.text+0xe9): undefined reference to `clock_gettime'
4) 下面这个是因为没有指定链接参数-ldl /usr/local/thirdparty/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup': dso_dlfcn.c:(.text+0x4c): undefined reference to `dlopen' dso_dlfcn.c:(.text+0x62): undefined reference to `dlsym' dso_dlfcn.c:(.text+0x6c): undefined reference to `dlclose'
5) 下面这个是因为指定了链接参数-static,它的存在,要求链接的必须是静态库,而不能是共享库 ld: attempted static link of dynamic object 如果是以-L加-l方式指定,则目录下必须有.a文件存在,否则会报-l的库文件找不到:ld: cannot find -lACE
6) GCC编译遇到如下的错误,可能是因为在编译时没有指定-fPIC,记住:-fPIC即是编译参数,也是链接参数 relocation R_x86_64_32S against `vtable for CMyClass` can not be used when making a shared object
7) 下面的错误表示gcc编译时需要定义宏__STDC_FORMAT_MACROS,并且必须包含头文件inttypes.h test.cpp:35: error: expected `)' before 'PRIu64'
8) 下面是因为在x86机器(32位)上编译没有指定编译参数-march=pentium4 ../../src/common/libmooon.a(logger.o): In function `atomic_dec_and_test': ../../include/mooon/sys/atomic_gcc.h:103: undefined reference to `__sync_sub_and_fetch_4'
9) 下列错误可能是因为多了个“}” error: expected declaration before '}' token
10) 下列错误可能是因为少了个“}” error: expected `}' at end of input
11) 下面这个错误是编译一个共享库时,该共享库依赖的一静态库编译时没有加“-fPIC”参数,解决方法为带“-fPIC”重新编译被依赖的静态库 relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
12) 下面这个错误,是因为头文件中使用“_syscall0(pid_t, gettid)”不当引起的 ./test.o: In function `gettid()': ./test.h:17: multiple definition of `gettid()'
13) 下列编译告警是因为一个static类型的函数未被使用 my.cpp:364: warning: 'int my_function(const cgicc::Cgicc&, const std::string&)' defined but not used
只需使用“__attribute__((unused))”修饰函数的声明即可: static int __attribute__((unused)) my_function(const cgicc::Cgicc&, const std::string&);
14) 执行thrift的configure时遇到如下的错误(thrift-0.9.0和thrift-0.9.1遇到过): checking for setsockopt in -lsocket... no checking for BN_init in -lcrypto... no configure: error: "Error: libcrypto required."
15) 下面这个编译错误(表现为g++进入死循环),可能是由于缺少右大括号“}”导致的,比如定义名字空间时少了“}”: /usr/include/c++/4.1.2/tr1/type_traits:408: error: 'size_t' is not a member of 'db_proxy::std' /usr/include/c++/4.1.2/tr1/type_traits:408: error: 'size_t' is not a member of 'db_proxy::std' /usr/include/c++/4.1.2/tr1/mu_iterate.h:49: error: 'std::tr1' has not been declared /usr/include/c++/4.1.2/tr1/mu_iterate.h:49: error: 'std::tr1' has not been declared /usr/include/c++/4.1.2/tr1/bind_iterate.h:78: error: 'std::tr1' has not been declared /usr/include/c++/4.1.2/tr1/bind_iterate.h:78: error: 'std::tr1' has not been declared /usr/include/c++/4.1.2/tr1/bind_iterate.h:78: error: 'std::tr1' has not been declared
16) protoc编译错误,下面错误是因为没有在.proto文件所在目录下执行: /tmp/test.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think). 解决办法有两个:一是在.proto文件所在目录下执行protoc,二是为protoc指定参数--proto_path,参数值为.proto文件所在目录。
17) 下面这个编译错误,可能是因为在全局域内调用一个类对象的成员函数,全局域内是不能直接执行函的: error: expected constructor, destructor, or type conversion before '->' token
19) 下列是链接错误,不是编译错误,加上“-pthread”即可,注意不是“-lpthread”: /usr/local/mysql/lib/mysql/libmysqlclient.a(charset.c.o): In function `get_charset_name': /home/software/mysql-5.5.24/mysys/charset.c:533: undefined reference to `pthread_once' /usr/local/mysql/lib/mysql/libmysqlclient.a(charset.c.o): In function `get_charset_number':
20) 依赖OpenSSL(假设安装在/usr/local/thirdparty/openssl-1.0.2a)时,如果 ./configure --prefix=/usr/local/thirdparty/libssh2-1.6.0 --with-libssl-prefix=/usr/local/thirdparty/openssl-1.0.2a 时遇到如下错误: configure: error: No crypto library found! Try --with-libssl-prefix=PATH or --with-libgcrypt-prefix=PATH or --with-wincng on Windows
21) 错误“error: expected primary-expression before ‘;’ token”可能是因为如下原因: UserInfoInternal* user_info_internal = new UserInfoInternal; delete user_info; // 这里应当是user_info_internal
22) 下面这个编译错误的原因是定义字符串宏时没有加双引引号: example.cpp:563:16: error: too many decimal points in number 如定义成了:#define IP1 127.0.0.1,改成#define IP1 "127.0.0.1"后问题即解决。
23) 下面这个编译错误是因为g++命令参数没写对,多了个“-” g++: -E or -x required when input is from standard input 如: CPPFLAGS=-pthread - g++ -g -o $@ $^ $(CPPFLAGS) $(LDFLAGS)
24) libjson_7.6.1编译错误: makefile:180: Extraneous text after `else' directive makefile:183: *** only one `else' per conditional. Stop. 解决办法: 找到makefile文件的第180行,将“else ifeq ($(BUILD_TYPE), debug)”,改成两行内嵌方式: # BUILD_TYPE specific settings ifeq ($(BUILD_TYPE), small) CXXFLAGS = $(cxxflags_small) else ifeq ($(BUILD_TYPE), debug) # 不能和else同一行,否则Makefile语法错误,不支持else ifeq CXXFLAGS = $(cxxflags_debug) libname := $(libname_debug) else CXXFLAGS ?= $(cxxflags_default) endif endif